corrade-http-templates – Blame information for rev 82

Subversion Repositories:
Rev:
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');
71 office 14 require_once('vendor/was/utilities/src/formats/kvp/kvp.php');
2 eva 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' => 'group',
48 office 27 'action' => 'add', # Set will discard other URLs
28 'tag' => $NOTIFICATION_TAG,
2 eva 29 'URL' => $STORE
30 );
31  
32 ####
33 # II. Escape the data to be sent to Corrade.
34 array_walk($params,
35 function(&$value, $key) {
82 office 36 $value = urlencode($key)."=".urlencode($value);
2 eva 37 }
38 );
39 $postvars = implode('&', $params);
40  
41 ####
42 # III. Use curl to send the message.
43 if (!($curl = curl_init())) {
44 print 0;
45 return;
46 }
47 curl_setopt($curl, CURLOPT_URL, $URL);
48 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
49 curl_setopt($curl, CURLOPT_POST, true);
50 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
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 # V. Check the status of the command.
65 switch($status) {
66 case "True":
48 office 67 echo 'Group chat notification installed!'.PHP_EOL;
2 eva 68 break;
69 default:
70 echo 'Corrade returned the error: '.urldecode(
71 wasKeyValueGet(
72 "error",
73 $result
74 )
48 office 75 ).PHP_EOL;
2 eva 76 break;
77 }
78  
79 ?>