corrade-http-templates – Blame information for rev 4
?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 that binds to Corrade's "group" chat notification. ## |
||
7 | ########################################################################### |
||
8 | |||
9 | ########################################################################### |
||
10 | ## CONFIGURATION ## |
||
11 | ########################################################################### |
||
12 | |||
4 | eva | 13 | require_once('config.php'); |
2 | eva | 14 | |
15 | ########################################################################### |
||
16 | ## INTERNALS ## |
||
17 | ########################################################################### |
||
18 | |||
19 | ########################################################################### |
||
20 | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## |
||
21 | ########################################################################### |
||
22 | function wasKeyValueGet($key, $data) { |
||
23 | return array_reduce( |
||
24 | explode( |
||
25 | "&", |
||
26 | $data |
||
27 | ), |
||
28 | function($o, $p) { |
||
29 | $x = explode("=", $p); |
||
30 | return array_shift($x) != $o ? $o : array_shift($x); |
||
31 | }, |
||
32 | $key |
||
33 | ); |
||
34 | } |
||
35 | |||
36 | #### |
||
37 | # I. Build the POST array to send to Corrade. |
||
38 | $params = array( |
||
39 | 'command' => 'notify', |
||
40 | 'group' => $GROUP, |
||
41 | 'password' => $PASSWORD, |
||
42 | 'type' => 'group', |
||
43 | 'action' => 'set', # Set will discard other URLs |
||
44 | 'URL' => $STORE |
||
45 | ); |
||
46 | |||
47 | #### |
||
48 | # II. Escape the data to be sent to Corrade. |
||
49 | array_walk($params, |
||
50 | function(&$value, $key) { |
||
51 | $value = rawurlencode($key)."=".rawurlencode($value); |
||
52 | } |
||
53 | ); |
||
54 | $postvars = implode('&', $params); |
||
55 | |||
56 | #### |
||
57 | # III. Use curl to send the message. |
||
58 | if (!($curl = curl_init())) { |
||
59 | print 0; |
||
60 | return; |
||
61 | } |
||
62 | curl_setopt($curl, CURLOPT_URL, $URL); |
||
63 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
64 | curl_setopt($curl, CURLOPT_POST, true); |
||
65 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
||
66 | $result = curl_exec($curl); |
||
67 | curl_close($curl); |
||
68 | |||
69 | #### |
||
70 | # IV. Grab the status of the command. |
||
71 | $status = urldecode( |
||
72 | wasKeyValueGet( |
||
73 | "success", |
||
74 | $result |
||
75 | ) |
||
76 | ); |
||
77 | |||
78 | #### |
||
79 | # V. Check the status of the command. |
||
80 | switch($status) { |
||
81 | case "True": |
||
82 | echo 'Group chat notification installed!'; |
||
83 | break; |
||
84 | default: |
||
85 | echo 'Corrade returned the error: '.urldecode( |
||
86 | wasKeyValueGet( |
||
87 | "error", |
||
88 | $result |
||
89 | ) |
||
90 | ); |
||
91 | break; |
||
92 | } |
||
93 | |||
94 | ?> |