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
164 lines
| 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 = esc_url_raw((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 | $_COOKIE['session_id'] = md5(uniqid(time())); |
| 23 | setcookie("session_id", $_COOKIE['session_id'],time() + 86400,"/",$domain); |
| 24 | } |
| 25 | |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @param $input |
| 30 | * @return mixed |
| 31 | */ |
| 32 | private function do_request($input) |
| 33 | { |
| 34 | $input['key'] = $this->api_key; |
| 35 | $url = $this->base_url . "?" . http_build_query($input); |
| 36 | $data = wp_remote_retrieve_body(wp_remote_request($url, ['method' => 'GET'])); |
| 37 | |
| 38 | return json_decode($data,true); |
| 39 | } |
| 40 | |
| 41 | public function identify($data) |
| 42 | { |
| 43 | $data['sib_type'] = 'identify'; |
| 44 | |
| 45 | if (!array_key_exists('name',$data)) { |
| 46 | $data['name'] = "Contact Created"; |
| 47 | } |
| 48 | $url = esc_url_raw((isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); |
| 49 | if (!array_key_exists('url',$data)) { |
| 50 | $data['url'] = $url; |
| 51 | } |
| 52 | if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') { |
| 53 | $data['session_id'] = sanitize_text_field( $_COOKIE['session_id'] ); |
| 54 | } |
| 55 | $parsed = parse_url($url); |
| 56 | $host_parts = explode('.', $parsed['host']); |
| 57 | $domain = implode('.', array_slice($host_parts, count($host_parts)-2)); |
| 58 | //store email_id cookie |
| 59 | $_COOKIE['email_id'] = sanitize_email($data['email_id']); |
| 60 | setcookie("email_id",$_COOKIE['email_id'],time() + 86400,"/",$domain); |
| 61 | return $this->do_request($data); |
| 62 | } |
| 63 | |
| 64 | public function track($data) |
| 65 | { |
| 66 | $data['sib_type'] = 'track'; |
| 67 | $url = esc_url_raw((isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); |
| 68 | if (!array_key_exists('url',$data)) { |
| 69 | $data['url'] = $url; |
| 70 | } |
| 71 | |
| 72 | if (!array_key_exists('sib_name',$data)) { |
| 73 | if (array_key_exists('name',$data)) { |
| 74 | $data['sib_name'] = $data['name']; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | //get email cookie |
| 79 | |
| 80 | if (isset($_COOKIE['email_id']) && $_COOKIE['email_id'] != '') { |
| 81 | $data['email_id'] = sanitize_email( $_COOKIE['email_id'] ); |
| 82 | } |
| 83 | if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') { |
| 84 | $data['session_id'] = sanitize_text_field( $_COOKIE['session_id'] ); |
| 85 | } |
| 86 | |
| 87 | //store email cookie |
| 88 | $obj = $this->do_request($data); |
| 89 | if (isset($obj['email_id']) && $obj['email_id'] != '') { |
| 90 | $parsed = parse_url($url); |
| 91 | $host_parts = explode('.', $parsed['host']); |
| 92 | $domain = implode('.', array_slice($host_parts, count($host_parts)-2)); |
| 93 | //store email_id cookie |
| 94 | $_COOKIE['email_id'] = sanitize_email($obj['email_id']); |
| 95 | setcookie("email_id",$_COOKIE['email_id'],time() + 86400,"/",$domain); |
| 96 | } |
| 97 | } |
| 98 | public function page($data) |
| 99 | { |
| 100 | $data['sib_type'] = 'page'; |
| 101 | $url = esc_url_raw((isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); |
| 102 | if (!array_key_exists('url',$data)) { |
| 103 | $data['url'] = $url; |
| 104 | } |
| 105 | //get email cookie |
| 106 | if (isset($_COOKIE['email_id']) && $_COOKIE['email_id'] != '') { |
| 107 | $data['email_id'] = sanitize_email( $_COOKIE['email_id'] ); |
| 108 | } |
| 109 | if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') { |
| 110 | $data['session_id'] = sanitize_text_field( $_COOKIE['session_id'] ); |
| 111 | } |
| 112 | //referrer |
| 113 | if (!array_key_exists('referrer',$data) && array_key_exists('HTTP_REFERER',$_SERVER)) { |
| 114 | $data['referrer'] = $_SERVER['HTTP_REFERER']; |
| 115 | } |
| 116 | //pathname |
| 117 | if (!array_key_exists('pathname',$data)) { |
| 118 | $data['pathname'] = $_SERVER['REQUEST_URI']; |
| 119 | } |
| 120 | |
| 121 | //name |
| 122 | if (!array_key_exists('name',$data)) { |
| 123 | $data['name'] = $_SERVER['REQUEST_URI']; |
| 124 | } |
| 125 | |
| 126 | //store email cookie |
| 127 | $obj = $this->do_request($data); |
| 128 | if (isset($obj['email_id']) && $obj['email_id'] != '') { |
| 129 | $parsed = parse_url($url); |
| 130 | $host_parts = explode('.', $parsed['host']); |
| 131 | $domain = implode('.', array_slice($host_parts, count($host_parts)-2)); |
| 132 | //store email_id cookie |
| 133 | $_COOKIE['email_id'] = sanitize_email($obj['email_id']); |
| 134 | setcookie("email_id",$_COOKIE['email_id'],time() + 86400,"/",$domain); |
| 135 | } |
| 136 | } |
| 137 | public function trackLink($data) |
| 138 | { |
| 139 | $data['sib_type'] = 'trackLink'; |
| 140 | //get email cookie |
| 141 | if (isset($_COOKIE['email_id']) && $_COOKIE['email_id'] != '') { |
| 142 | $data['email_id'] = sanitize_email( $_COOKIE['email_id'] ); |
| 143 | } |
| 144 | if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') { |
| 145 | $data['session_id'] = sanitize_text_field( $_COOKIE['session_id'] ); |
| 146 | } |
| 147 | $url = esc_url_raw((isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); |
| 148 | if (!array_key_exists('url',$data)) { |
| 149 | $data['url'] = $url; |
| 150 | } |
| 151 | //store email cookie |
| 152 | $obj = $this->do_request($data); |
| 153 | if (isset($obj['email_id']) && $obj['email_id'] != '') { |
| 154 | $parsed = parse_url($url); |
| 155 | $host_parts = explode('.', $parsed['host']); |
| 156 | $domain = implode('.', array_slice($host_parts, count($host_parts)-2)); |
| 157 | //store email_id cookie |
| 158 | $_COOKIE['email_id'] = sanitize_email($obj['email_id']); |
| 159 | setcookie("email_id",$_COOKIE['email_id'],time() + 86400,"/",$domain); |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | ?> |
| 164 |