templates
9 years ago
function.wp_mail.php
8 years ago
index.php
8 years ago
mailin.php
9 years ago
sendinblue.php
9 years ago
sib-api-manager.php
7 years ago
sib-form-preview.php
8 years ago
sib-sms-code.php
8 years ago
table-forms.php
8 years ago
sendinblue.php
169 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 = (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 | * Do CURL request with authorization |
| 28 | */ |
| 29 | |
| 30 | private function do_request($input) |
| 31 | { |
| 32 | $input['key'] = $this->api_key; |
| 33 | $input = http_build_query($input); |
| 34 | $ch = curl_init($this->base_url."?".$input); |
| 35 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
| 36 | // Windows only over-ride |
| 37 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 38 | } |
| 39 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
| 40 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 41 | curl_setopt($ch, CURLOPT_HEADER, 0); |
| 42 | $data = curl_exec($ch); |
| 43 | if(curl_errno($ch)) |
| 44 | { |
| 45 | echo 'Curl error: ' . curl_error($ch). '\n'; |
| 46 | } |
| 47 | curl_close($ch); |
| 48 | return json_decode($data,true); |
| 49 | } |
| 50 | public function identify($data) |
| 51 | { |
| 52 | $data['sib_type'] = 'identify'; |
| 53 | |
| 54 | if (!array_key_exists('name',$data)) { |
| 55 | $data['name'] = "Contact Created"; |
| 56 | } |
| 57 | $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; |
| 58 | if (!array_key_exists('url',$data)) { |
| 59 | $data['url'] = $url; |
| 60 | } |
| 61 | if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') { |
| 62 | $data['session_id'] = $_COOKIE['session_id']; |
| 63 | } |
| 64 | $parsed = parse_url($url); |
| 65 | $host_parts = explode('.', $parsed['host']); |
| 66 | $domain = implode('.', array_slice($host_parts, count($host_parts)-2)); |
| 67 | //store email_id cookie |
| 68 | setcookie("email_id",$_COOKIE['email_id'] = $data['email_id'],time() + 86400,"/",$domain); |
| 69 | return $this->do_request($data); |
| 70 | } |
| 71 | |
| 72 | public function track($data) |
| 73 | { |
| 74 | $data['sib_type'] = 'track'; |
| 75 | $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; |
| 76 | if (!array_key_exists('url',$data)) { |
| 77 | $data['url'] = $url; |
| 78 | } |
| 79 | |
| 80 | if (!array_key_exists('sib_name',$data)) { |
| 81 | if (array_key_exists('name',$data)) { |
| 82 | $data['sib_name'] = $data['name']; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | //get email cookie |
| 87 | |
| 88 | if (isset($_COOKIE['email_id']) && $_COOKIE['email_id'] != '') { |
| 89 | $data['email_id'] = $_COOKIE['email_id']; |
| 90 | } |
| 91 | if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') { |
| 92 | $data['session_id'] = $_COOKIE['session_id']; |
| 93 | } |
| 94 | |
| 95 | //store email cookie |
| 96 | $obj = $this->do_request($data); |
| 97 | if (isset($obj['email_id']) && $obj['email_id'] != '') { |
| 98 | $parsed = parse_url($url); |
| 99 | $host_parts = explode('.', $parsed['host']); |
| 100 | $domain = implode('.', array_slice($host_parts, count($host_parts)-2)); |
| 101 | //store email_id cookie |
| 102 | setcookie("email_id",$_COOKIE['email_id'] = $obj['email_id'],time() + 86400,"/",$domain); |
| 103 | } |
| 104 | } |
| 105 | public function page($data) |
| 106 | { |
| 107 | $data['sib_type'] = 'page'; |
| 108 | $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; |
| 109 | if (!array_key_exists('url',$data)) { |
| 110 | $data['url'] = $url; |
| 111 | } |
| 112 | //get email cookie |
| 113 | if (isset($_COOKIE['email_id']) && $_COOKIE['email_id'] != '') { |
| 114 | $data['email_id'] = $_COOKIE['email_id']; |
| 115 | } |
| 116 | if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') { |
| 117 | $data['session_id'] = $_COOKIE['session_id']; |
| 118 | } |
| 119 | //referrer |
| 120 | if (!array_key_exists('referrer',$data) && array_key_exists('HTTP_REFERER',$_SERVER)) { |
| 121 | $data['referrer'] = $_SERVER['HTTP_REFERER']; |
| 122 | } |
| 123 | //pathname |
| 124 | if (!array_key_exists('pathname',$data)) { |
| 125 | $data['pathname'] = $_SERVER['REQUEST_URI']; |
| 126 | } |
| 127 | |
| 128 | //name |
| 129 | if (!array_key_exists('name',$data)) { |
| 130 | $data['name'] = $_SERVER['REQUEST_URI']; |
| 131 | } |
| 132 | |
| 133 | //store email cookie |
| 134 | $obj = $this->do_request($data); |
| 135 | if (isset($obj['email_id']) && $obj['email_id'] != '') { |
| 136 | $parsed = parse_url($url); |
| 137 | $host_parts = explode('.', $parsed['host']); |
| 138 | $domain = implode('.', array_slice($host_parts, count($host_parts)-2)); |
| 139 | //store email_id cookie |
| 140 | setcookie("email_id",$_COOKIE['email_id'] = $obj['email_id'],time() + 86400,"/",$domain); |
| 141 | } |
| 142 | } |
| 143 | public function trackLink($data) |
| 144 | { |
| 145 | $data['sib_type'] = 'trackLink'; |
| 146 | //get email cookie |
| 147 | if (isset($_COOKIE['email_id']) && $_COOKIE['email_id'] != '') { |
| 148 | $data['email_id'] = $_COOKIE['email_id']; |
| 149 | } |
| 150 | if (isset($_COOKIE['session_id']) && $_COOKIE['session_id'] != '') { |
| 151 | $data['session_id'] = $_COOKIE['session_id']; |
| 152 | } |
| 153 | $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; |
| 154 | if (!array_key_exists('url',$data)) { |
| 155 | $data['url'] = $url; |
| 156 | } |
| 157 | //store email cookie |
| 158 | $obj = $this->do_request($data); |
| 159 | if (isset($obj['email_id']) && $obj['email_id'] != '') { |
| 160 | $parsed = parse_url($url); |
| 161 | $host_parts = explode('.', $parsed['host']); |
| 162 | $domain = implode('.', array_slice($host_parts, count($host_parts)-2)); |
| 163 | //store email_id cookie |
| 164 | setcookie("email_id",$_COOKIE['email_id'] = $obj['email_id'],time() + 86400,"/",$domain); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | ?> |
| 169 |