corrade-http-templates – Blame information for rev 14

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  
14 eva 13 require_once('config.php');
14 require_once('functions.php');
2 eva 15  
16 ###########################################################################
17 ## INTERNALS ##
18 ###########################################################################
19  
20 # If no avatars have been sent, then bail.
21 if(!isset($_POST['avatars'])) return;
22  
23 ####
24 # I. Build the list of invites to send to Corrade.
25 $invites = array();
26 foreach(
27 array_filter(explode("\n", $_POST['avatars']), 'trim') as $avatar) {
28 $nameUUID = preg_split("/[\s]+/", $avatar);
29 switch(count($nameUUID)) {
30 case 2:
31 case 1:
32 array_push($invites, $avatar);
33 break;
34 }
35 }
36  
37 # Do not bother with an empty list of invites
38 if(count($invites) == 0) {
39 echo implode(PHP_EOL, $invites);
40 return -1;
41 }
42  
43 ####
44 # II. Build the command by name.
45 $params = array(
46 'command' => 'batchinvite',
47 'group' => $GROUP,
48 'password' => $PASSWORD,
49 'avatars' => wasArrayToCSV($invites)
50 );
51  
52 ####
53 # III. Escape the data to be sent to Corrade.
54 array_walk($params,
55 function(&$value, $key) {
56 $value = rawurlencode($key)."=".rawurlencode($value);
57 }
58 );
59 $postvars = implode('&', $params);
60  
61 ####
62 # IV. Use curl to send the message.
63 if (!($curl = curl_init())) {
64 print 0;
65 return;
66 }
67 curl_setopt($curl, CURLOPT_URL, $URL);
68 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
69 curl_setopt($curl, CURLOPT_POST, true);
70 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
71 $result = curl_exec($curl);
72 curl_close($curl);
73  
74 ####
75 # V. Grab the status of the command.
76 $status = urldecode(
77 wasKeyValueGet(
78 "success",
79 $result
80 )
81 );
82  
83  
84 ####
85 # VI. Check the status of the command.
86 switch($status) {
87 case "False":
88 return -1;
89 }
90  
91 ####
92 # V. Return any avatars or UUIDs for which invites could not be sent.
93 echo implode(
94 PHP_EOL,
95 wasCSVToArray(
96 urldecode(
97 wasKeyValueGet(
98 "data",
99 $result
100 )
101 )
102 )
103 );
104  
105 return 0;
106  
107 ?>