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