corrade-http-templates – Blame information for rev 6
?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 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 ## |
||
8 | ## DataTables JQuery extension. ## |
||
9 | ########################################################################### |
||
10 | |||
11 | ########################################################################### |
||
12 | ## CONFIGURATION ## |
||
13 | ########################################################################### |
||
14 | |||
6 | zed | 15 | require_once('config.php'); |
16 | require_once('functions.php'); |
||
2 | eva | 17 | |
18 | ########################################################################### |
||
19 | ## INTERNALS ## |
||
20 | ########################################################################### |
||
21 | |||
22 | #### |
||
23 | # I. Get the top scripts. |
||
24 | $params = array( |
||
25 | 'command' => 'getregiontop', |
||
26 | 'group' => $GROUP, |
||
27 | 'password' => $PASSWORD, |
||
28 | 'type' => 'scripts' |
||
29 | ); |
||
30 | array_walk($params, |
||
6 | zed | 31 | function(&$value, $key) { |
32 | $value = rawurlencode($key)."=".rawurlencode($value); |
||
33 | } |
||
2 | eva | 34 | ); |
35 | $postvars = implode('&', $params); |
||
36 | if (!($curl = curl_init())) { |
||
37 | print 0; |
||
38 | return; |
||
39 | } |
||
40 | curl_setopt($curl, CURLOPT_URL, $URL); |
||
41 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
42 | curl_setopt($curl, CURLOPT_POST, true); |
||
43 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
||
6 | zed | 44 | curl_setopt($curl, CURLOPT_ENCODING, true); |
2 | eva | 45 | $return = curl_exec($curl); |
46 | curl_close($curl); |
||
47 | |||
48 | #### |
||
49 | # II. Check for success. |
||
50 | $success = urldecode( |
||
51 | wasKeyValueGet( |
||
52 | "success", |
||
53 | $return |
||
54 | ) |
||
55 | ); |
||
56 | if($success == 'False') { |
||
57 | echo 'Unable to query the top scripts.'; |
||
58 | die; |
||
59 | } |
||
60 | |||
61 | #### |
||
62 | # III. Dump JSON for DataTables. |
||
63 | echo json_encode( |
||
64 | array( |
||
65 | "data" => |
||
66 | array_chunk( |
||
67 | wasCSVToArray( |
||
68 | urldecode( |
||
69 | wasKeyValueGet( |
||
70 | "data", |
||
71 | $return |
||
72 | ) |
||
73 | ) |
||
74 | ), |
||
75 | 5 # We split the CSV in 5: score, task name, UUID, Owner and Position |
||
76 | ) |
||
77 | ) |
||
78 | ); |
||
79 | |||
80 | ?> |
||
81 | |||
82 |