corrade-http-templates – Blame information for rev 82

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