PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.1.39
Brevo – Email, SMS, Web Push, Chat, and more. v3.1.39
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 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.2 3.1.20 3.1.21 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.1.29 3.1.3 3.1.30 3.1.31 3.1.32 3.1.33 3.1.34 3.1.35 3.1.36 3.1.37 3.1.38 3.1.39 3.1.4 3.1.40 3.1.41 3.1.42 3.1.43 3.1.44 3.1.45 3.1.46 3.1.47 3.1.48 3.1.49 3.1.5 3.1.50 3.1.51 3.1.52 3.1.53 3.1.54 3.1.55 3.1.56 3.1.57 3.1.58 3.1.59 3.1.6 3.1.60 3.1.61 3.1.62 3.1.63 3.1.64 3.1.65 3.1.66 3.1.67 3.1.68 3.1.69 3.1.7 3.1.70 3.1.71 3.1.72 3.1.73 3.1.74 3.1.75 3.1.76 3.1.77 3.1.78 3.1.79 3.1.8 3.1.80 3.1.81 3.1.82 3.1.83 3.1.84 3.1.85 3.1.86 3.1.87 3.1.88 3.1.89 3.1.9 3.1.90 3.1.91 3.1.92 3.1.93 3.1.94 3.1.95 3.1.96 3.1.97 3.1.98 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 trunk 1.0 1.5 2.0.8 2.9.10 2.9.11 2.9.12
mailin / inc / sendinblue.php
mailin / inc Last commit date
templates 4 years ago SendinblueAccount.php 5 years ago SendinblueApiClient.php 4 years ago function.wp_mail.php 8 years ago index.php 8 years ago mailin.php 5 years ago sendinblue.php 4 years ago sib-api-manager.php 4 years ago sib-form-preview.php 4 years ago sib-sms-code.php 8 years ago table-forms.php 4 years ago
sendinblue.php
174 lines
1 <?php
2 class Sendinblue
3 {
4 public $api_key;
5 public $base_url;
6 public $curl_opts = array();
7
8 public function __construct($api_key)
9 {
10 if (!function_exists('curl_init')) {
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 $domain = self::get_app_domain();
18 //store session_id cookie
19 $session_id = md5(uniqid(time()));
20 $expiry_time = self::get_default_cookie_expiry();
21 setcookie("session_id", $session_id, $expiry_time, "/", $domain, is_ssl());
22 }
23 }
24
25 /**
26 * @param $input
27 * @return mixed
28 */
29 private function do_request($input)
30 {
31 $input['key'] = $this->api_key;
32 $url = $this->base_url . "?" . http_build_query($input);
33 $data = wp_remote_retrieve_body(wp_remote_request($url, ['method' => 'GET']));
34
35 return json_decode($data, true);
36 }
37
38 /**
39 * @return string
40 */
41 private static function get_app_domain()
42 {
43 $url = get_site_url();
44 $parsed_url = parse_url($url);
45 return !empty($parsed_url['host']) ? $parsed_url['host'] : 'localhost';
46 }
47
48 /**
49 * @return int
50 */
51 private static function get_default_cookie_expiry()
52 {
53 return time() + 8640;
54 }
55
56
57 /**
58 * @param string $email
59 * @param int $expiry_time
60 * @return void
61 */
62 private function set_email_cookie(string $email)
63 {
64 $expiry_time = self::get_default_cookie_expiry();
65 $domain = self::get_app_domain();
66 setcookie("email_id", sanitize_email($email), $expiry_time, "/", $domain, is_ssl());
67 }
68
69 public function identify($data)
70 {
71 $data['sib_type'] = 'identify';
72
73 if (!array_key_exists('name', $data)) {
74 $data['name'] = "Contact Created";
75 }
76 $url = esc_url_raw((isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
77 if (!array_key_exists('url', $data)) {
78 $data['url'] = $url;
79 }
80 if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') {
81 $data['session_id'] = sanitize_text_field($_COOKIE['session_id']);
82 }
83 //store email_id cookie
84 $this->set_email_cookie($data['email_id']);
85 return $this->do_request($data);
86 }
87
88 public function track($data)
89 {
90 $data['sib_type'] = 'track';
91 $url = esc_url_raw((isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
92 if (!array_key_exists('url', $data)) {
93 $data['url'] = $url;
94 }
95
96 if (!array_key_exists('sib_name', $data)) {
97 if (array_key_exists('name', $data)) {
98 $data['sib_name'] = $data['name'];
99 }
100 }
101
102 //get email cookie
103
104 if (isset($_COOKIE['email_id']) && $_COOKIE['email_id'] != '') {
105 $data['email_id'] = sanitize_email($_COOKIE['email_id']);
106 }
107 if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') {
108 $data['session_id'] = sanitize_text_field($_COOKIE['session_id']);
109 }
110
111 //store email cookie
112 $obj = $this->do_request($data);
113 if (isset($obj['email_id']) && $obj['email_id'] != '') {
114 $this->set_email_cookie($obj['email_id']);
115 }
116 }
117
118 public function page($data)
119 {
120 $data['sib_type'] = 'page';
121 $url = esc_url_raw((isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
122 if (!array_key_exists('url', $data)) {
123 $data['url'] = $url;
124 }
125 //get email cookie
126 if (isset($_COOKIE['email_id']) && $_COOKIE['email_id'] != '') {
127 $data['email_id'] = sanitize_email($_COOKIE['email_id']);
128 }
129 if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') {
130 $data['session_id'] = sanitize_text_field($_COOKIE['session_id']);
131 }
132 //referrer
133 if (!array_key_exists('referrer', $data) && array_key_exists('HTTP_REFERER', $_SERVER)) {
134 $data['referrer'] = $_SERVER['HTTP_REFERER'];
135 }
136 //pathname
137 if (!array_key_exists('pathname', $data)) {
138 $data['pathname'] = $_SERVER['REQUEST_URI'];
139 }
140
141 //name
142 if (!array_key_exists('name', $data)) {
143 $data['name'] = $_SERVER['REQUEST_URI'];
144 }
145
146 //store email cookie
147 $obj = $this->do_request($data);
148 if (isset($obj['email_id']) && $obj['email_id'] != '') {
149 $this->set_email_cookie($obj['email_id']);
150 }
151 }
152
153 public function trackLink($data)
154 {
155 $data['sib_type'] = 'trackLink';
156 //get email cookie
157 if (isset($_COOKIE['email_id']) && $_COOKIE['email_id'] != '') {
158 $data['email_id'] = sanitize_email($_COOKIE['email_id']);
159 }
160 if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') {
161 $data['session_id'] = sanitize_text_field($_COOKIE['session_id']);
162 }
163 $url = esc_url_raw((isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
164 if (!array_key_exists('url', $data)) {
165 $data['url'] = $url;
166 }
167 //store email cookie
168 $obj = $this->do_request($data);
169 if (isset($obj['email_id']) && $obj['email_id'] != '') {
170 $this->set_email_cookie($obj['email_id']);
171 }
172 }
173 }
174