corrade-http-templates – Blame information for rev 4

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 sends a group message using Corrade. ##
7 ###########################################################################
8  
9 ###########################################################################
10 ## CONFIGURATION ##
11 ###########################################################################
12  
4 eva 13 require_once('config.php');
14 require_once('functions.php');
2 eva 15  
16 ###########################################################################
17 ## INTERNALS ##
18 ###########################################################################
19  
4 eva 20 # If there is no message set or no name set or if the message or the name
21 # are empty then do not proceed any further.
22 if(!isset($_POST['message']) ||
23 empty($_POST['message']) ||
24 !isset($_POST['name']) ||
25 empty($_POST['name'])) return;
2 eva 26  
27 ####
28 # I. Build the POST array to send to Corrade.
29 $params = array(
30 'command' => 'tell',
31 'group' => $GROUP,
32 'password' => $PASSWORD,
33 'entity' => 'group',
34 'message' => $_POST['name'].' says '.$_POST['message']
35 );
36  
37 ####
38 # II. Escape the data to be sent to Corrade.
39 array_walk($params,
40 function(&$value, $key) {
41 $value = rawurlencode($key)."=".rawurlencode($value);
42 }
43 );
44 $postvars = implode('&', $params);
45  
46 ####
47 # III. Use curl to send the message.
48 if (!($curl = curl_init())) {
49 print 0;
50 return;
51 }
52 curl_setopt($curl, CURLOPT_URL, $URL);
53 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
54 curl_setopt($curl, CURLOPT_POST, true);
55 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
4 eva 56 curl_setopt($curl, CURLOPT_ENCODING, true);
2 eva 57 $result = curl_exec($curl);
58 curl_close($curl);
59  
60 ####
61 # IV. Grab the status of the command.
62 $status = urldecode(
63 wasKeyValueGet(
64 "success",
65 $result
66 )
67 );
68  
69 ####
70 # V. Check the status of the command.
71 switch($status) {
4 eva 72 case "True": # Be silent if the message has been sent successfully.
73 # echo 'Message sent successfully!';
2 eva 74 break;
4 eva 75 default: # If an error occured, then return the error message.
76 echo 'Corrade failed to send the group message and reported the error: '.urldecode(
2 eva 77 wasKeyValueGet(
78 "error",
79 $result
80 )
81 );
82 break;
83 }
84  
85 ?>