PluginProbe
Brevo – Email, SMS, Web Push, Chat, and more. / 3.1.21
Brevo – Email, SMS, Web Push, Chat, and more. v3.1.21
2.9.13 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 All 140 releases
mailin / inc / sendinblue.php
sendinblue.php
159 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class Sendinblue
3 {
4 public $api_key;
5 public $base_url;
6 public $curl_opts = array();
7 public function __construct($api_key)
8 {
9 if(!function_exists('curl_init'))
10 {
11 throw new Exception('Sendinblue requires CURL module');
12 }
13 $this->base_url = 'https://in-automate.sendinblue.com/p';
14 $this->api_key = $api_key;
15 //create a session cookie
16 if (!array_key_exists('session_id',$_COOKIE)) {
17 $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
18 $parsed = parse_url($url);
19 $host_parts = explode('.', $parsed['host']);
20 $domain = implode('.', array_slice($host_parts, count($host_parts)-2));
21 //store email_id cookie
22 setcookie("session_id",$_COOKIE['session_id'] = md5(uniqid(time())),time() + 86400,"/",$domain);
23 }
24
25 }
26
27 /**
28 * @param $input
29 * @return mixed
30 */
31 private function do_request($input)
32 {
33 $input['key'] = $this->api_key;
34 $url = $this->base_url . "?" . http_build_query($input);
35 $data = wp_remote_retrieve_body(wp_remote_request($url, ['method' => 'GET']));
36
37 return json_decode($data,true);
38 }
39
40 public function identify($data)
41 {
42 $data['sib_type'] = 'identify';
43
44 if (!array_key_exists('name',$data)) {
45 $data['name'] = "Contact Created";
46 }
47 $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
48 if (!array_key_exists('url',$data)) {
49 $data['url'] = $url;
50 }
51 if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') {
52 $data['session_id'] = $_COOKIE['session_id'];
53 }
54 $parsed = parse_url($url);
55 $host_parts = explode('.', $parsed['host']);
56 $domain = implode('.', array_slice($host_parts, count($host_parts)-2));
57 //store email_id cookie
58 setcookie("email_id",$_COOKIE['email_id'] = $data['email_id'],time() + 86400,"/",$domain);
59 return $this->do_request($data);
60 }
61
62 public function track($data)
63 {
64 $data['sib_type'] = 'track';
65 $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
66 if (!array_key_exists('url',$data)) {
67 $data['url'] = $url;
68 }
69
70 if (!array_key_exists('sib_name',$data)) {
71 if (array_key_exists('name',$data)) {
72 $data['sib_name'] = $data['name'];
73 }
74 }
75
76 //get email cookie
77
78 if (isset($_COOKIE['email_id']) && $_COOKIE['email_id'] != '') {
79 $data['email_id'] = $_COOKIE['email_id'];
80 }
81 if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') {
82 $data['session_id'] = $_COOKIE['session_id'];
83 }
84
85 //store email cookie
86 $obj = $this->do_request($data);
87 if (isset($obj['email_id']) && $obj['email_id'] != '') {
88 $parsed = parse_url($url);
89 $host_parts = explode('.', $parsed['host']);
90 $domain = implode('.', array_slice($host_parts, count($host_parts)-2));
91 //store email_id cookie
92 setcookie("email_id",$_COOKIE['email_id'] = $obj['email_id'],time() + 86400,"/",$domain);
93 }
94 }
95 public function page($data)
96 {
97 $data['sib_type'] = 'page';
98 $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
99 if (!array_key_exists('url',$data)) {
100 $data['url'] = $url;
101 }
102 //get email cookie
103 if (isset($_COOKIE['email_id']) && $_COOKIE['email_id'] != '') {
104 $data['email_id'] = $_COOKIE['email_id'];
105 }
106 if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') {
107 $data['session_id'] = $_COOKIE['session_id'];
108 }
109 //referrer
110 if (!array_key_exists('referrer',$data) && array_key_exists('HTTP_REFERER',$_SERVER)) {
111 $data['referrer'] = $_SERVER['HTTP_REFERER'];
112 }
113 //pathname
114 if (!array_key_exists('pathname',$data)) {
115 $data['pathname'] = $_SERVER['REQUEST_URI'];
116 }
117
118 //name
119 if (!array_key_exists('name',$data)) {
120 $data['name'] = $_SERVER['REQUEST_URI'];
121 }
122
123 //store email cookie
124 $obj = $this->do_request($data);
125 if (isset($obj['email_id']) && $obj['email_id'] != '') {
126 $parsed = parse_url($url);
127 $host_parts = explode('.', $parsed['host']);
128 $domain = implode('.', array_slice($host_parts, count($host_parts)-2));
129 //store email_id cookie
130 setcookie("email_id",$_COOKIE['email_id'] = $obj['email_id'],time() + 86400,"/",$domain);
131 }
132 }
133 public function trackLink($data)
134 {
135 $data['sib_type'] = 'trackLink';
136 //get email cookie
137 if (isset($_COOKIE['email_id']) && $_COOKIE['email_id'] != '') {
138 $data['email_id'] = $_COOKIE['email_id'];
139 }
140 if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') {
141 $data['session_id'] = $_COOKIE['session_id'];
142 }
143 $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
144 if (!array_key_exists('url',$data)) {
145 $data['url'] = $url;
146 }
147 //store email cookie
148 $obj = $this->do_request($data);
149 if (isset($obj['email_id']) && $obj['email_id'] != '') {
150 $parsed = parse_url($url);
151 $host_parts = explode('.', $parsed['host']);
152 $domain = implode('.', array_slice($host_parts, count($host_parts)-2));
153 //store email_id cookie
154 setcookie("email_id",$_COOKIE['email_id'] = $obj['email_id'],time() + 86400,"/",$domain);
155 }
156 }
157 }
158 ?>
159