corrade-http-templates – Blame information for rev 82

Subversion Repositories:
Rev:
Rev Author Line No. Line
24 vero 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 require_once('config.php');
78 office 14 require_once('vendor/was/utilities/src/formats/kvp/kvp.php');
24 vero 15  
16 ###########################################################################
17 ## INTERNALS ##
18 ###########################################################################
19  
20 ####
21 # I. Build the POST array to send to Corrade.
22 $params = array(
23 'command' => 'notify',
24 'group' => $GROUP,
25 'password' => $PASSWORD,
26 'type' => 'membership',
27 'action' => 'add', # Set will discard other URLs
28 'URL' => $STORE
29 );
30  
31 ####
32 # II. Escape the data to be sent to Corrade.
33 array_walk($params,
34 function(&$value, $key) {
82 office 35 $value = urlencode($key)."=".urlencode($value);
24 vero 36 }
37 );
38 $postvars = implode('&', $params);
39  
40 ####
41 # III. Use curl to send the message.
42 if (!($curl = curl_init())) {
43 print 0;
44 return;
45 }
46 curl_setopt($curl, CURLOPT_URL, $URL);
47 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
48 curl_setopt($curl, CURLOPT_POST, true);
49 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
50 curl_setopt($curl, CURLOPT_ENCODING, true);
51 $result = curl_exec($curl);
52 curl_close($curl);
53  
54 ####
55 # IV. Grab the status of the command.
56 $status = urldecode(
57 wasKeyValueGet(
58 "success",
59 $result
60 )
61 );
62  
63 ####
64 # IV. Check the status of the command.
65 switch($status) {
66 case "True":
67 echo 'Membership notification installed!';
68 break;
69 default:
70 echo 'Corrade returned the error: '.urldecode(
71 wasKeyValueGet(
72 "error",
73 $result
74 )
75 );
76 break;
77 }
78  
79 ?>