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

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 48 Rev 71
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   15  
15 ########################################################################### 16 ###########################################################################
16 ## INTERNALS ## 17 ## INTERNALS ##
17 ########################################################################### 18 ###########################################################################
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 19
36 #### 20 ####
37 # I. Build the POST array to send to Corrade. 21 # I. Build the POST array to send to Corrade.
38 $params = array( 22 $params = array(
39 'command' => 'notify', 23 'command' => 'notify',
40 'group' => $GROUP, 24 'group' => $GROUP,
41 'password' => $PASSWORD, 25 'password' => $PASSWORD,
42 'type' => 'group', 26 'type' => 'group',
43 'action' => 'add', # Set will discard other URLs 27 'action' => 'add', # Set will discard other URLs
44 'tag' => $NOTIFICATION_TAG, 28 'tag' => $NOTIFICATION_TAG,
45 'URL' => $STORE 29 'URL' => $STORE
46 ); 30 );
47 31
48 #### 32 ####
49 # II. Escape the data to be sent to Corrade. 33 # II. Escape the data to be sent to Corrade.
50 array_walk($params, 34 array_walk($params,
51 function(&$value, $key) { 35 function(&$value, $key) {
52 $value = rawurlencode($key)."=".rawurlencode($value); 36 $value = rawurlencode($key)."=".rawurlencode($value);
53 } 37 }
54 ); 38 );
55 $postvars = implode('&', $params); 39 $postvars = implode('&', $params);
56 40
57 #### 41 ####
58 # III. Use curl to send the message. 42 # III. Use curl to send the message.
59 if (!($curl = curl_init())) { 43 if (!($curl = curl_init())) {
60 print 0; 44 print 0;
61 return; 45 return;
62 } 46 }
63 curl_setopt($curl, CURLOPT_URL, $URL); 47 curl_setopt($curl, CURLOPT_URL, $URL);
64 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 48 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
65 curl_setopt($curl, CURLOPT_POST, true); 49 curl_setopt($curl, CURLOPT_POST, true);
66 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); 50 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
67 $result = curl_exec($curl); 51 $result = curl_exec($curl);
68 curl_close($curl); 52 curl_close($curl);
69   53  
70 #### 54 ####
71 # IV. Grab the status of the command. 55 # IV. Grab the status of the command.
72 $status = urldecode( 56 $status = urldecode(
73 wasKeyValueGet( 57 wasKeyValueGet(
74 "success", 58 "success",
75 $result 59 $result
76 ) 60 )
77 ); 61 );
78   62  
79 #### 63 ####
80 # V. Check the status of the command. 64 # V. Check the status of the command.
81 switch($status) { 65 switch($status) {
82 case "True": 66 case "True":
83 echo 'Group chat notification installed!'.PHP_EOL; 67 echo 'Group chat notification installed!'.PHP_EOL;
84 break; 68 break;
85 default: 69 default:
86 echo 'Corrade returned the error: '.urldecode( 70 echo 'Corrade returned the error: '.urldecode(
87 wasKeyValueGet( 71 wasKeyValueGet(
88 "error", 72 "error",
89 $result 73 $result
90 ) 74 )
91 ).PHP_EOL; 75 ).PHP_EOL;
92 break; 76 break;
93 } 77 }
94 78
95 ?> 79 ?>
96   80  
97
Generated by GNU Enscript 1.6.5.90.
81
Generated by GNU Enscript 1.6.5.90.
98   82  
99   83  
100   84