corrade-http-templates – Diff between revs 2 and 6
?pathlinks?
Rev 2 | Rev 6 | |||
---|---|---|---|---|
Line 10... | Line 10... | |||
10 | |
10 | |
|
11 | ########################################################################### |
11 | ########################################################################### |
|
12 | ## CONFIGURATION ## |
12 | ## CONFIGURATION ## |
|
Line 13... | Line -... | |||
13 | ########################################################################### |
- | ||
14 | |
- | ||
15 | # Set this to the name of the group. |
13 | ########################################################################### |
|
16 | $GROUP = 'My Group'; |
14 | |
|
17 | # Set this to the group password. |
- | ||
18 | $PASSWORD = 'mypassword'; |
- | ||
Line 19... | Line 15... | |||
19 | # Set this to Corrade's HTTP Server URL. |
15 | require_once('config.php'); |
|
20 | $URL = 'http://corrade.internal.site:8080'; |
16 | require_once('functions.php'); |
|
21 | |
17 | |
|
Line 22... | Line -... | |||
22 | ########################################################################### |
- | ||
23 | ## INTERNALS ## |
- | ||
24 | ########################################################################### |
- | ||
25 | |
- | ||
26 | ########################################################################### |
- | ||
27 | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## |
- | ||
28 | ########################################################################### |
- | ||
29 | function wasKeyValueGet($key, $data) { |
- | ||
30 | return array_reduce( |
- | ||
31 | explode( |
- | ||
32 | "&", |
- | ||
33 | $data |
- | ||
34 | ), |
- | ||
35 | function($o, $p) { |
- | ||
36 | $x = explode("=", $p); |
- | ||
37 | return array_shift($x) != $o ? $o : array_shift($x); |
- | ||
38 | }, |
- | ||
39 | $key |
- | ||
40 | ); |
- | ||
41 | } |
- | ||
42 | /////////////////////////////////////////////////////////////////////////// |
- | ||
43 | // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // |
- | ||
44 | /////////////////////////////////////////////////////////////////////////// |
- | ||
45 | function wasCSVToArray($csv) { |
- | ||
46 | $l = array(); |
- | ||
47 | $s = array(); |
- | ||
48 | $m = ""; |
- | ||
49 | for ($i = 0; $i < strlen($csv); ++$i) { |
- | ||
50 | switch ($csv{$i}) { |
- | ||
51 | case ',': |
- | ||
52 | if (sizeof($s) == 0 || !current($s) == '"') { |
- | ||
53 | array_push($l, $m); |
- | ||
54 | $m = ""; |
- | ||
55 | break; |
- | ||
56 | } |
- | ||
57 | $m .= $csv{$i}; |
- | ||
58 | continue; |
- | ||
59 | case '"': |
- | ||
60 | if ($i + 1 < strlen($csv) && $csv{$i} == $csv{$i + 1}) { |
- | ||
61 | $m .= $csv{$i}; |
- | ||
62 | ++$i; |
- | ||
63 | break; |
- | ||
64 | } |
- | ||
65 | if (sizeof($s) == 0|| !current($s) == $csv[$i]) { |
- | ||
66 | array_push($s, $csv{$i}); |
- | ||
67 | continue; |
- | ||
68 | } |
- | ||
69 | array_pop($s); |
- | ||
70 | break; |
- | ||
71 | default: |
- | ||
72 | $m .= $csv{$i}; |
- | ||
73 | break; |
- | ||
74 | } |
- | ||
75 | } |
- | ||
76 | array_push($l, $m); |
18 | ########################################################################### |
|
77 | return $l; |
19 | ## INTERNALS ## |
|
78 | } |
20 | ########################################################################### |
|
79 | |
21 | |
|
80 | #### |
22 | #### |
|
81 | # I. Get the top scripts. |
23 | # I. Get the top scripts. |
|
82 | $params = array( |
24 | $params = array( |
|
83 | 'command' => 'getregiontop', |
25 | 'command' => 'getregiontop', |
|
84 | 'group' => $GROUP, |
26 | 'group' => $GROUP, |
|
85 | 'password' => $PASSWORD, |
27 | 'password' => $PASSWORD, |
|
86 | 'type' => 'scripts' |
28 | 'type' => 'scripts' |
|
87 | ); |
29 | ); |
|
88 | array_walk($params, |
30 | array_walk($params, |
|
89 | function(&$value, $key) { |
31 | function(&$value, $key) { |
|
90 | $value = rawurlencode($key)."=".rawurlencode($value); |
32 | $value = rawurlencode($key)."=".rawurlencode($value); |
|
91 | } |
33 | } |
|
92 | ); |
34 | ); |
|
93 | $postvars = implode('&', $params); |
35 | $postvars = implode('&', $params); |
|
94 | if (!($curl = curl_init())) { |
36 | if (!($curl = curl_init())) { |
|
95 | print 0; |
37 | print 0; |
|
96 | return; |
38 | return; |
|
97 | } |
39 | } |
|
- | 40 | curl_setopt($curl, CURLOPT_URL, $URL); |
||
98 | curl_setopt($curl, CURLOPT_URL, $URL); |
41 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
99 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
42 | curl_setopt($curl, CURLOPT_POST, true); |
|
Line 100... | Line 43... | |||
100 | curl_setopt($curl, CURLOPT_POST, true); |
43 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
|
101 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
44 | curl_setopt($curl, CURLOPT_ENCODING, true); |