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

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