corrade-http-templates – Diff between revs 71 and 82

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 71 Rev 82
1 <?php 1 <?php
2 2
3 ########################################################################### 3 ###########################################################################
4 ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## 4 ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ##
5 ########################################################################### 5 ###########################################################################
6 ## This is a script that binds to Corrade's "group" chat notification. ## 6 ## This is a script that binds to Corrade's "group" chat notification. ##
7 ########################################################################### 7 ###########################################################################
8   8  
9 ########################################################################### 9 ###########################################################################
10 ## CONFIGURATION ## 10 ## CONFIGURATION ##
11 ########################################################################### 11 ###########################################################################
12   12  
13 require_once('config.php'); 13 require_once('config.php');
14 require_once('vendor/was/utilities/src/formats/kvp/kvp.php'); 14 require_once('vendor/was/utilities/src/formats/kvp/kvp.php');
15   15  
16 ########################################################################### 16 ###########################################################################
17 ## INTERNALS ## 17 ## INTERNALS ##
18 ########################################################################### 18 ###########################################################################
19 19
20 #### 20 ####
21 # I. Build the POST array to send to Corrade. 21 # I. Build the POST array to send to Corrade.
22 $params = array( 22 $params = array(
23 'command' => 'notify', 23 'command' => 'notify',
24 'group' => $GROUP, 24 'group' => $GROUP,
25 'password' => $PASSWORD, 25 'password' => $PASSWORD,
26 'type' => 'group', 26 'type' => 'group',
27 'action' => 'add', # Set will discard other URLs 27 'action' => 'add', # Set will discard other URLs
28 'tag' => $NOTIFICATION_TAG, 28 'tag' => $NOTIFICATION_TAG,
29 'URL' => $STORE 29 'URL' => $STORE
30 ); 30 );
31 31
32 #### 32 ####
33 # II. Escape the data to be sent to Corrade. 33 # II. Escape the data to be sent to Corrade.
34 array_walk($params, 34 array_walk($params,
35 function(&$value, $key) { 35 function(&$value, $key) {
36 $value = rawurlencode($key)."=".rawurlencode($value); 36 $value = urlencode($key)."=".urlencode($value);
37 } 37 }
38 ); 38 );
39 $postvars = implode('&', $params); 39 $postvars = implode('&', $params);
40 40
41 #### 41 ####
42 # III. Use curl to send the message. 42 # III. Use curl to send the message.
43 if (!($curl = curl_init())) { 43 if (!($curl = curl_init())) {
44 print 0; 44 print 0;
45 return; 45 return;
46 } 46 }
47 curl_setopt($curl, CURLOPT_URL, $URL); 47 curl_setopt($curl, CURLOPT_URL, $URL);
48 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 48 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
49 curl_setopt($curl, CURLOPT_POST, true); 49 curl_setopt($curl, CURLOPT_POST, true);
50 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); 50 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
51 $result = curl_exec($curl); 51 $result = curl_exec($curl);
52 curl_close($curl); 52 curl_close($curl);
53   53  
54 #### 54 ####
55 # IV. Grab the status of the command. 55 # IV. Grab the status of the command.
56 $status = urldecode( 56 $status = urldecode(
57 wasKeyValueGet( 57 wasKeyValueGet(
58 "success", 58 "success",
59 $result 59 $result
60 ) 60 )
61 ); 61 );
62   62  
63 #### 63 ####
64 # V. Check the status of the command. 64 # V. Check the status of the command.
65 switch($status) { 65 switch($status) {
66 case "True": 66 case "True":
67 echo 'Group chat notification installed!'.PHP_EOL; 67 echo 'Group chat notification installed!'.PHP_EOL;
68 break; 68 break;
69 default: 69 default:
70 echo 'Corrade returned the error: '.urldecode( 70 echo 'Corrade returned the error: '.urldecode(
71 wasKeyValueGet( 71 wasKeyValueGet(
72 "error", 72 "error",
73 $result 73 $result
74 ) 74 )
75 ).PHP_EOL; 75 ).PHP_EOL;
76 break; 76 break;
77 } 77 }
78 78
79 ?> 79 ?>
80   80  
81
Generated by GNU Enscript 1.6.5.90.
81
Generated by GNU Enscript 1.6.5.90.
82   82  
83   83  
84   84