corrade-http-templates – Blame information for rev 2
?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 | |||
13 | # Set this to the name of the group. |
||
14 | $GROUP = 'My Group'; |
||
15 | # Set this to the group password. |
||
16 | $PASSWORD = 'mypassword'; |
||
17 | # Set this to Corrade's HTTP Server URL. |
||
18 | $URL = 'http://corrade.local.site:8080'; |
||
19 | # Set this to the location of the process PHP script. |
||
20 | $READER = 'http://web.server/path/to/maleFemale/storeMaleFemale.php'; |
||
21 | |||
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 | # This constructs the command as an array of key-value pairs. |
||
44 | $params = array( |
||
45 | 'command' => 'notify', |
||
46 | 'group' => $GROUP, |
||
47 | 'password' => $PASSWORD, |
||
48 | 'type' => 'avatars', |
||
49 | 'action' => 'set', |
||
50 | 'URL' => $READER |
||
51 | ); |
||
52 | |||
53 | # We now escape each key and value: this is very important, because the |
||
54 | # data we send to Corrade may contain the '&' or '=' characters (we don't |
||
55 | # in this example though but this will not hurt anyone). |
||
56 | array_walk($params, |
||
57 | function(&$value, $key) { |
||
58 | $value = rawurlencode($key)."=".rawurlencode($value); |
||
59 | } |
||
60 | ); |
||
61 | $postvars = implode('&', $params); |
||
62 | |||
63 | # Set the options, send the request and then display the outcome |
||
64 | if (!($curl = curl_init())) { |
||
65 | print 0; |
||
66 | return; |
||
67 | } |
||
68 | |||
69 | curl_setopt($curl, CURLOPT_URL, $URL); |
||
70 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
71 | curl_setopt($curl, CURLOPT_POST, true); |
||
72 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
||
73 | $result = curl_exec($curl); |
||
74 | $status = urldecode( |
||
75 | wasKeyValueGet( |
||
76 | "success", |
||
77 | $result |
||
78 | ) |
||
79 | ); |
||
80 | $error = urldecode( |
||
81 | wasKeyValueGet( |
||
82 | "error", |
||
83 | $result |
||
84 | ) |
||
85 | ); |
||
86 | curl_close($curl); |
||
87 | |||
88 | switch($status) { |
||
89 | case "True": |
||
90 | echo 'Avatars notification installed!'; |
||
91 | break; |
||
92 | default: |
||
93 | echo 'The following error was encountered while attempting to install the avatars notification: '.$error; |
||
94 | break; |
||
95 | } |
||
96 | |||
97 | ?> |