-
Notifications
You must be signed in to change notification settings - Fork 8
/
class.notification.php
80 lines (67 loc) · 1.68 KB
/
class.notification.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* The easiest way to throw a notification using CuRL
*
* For more informations about the notification center please visit http://lab.mbuonomo.com/notificationcenter
*
* @author Mathieu BUONOMO <[email protected]>
* @version 0.1
*/
class notificationcenter
{
/**
* Server url
*
* By using Faye it's something like http://yourserverip:port/faye
*
* @var string
*/
private $_sServerUrl = "";
/**
* Your channel
*
* For example : /messages
*
* @var string
*/
private $_sChannel = "";
/**
* This method will be called to send a request
*
* Really simple cUrl :)
*
* @param string $sUrl
* @return void
*/
private function sendRequest($sUrl, $aParams){
$data_string = json_encode(array("channel" => $this->_sChannel, "data" => $aParams));
$ch = curl_init($this->_sServerUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$output = curl_exec($ch);
if($output === false)
{
trigger_error('Erreur curl : '.curl_error($ch),E_USER_WARNING);
}
else
{
curl_close($ch);
return $output;
}
}
public function __construct($server, $channel){
$this->_sServerUrl = $server;
$this->_sChannel = $channel;
}
public function shoot($message, $type){
$aParams['text'] = $message;
$aParams['type'] = $type;
return $this->sendRequest($this->_sServerUrl, $aParams);
}
}
?>