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

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 2 Rev 4
Line 8... Line 8...
8   8  
9 ########################################################################### 9 ###########################################################################
10 ## CONFIGURATION ## 10 ## CONFIGURATION ##
Line 11... Line -...
11 ########################################################################### -  
12   -  
13 # Set this to the name of the group. 11 ###########################################################################
14 $GROUP = 'My Group'; 12  
15 # Set this to the group password. -  
16 $PASSWORD = 'mypassword'; -  
Line 17... Line 13...
17 # Set this to Corrade's HTTP Server URL. 13 require_once('config.php');
18 $URL = 'http://corrade.hostname:8080'; 14 require_once('functions.php');
19   15  
Line 20... Line 16...
20 ########################################################################### 16 ###########################################################################
21 ## INTERNALS ## -  
22 ########################################################################### -  
23   -  
24 # If there is no "message" or "name" POST variable set then bail. 17 ## INTERNALS ##
25 if(!isset($_POST['message']) || !isset($_POST['name'])) return; -  
26   18 ###########################################################################
27 ########################################################################### 19  
28 ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## -  
29 ########################################################################### -  
30 function wasKeyValueGet($key, $data) { -  
31 return array_reduce( -  
32 explode( 20 # If there is no message set or no name set or if the message or the name
33 "&", 21 # are empty then do not proceed any further.
34 $data -  
35 ), -  
36 function($o, $p) { -  
37 $x = explode("=", $p); -  
38 return array_shift($x) != $o ? $o : array_shift($x); -  
Line 39... Line 22...
39 }, 22 if(!isset($_POST['message']) ||
40 $key 23 empty($_POST['message']) ||
41 ); 24 !isset($_POST['name']) ||
42 } 25 empty($_POST['name'])) return;
Line 68... Line 51...
68 } 51 }
69 curl_setopt($curl, CURLOPT_URL, $URL); 52 curl_setopt($curl, CURLOPT_URL, $URL);
70 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 53 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
71 curl_setopt($curl, CURLOPT_POST, true); 54 curl_setopt($curl, CURLOPT_POST, true);
72 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); 55 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
-   56 curl_setopt($curl, CURLOPT_ENCODING, true);
73 $result = curl_exec($curl); 57 $result = curl_exec($curl);
74 curl_close($curl); 58 curl_close($curl);
Line 75... Line 59...
75   59  
76 #### 60 ####
Line 83... Line 67...
83 ); 67 );
Line 84... Line 68...
84   68  
85 #### 69 ####
86 # V. Check the status of the command. 70 # V. Check the status of the command.
87 switch($status) { 71 switch($status) {
88 case "True": 72 case "True": # Be silent if the message has been sent successfully.
89 echo 'Message sent successfully!'; 73 # echo 'Message sent successfully!';
90 break; 74 break;
91 default: 75 default: # If an error occured, then return the error message.
92 echo 'Corrade returned the error: '.urldecode( 76 echo 'Corrade failed to send the group message and reported the error: '.urldecode(
93 wasKeyValueGet( 77 wasKeyValueGet(
94 "error", 78 "error",
95 $result 79 $result
96 ) 80 )