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