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 binds to Corrade's "group" chat notification. ##
7 ###########################################################################
8  
9 ###########################################################################
10 ## CONFIGURATION ##
11 ###########################################################################
12  
13 # Set this to the name of the group.
14 $GROUP = 'My Group';
15 # Set this to the group password.
16 $PASSWORD = 'mypassword';
17 # Set this to Corrade's HTTP Server URL.
18 $URL = 'http://corrade.local.site:8080';
19 # Set this to the location of the process PHP script.
20 $READER = 'http://web.server/path/to/maleFemale/storeMaleFemale.php';
21  
22 ###########################################################################
23 ## INTERNALS ##
24 ###########################################################################
80 office 25  
26 require_once('vendor/was/utilities/src/formats/kvp/kvp.php');
2 eva 27  
28 # This constructs the command as an array of key-value pairs.
29 $params = array(
30 'command' => 'notify',
31 'group' => $GROUP,
32 'password' => $PASSWORD,
33 'type' => 'avatars',
34 'action' => 'set',
35 'URL' => $READER
36 );
37  
38 # We now escape each key and value: this is very important, because the
39 # data we send to Corrade may contain the '&' or '=' characters (we don't
40 # in this example though but this will not hurt anyone).
41 array_walk($params,
42 function(&$value, $key) {
82 office 43 $value = urlencode($key)."=".urlencode($value);
2 eva 44 }
45 );
46 $postvars = implode('&', $params);
47  
48 # Set the options, send the request and then display the outcome
49 if (!($curl = curl_init())) {
50 print 0;
51 return;
52 }
53  
54 curl_setopt($curl, CURLOPT_URL, $URL);
55 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
56 curl_setopt($curl, CURLOPT_POST, true);
57 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
58 $result = curl_exec($curl);
59 $status = urldecode(
60 wasKeyValueGet(
61 "success",
62 $result
63 )
64 );
65 $error = urldecode(
66 wasKeyValueGet(
67 "error",
68 $result
69 )
70 );
71 curl_close($curl);
72  
73 switch($status) {
74 case "True":
75 echo 'Avatars notification installed!';
76 break;
77 default:
78 echo 'The following error was encountered while attempting to install the avatars notification: '.$error;
79 break;
80 }