PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 1.5
Brevo – Email, SMS, Web Push, Chat, and more. v1.5
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 / mailinapi.class.php
mailin Last commit date
css 12 years ago emails 12 years ago img 12 years ago js 12 years ago lang 12 years ago ajaxcall.php 12 years ago ajaxcontent.php 12 years ago ajaxmanagesubscribe.php 12 years ago ajaxsmtp.php 12 years ago api_form.php 12 years ago compatibility.php 12 years ago cron.php 12 years ago listings.php 12 years ago mailin.php 12 years ago mailin_widget.php 12 years ago mailinapi.class.php 12 years ago readme.html 12 years ago
mailinapi.class.php
709 lines
1 <?php
2 class MailinApi
3 {
4 public $mailin_error = array();
5 public $mailin_success = array();
6 /**
7 * update user list
8 */
9 public function updateUserLists($api_key = null)
10 {
11 if ($api_key == '')
12 return;
13 elseif ($api_key != null)
14 $api_key = get_option('mailin_apikey');
15 $return_data = $this->getUserLists($api_key);
16 if (isset($return_data->result) && !empty($return_data->result))
17 {
18 $list_data = $return_data->result;
19 $lists = serialize($list_data);
20 update_option('mailin_lists', $lists);
21 }
22 }
23 /**
24 * check api key is validate or not
25 */
26 public function validateAPIkey($api_key = null)
27 {
28 $is_valid = false;
29 $error = '';
30 $list_data = array();
31 if ($api_key == '')
32 $error = 'Please enter API key';
33 else
34 {
35 $return_data = $this->getUserLists($api_key);
36 if (!is_object($return_data))
37 $error = 'Oops!, unable to connect!';
38 else if (isset($return_data->error_msg))
39 $error = $return_data->error_msg;
40 else if (isset($return_data->result))
41 {
42 $is_valid = true;
43 if (!empty($return_data->result))
44 $list_data = $return_data->result;
45 }
46 }
47 return $return_data = array(
48 'isValid' => $is_valid,
49 'data' => $list_data,
50 'error' => $error
51 );
52 }
53 /**
54 * handle api key form
55 */
56 public function handleApikeyFormSubmit($api_new_key = null)
57 {
58 $api_new_key = strip_tags(trim($api_new_key));
59 $return_data = $this->validateAPIkey($api_new_key);
60 if ($return_data['error'] != '')
61 $this->mailin_error[] = __($return_data['error'], 'mailin_i18n');
62 else if (!$return_data['isValid'])
63 $this->mailin_error[] = __($return_data['error'], 'mailin_i18n');
64 else {
65 $this->mailin_success[] = __('Successfully Updated', 'mailin_i18n');
66 $api_previous_key = get_option('mailin_apikey');
67 update_option('mailin_apikey', $api_new_key);
68 update_option('mailin_manage_subscribe', 1);
69 if ($api_previous_key == null)
70 $this->createFolderName();
71 elseif ($api_new_key != $api_previous_key)
72 {
73 $this->mailinRemove();
74 $this->createFolderName();
75 }
76 update_option('mailin_apikey_status', $_POST['mailin_api_status']);
77 $this->updateUserLists($api_new_key);
78 }
79 }
80 /**
81 * Method is being called at the time of put another key the Mailin plugin.
82 */
83 public function mailinRemove()
84 {
85 update_option('mailin_list_selected', '');
86 update_option('mailin_smtp', '');
87 update_option('mailin_lists', '');
88 update_option('mailin_manage_subscribe', '');
89 update_option('mailin_apikey_status', '');
90 $mailinsmtp_options = array(
91 'mail_from' => '',
92 'mail_from_name' => '',
93 'mailer' => 'mail',
94 'mail_set_return_path' => 'false',
95 'mailin_smtp_host' => 'localhost',
96 'mailin_smtp_port' => '25',
97 'mailin_smtp_ssl' => 'none',
98 'mailin_smtp_auth' => false,
99 'mailin_smtp_user' => '',
100 'mailin_smtp_pass' => ''
101 );
102 // Create the required options...
103 foreach ($mailinsmtp_options as $name => $val)
104 update_option($name, $val);
105 }
106 /**
107 * Creates a list by the name "wordpress" on user's Mailin account.
108 */
109 public function createNewList($response, $exist_list)
110 {
111 if ($exist_list != '')
112 {
113 $date = date('dmY');
114 $list_name = 'wordpress_'.$date;
115 } else
116 $list_name = 'wordpress';
117 $api_key = get_option('mailin_apikey');
118 $data = array();
119 $data['key'] = $api_key;
120 $data['listname'] = $list_name;
121 $data['webaction'] = 'NEWLIST';
122 $data['list_parent'] = $response; //folder id
123 $list_response = json_decode($this->curlRequest($data));
124 $this->sendAllMailIDToMailin($list_response->result);
125 }
126 /**
127 * functions used for create folder
128 */
129 public function createFolderName()
130 {
131 $this->createAttributesName();
132 $result = $this->checkFolderList();
133 if (empty($result[1]))
134 {
135 $data = array();
136 $data['key'] = get_option('mailin_apikey');
137 $data['webaction'] = 'ADDFOLDER';
138 $data['foldername'] = 'wordpress';
139 $res = $this->curlRequest($data);
140 $res = json_decode($res);
141 $folder_id = $res->folder_id;
142 $exist_list = '';
143 } else
144 {
145 $folder_id = $result[0];
146 $exist_list = $result[2];
147 }
148 $this->createNewList($folder_id, $exist_list); // create list in mailin
149 $this->partnerWordpress(); // create partner name
150 }
151 /**
152 * Method is used to add the partner's name in Mailin.
153 * In this case its "WORDPRESS".
154 */
155 public function partnerWordpress()
156 {
157 $data['key'] = get_option('mailin_apikey');
158 $data['webaction'] = 'MAILIN-PARTNER';
159 $data['partner'] = 'WORDPRESS';
160 $list_response = $this->curlRequest($data);
161 }
162 /**
163 * Fetches all folders and all list within each folder of the user's Mailin
164 * account and displays them to the user.
165 */
166 public function checkFolderList()
167 {
168 $data = array();
169 $data['key'] = get_option('mailin_apikey');
170 $data['webaction'] = 'DISPLAY-FOLDERS-LISTS';
171 $data['ids'] = ''; //folder id
172 $s_array = array();
173 $list_response = $this->curlRequest($data);
174 $res = json_decode($list_response, true);
175 if (isset($res) && !empty($res))
176 {
177 foreach ($res as $key => $value)
178 {
179 if (strtolower($value['name']) == 'wordpress')
180 {
181 $s_array[] = $key;
182 $s_array[] = $value['name'];
183 }
184 if (!empty($value['lists']))
185 {
186 foreach ($value['lists'] as $val)
187 {
188 if (strtolower($val['name']) == 'wordpress')
189 $s_array[] = $val['name'];
190 }
191 }
192 }
193 }
194 return $s_array;
195 }
196 /**
197 * Checks if a folder 'Wordpress' and a list "Wordpress" exits in the Mailin account.
198 * If they do not exits, this method creates them.
199 */
200 public function createFolderCaseTwo()
201 {
202 $result = $this->checkFolderList();
203 $list_name = 'wordpress';
204 $param = array();
205 $data = array();
206 $folder_id = $result[0];
207 $exist_list = $result[2];
208 if (empty($result[1]))
209 {
210 $data['key'] = get_option('mailin_apikey');
211 $data['webaction'] = 'ADDFOLDER';
212 $data['foldername'] = 'wordpress';
213 $res = $this->curlRequest($data);
214 $res = json_decode($res);
215 $folder_id = $res->folder_id;
216 $param['key'] = get_option('mailin_apikey');
217 $param['listname'] = $list_name;
218 $param['webaction'] = 'NEWLIST';
219 $param['list_parent'] = $folder_id; //folder id
220 $list_response = $this->curlRequest($param);
221 $res = json_decode($list_response);
222 $list_id = $res->result;
223 // import old user to mailin
224 $this->sendAllMailIDToMailin($list_id);
225 } elseif (empty($exist_list))
226 {
227 // create list
228 $param['key'] = get_option('mailin_apikey');
229 $param['listname'] = $list_name;
230 $param['webaction'] = 'NEWLIST';
231 $param['list_parent'] = $folder_id; //folder id
232 $list_response = $this->curlRequest($param);
233 $res = json_decode($list_response);
234 $list_id = $res->result;
235 $this->sendAllMailIDToMailin($list_id);
236 }
237 }
238 /**
239 * Method is used to send all the subscribers from Wordpress to
240 * Mailin for adding / updating purpose.
241 */
242 public function sendAllMailIDToMailin($list)
243 {
244 $lang = get_bloginfo('language');
245 update_option('mailin_list_selected', trim($list));
246 if ($lang == 'en-US')
247 $l = 'en';
248 else
249 $l = 'fr';
250 $api_key = get_option('mailin_apikey');
251 $allemail = $this->autoSubscribeAfterInstallation();
252 if ($allemail != false)
253 {
254 $data = array();
255 $data['webaction'] = 'MULTI-USERCREADIT';
256 $data['key'] = $api_key;
257 $data['attributes'] = $allemail;
258 $data['lang'] = $l;
259 $data['listid'] = $list; // List id should be optional
260 $response = $this->curlRequest($data);
261 } else
262 return false;
263 }
264 /**
265 * Fetches the SMTP and order tracking details
266 */
267 public function trackingSmtp()
268 {
269 $api_key = get_option('mailin_apikey');
270 $data = array();
271 $data['key'] = $api_key;
272 $data['webaction'] = 'TRACKINGDATA';
273 return json_decode($this->curlRequest($data));
274 }
275 /**
276 * Create Normal attributes and their values
277 * on Mailin platform. This is necessary for the Wordpress to add subscriber's details.
278 */
279 public function createAttributesName()
280 {
281 $data = array();
282 $api_key = get_option('mailin_apikey');
283 $data['key'] = $api_key;
284 $data['webaction'] = 'ATTRIBUTES_CREATION';
285 $data['normal_attributes'] = 'PRENOM,text|NOM,text|CLIENT,number';
286 return $this->curlRequest($data);
287 }
288 /**
289 * This method is used to check the subscriber's newsletter subscription status in Mailin
290 */
291 public function checkusermainStatus($result)
292 {
293 $data = array();
294 $userstatus = array();
295 if (isset($result))
296 foreach ($result as $value)
297 $userstatus[] = $value->email;
298 $email = implode(',', $userstatus);
299 $api_key = get_option('mailin_apikey');
300 $data['key'] = $api_key;
301 $data['webaction'] = 'USERS-STATUS';
302 $data['email'] = $email;
303 return json_decode($this->curlRequest($data), true);
304 }
305 /**
306 * Fetches all the subscribers of Wordpress and adds them to the Mailin database.
307 */
308 public function autoSubscribeAfterInstallation()
309 {
310 $users = $this->getAllSubscribers();
311 $data = array();
312 if (!empty($users))
313 foreach ($users as $subs)
314 $data[] = array(
315 'email' => $subs->email,
316 'PRENOM' => $subs->fname,
317 'NOM' => $subs->lname
318 );
319 if (!empty($data))
320 return json_encode($data);
321 else
322 return false;
323 }
324 /**
325 * update list form submit
326 */
327 public function handleUpdateListFormSubmit($list_id)
328 {
329 if (!empty($list_id))
330 {
331 $this->updateUserLists();
332 $list_id = implode('|', $list_id);
333 update_option('mailin_list_selected', $list_id);
334 update_option('mailin_unsubscribe', $_POST['unsubscription']);
335 $this->mailin_success[] = __('Successfully Updated', 'mailin_i18n');
336 } else
337 $this->mailin_error[] = __('Please select a list', 'mailin_i18n');
338 }
339 /**
340 * validate manage subscribe
341 */
342 public function manageSubscribe()
343 {
344 update_option('mailin_manage_subscribe', $_POST['managesubscribe']);
345 }
346 /**
347 * validate newsletter form
348 */
349 public function validateNewsletterForm($email, $fname, $lname)
350 {
351 if (!preg_match('/^([a-z0-9]+([_\.\-]{1}[a-z0-9]+)*){1}([@]){1}([a-z0-9]+([_\-]{1}[a-z0-9]+)*)+(([\.]{1}[a-z]{2,6}){0,3}){1}$/i', $email))
352 $this->mailin_error['email'] = __('Please enter valid e-mail', 'mailin_i18n');
353 if ($fname == '' && isset($_POST['fname']))
354 $this->mailin_error['fname'] = __('Please enter your first name', 'mailin_i18n');
355 if ($lname == '' && isset($_POST['lname']))
356 $this->mailin_error['lname'] = __('Please enter your last name', 'mailin_i18n');
357 return $this->mailin_error;
358 }
359 /**
360 * handle newsletter subscribe form
361 */
362 public function handleNewsletterSubscribeSubmit()
363 {
364 if (!$this->syncronizeSetting())
365 return false;
366 $email = trim(strip_tags($_POST['mailin_email']));
367 $email = strtolower($email);
368 $fname = isset($_POST['fname']) ? trim(strip_tags($_POST['fname'])) : '';
369 $lname = isset($_POST['lname']) ? trim(strip_tags($_POST['lname'])) : '';
370 $action = isset($_POST['action']) ? trim(strip_tags($_POST['action'])) : 5;
371 if ($action == 2)
372 $action = 0;
373 if ($action == 5)
374 $action = 1;
375 $this->validateNewsletterForm($email, $fname, $lname);
376 if (empty($this->mailin_error))
377 {
378 $api_key = get_option('mailin_apikey');
379 $selected_list = get_option('mailin_list_selected');
380 if ($action == 1)
381 $return_data = $this->createUser($api_key, $email, $selected_list, $fname, $lname);
382 else
383 {
384 $return_data = $this->unSubUser($api_key, $email);
385 global $wpdb;
386 $myrows = $wpdb->get_results('SELECT id FROM '.MAILIN_SUBSCRIBERS.' WHERE email = "'.$email.'" LIMIT 1');
387 if ($action == 0 && empty($myrows))
388 {
389 $this->mailin_error['doesnotexist'] = __('Email filled does not exist in our database', 'mailin_i18n');
390 return false;
391 }
392 }
393 if (!is_object($return_data))
394 $error = 'Oops!, unable to connect!';
395 else if ((isset($return_data->msg_ty) && $return_data->msg_ty == 'success') || isset($return_data->result))
396 {
397 $this->updateUserLists($api_key);
398 $this->updateSubscribers($email, $selected_list, $fname, $lname, $action, 0);
399 if ($action == 0)
400 $this->mailin_success[] = __('Unsubscription successful', 'mailin_i18n');
401 else
402 $this->mailin_success[] = __('Subscription successful', 'mailin_i18n');
403 } else if (isset($return_data->msg_ty) && $return_data->msg_ty == 'error')
404 $this->mailin_error[] = __($return_data->msg, 'mailin_i18n');
405 }
406 }
407 /**
408 * make curl request
409 */
410 public function curlRequest($data)
411 {
412 $url = 'http://ws.mailin.fr/'; //WS URL
413 $ch = curl_init();
414 // prepate data for curl post
415 $ndata = '';
416 if (is_array($data))
417 {
418 foreach ($data as $key => $value)
419 $ndata .= $key.'='.urlencode($value).'&';
420 } else
421 $ndata = $data;
422 curl_setopt($ch, CURLOPT_HTTPHEADER, array(
423 'Expect:'
424 ));
425 curl_setopt($ch, CURLOPT_POST, 1);
426 curl_setopt($ch, CURLOPT_POSTFIELDS, $ndata);
427 curl_setopt($ch, CURLOPT_HEADER, 0);
428 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
429 curl_setopt($ch, CURLOPT_URL, $url);
430 $data = curl_exec($ch);
431 curl_close($ch);
432 return $data;
433 }
434 /**
435 * Subscribe a subscriber from Mailin.
436 */
437 public function createUser($api_key = null, $email, $list_id, $fname, $lname)
438 {
439 $client = 0;
440 $attribute = $fname.'|'.$lname.'|'.$client;
441 $data['key'] = $api_key;
442 $data['webaction'] = 'USERCREADITM';
443 $data['email'] = $email;
444 $data['id'] = '';
445 $data['blacklisted'] = '';
446 $data['attributes_name'] = 'PRENOM|NOM';
447 $data['attributes_value'] = $attribute;
448 $data['listid'] = $list_id;
449 return json_decode($this->curlRequest($data));
450 }
451 /**
452 * Subscribe a register user from Mailin.
453 */
454 public function createRegistrationUser($api_key = null, $email, $list_id, $fname, $lname)
455 {
456 $client = 1;
457 $attribute = $fname.'|'.$lname.'|'.$client;
458 $data['key'] = $api_key;
459 $data['webaction'] = 'USERCREADITM';
460 $data['email'] = $email;
461 $data['id'] = '';
462 $data['blacklisted'] = '';
463 $data['attributes_name'] = 'PRENOM|NOM|CLIENT';
464 $data['attributes_value'] = $attribute;
465 $data['listid'] = $list_id;
466 return json_decode($this->curlRequest($data));
467 }
468 /**
469 * Unsubscribe a subscriber from Mailin.
470 */
471 public function unSubUser($api_key = null, $email)
472 {
473 $data['key'] = $api_key;
474 $data['webaction'] = 'EMAILBLACKLIST';
475 $data['blacklisted'] = '0';
476 $data['email'] = $email;
477 return json_decode($this->curlRequest($data));
478 }
479 /**
480 * Fetches all the list of the user from the Mailin platform.
481 */
482 public function getUserLists($api_key = null, $list_id = null)
483 {
484 if ($api_key == '')
485 return;
486 $data = array();
487 $data['key'] = $api_key;
488 $data['webaction'] = 'DISPLAYLISTDATA';
489 if ($list_id != null)
490 $data['listids'] = $list_id;
491 return json_decode($this->curlRequest($data));
492 }
493 /**
494 * This is an automated version of the usersStatusTimeStamp method but is called using a CRON.
495 */
496 public function usersStatus($api_key)
497 {
498 if ($api_key == '')
499 return;
500 $timezone = get_option('timezone_string');
501 $users = $this->getAllUsers();
502 $userstatus = array();
503 $data = array();
504 if (!empty($users))
505 {
506 foreach ($users as $subs)
507 $userstatus[] = $subs->email.','.$subs->subscribed.','.$subs->create_date;
508 }
509 $userstatus = implode('|', $userstatus);
510 $data['key'] = $api_key;
511 $data['webaction'] = 'UPDATE-USER-SUBSCRIPTION-STATUS';
512 $data['timezone'] = $timezone;
513 $data['user_status'] = $userstatus;
514 return json_decode($this->curlRequest($data), true);
515 }
516 /**
517 * validate user
518 */
519 public function validateUser($api_key, $email)
520 {
521 if ($api_key == '')
522 return;
523 $data = array();
524 $data['key'] = $api_key;
525 $data['webaction'] = 'DISPLAYUSERDETAIL';
526 $data['email'] = $email;
527 return json_decode($this->curlRequest($data));
528 }
529 /**
530 * Checks whether the Mailin API key and the Mailin subscription form is enabled
531 * and returns the true|false accordingly.
532 */
533 public function syncronizeSetting()
534 {
535 $api_key = get_option('mailin_apikey');
536 $mailin_apikey_status = get_option('mailin_apikey_status');
537 $mailin_manage_subscribe = get_option('mailin_manage_subscribe');
538 if ($api_key == false || $mailin_apikey_status == 0 || $mailin_manage_subscribe == 0)
539 return false;
540 else
541 return true;
542 }
543 /**
544 * Update subscriber
545 */
546 public function updateSubscribers($email, $selected_list, $fname, $lname, $action, $type)
547 {
548 $selected_list = explode('|', $selected_list);
549 $selected_list = implode(',', $selected_list);
550 if ($type == 1)
551 $client = 1;
552 else
553 $client = 0;
554 global $wpdb;
555 $myrows = $wpdb->get_results('SELECT id FROM '.MAILIN_SUBSCRIBERS.' WHERE email = "'.$email.'" LIMIT 1');
556 if ($action == 0 && empty($myrows))
557 {
558 $this->mailin_error['doesnotexist'] = __('Email filled does not exist in our database', 'mailin_i18n');
559 return false;
560 }
561 $timezone_format = _x('Y-m-d G:i:s', 'timezone date format');
562 $timezone_format = date_i18n($timezone_format);
563 // end local time code
564 if (empty($myrows))
565 {
566 $sql = 'INSERT INTO '.MAILIN_SUBSCRIBERS.'
567 SET email= "'.$email.'",subscribed = "'.$action.'" , fname = "'.$fname.'" ,
568 lname = "'.$lname.'" , list = "'.$selected_list.'" , create_date= "'.$timezone_format.'" , client = "'.$client.'" ';
569 $wpdb->query($sql);
570 } else
571 {
572 $sql = 'UPDATE '.MAILIN_SUBSCRIBERS.' SET list = "'.$selected_list.'" , fname = "'.$fname.'" ,
573 lname = "'.$lname.'" , subscribed = "'.$action.'", create_date= "'.$timezone_format.'", client = "'.$client.'" WHERE id = '.$myrows[0]->id;
574 $wpdb->query($sql);
575 }
576 }
577 public function smtpUpdateConfiguration()
578 {
579 update_option('mailin_smtp', $_POST['mailin_smtp_action']);
580 if ($_POST['mailin_smtp_action'] == 0)
581 {
582 $mailinsmtp_options = array(
583 'mail_from' => '',
584 'mail_from_name' => '',
585 'mailer' => 'mail',
586 'mail_set_return_path' => 'false',
587 'mailin_smtp_host' => 'localhost',
588 'mailin_smtp_port' => '25',
589 'mailin_smtp_ssl' => 'none',
590 'mailin_smtp_auth' => false,
591 'mailin_smtp_user' => '',
592 'mailin_smtp_pass' => ''
593 );
594 // Create the required options...
595 foreach ($mailinsmtp_options as $name => $val)
596 update_option($name, $val);
597 } else
598 {
599 $value = $this->trackingSmtp();
600 if ($value->result->relay_data->status == 'enabled')
601 {
602 $mailinsmtp_options = array(
603 'mail_from' => '',
604 'mail_from_name' => '',
605 'mailer' => 'smtp',
606 'mail_set_return_path' => 'false',
607 'mailin_smtp_host' => $value->result->relay_data->data->relay,
608 'mailin_smtp_port' => $value->result->relay_data->data->port,
609 'mailin_smtp_ssl' => 'true',
610 'mailin_smtp_auth' => 'true',
611 'mailin_smtp_user' => $value->result->relay_data->data->username,
612 'mailin_smtp_pass' => $value->result->relay_data->data->password
613 );
614 // Create the required options...
615 foreach ($mailinsmtp_options as $name => $val)
616 update_option($name, $val);
617 update_option('mailin_smtp', 1);
618 } else
619 update_option('mailin_smtp', 0);
620 }
621 }
622 /**
623 * get all subscribers users
624 */
625 public function getAllSubscribers($subs = 1)
626 {
627 global $wpdb;
628 $sql = 'SELECT * FROM '.MAILIN_SUBSCRIBERS.' WHERE 1=1 ';
629 if ($subs == 1)
630 $sql .= ' AND subscribed = "1" ';
631 return $wpdb->get_results($sql);
632 }
633 /**
634 * Returns the list of active user details
635 *
636 */
637 public function getAllUsers()
638 {
639 global $wpdb;
640 $sql = 'SELECT * FROM '.MAILIN_SUBSCRIBERS.' WHERE 1=1 ';
641 return $wpdb->get_results($sql);
642 }
643 /**
644 * Returns the list of active user details for pagination
645 *
646 */
647 public function getAllUsersPagination($start, $page)
648 {
649 global $wpdb;
650 $sql = 'SELECT * FROM '.MAILIN_SUBSCRIBERS.' LIMIT '.$start.','.$page;
651 return $wpdb->get_results($sql);
652 }
653 /**
654 * Returns the list of active user details for pagination
655 *
656 */
657 public function getTotalUsers()
658 {
659 global $wpdb;
660 return $wpdb->get_results('SELECT COUNT(*) as total FROM '.MAILIN_SUBSCRIBERS.' WHERE 1=1 ');
661 }
662 /**
663 * Get the total count of the unsubscribed
664 *
665 */
666 public function getTotalUnsubUsers()
667 {
668 global $wpdb;
669 return $wpdb->get_results('SELECT COUNT(*) as total FROM '.MAILIN_SUBSCRIBERS.' WHERE subscribed=0 ');
670 }
671 /**
672 * Get the total count of the subscribed
673 *
674 */
675 public function getTotalsubUsers()
676 {
677 global $wpdb;
678 return $wpdb->get_results('SELECT COUNT(*) as total FROM '.MAILIN_SUBSCRIBERS.' WHERE subscribed=1 ');
679 }
680 /**
681 * syncronize user with mailin
682 */
683 public function syncUsers()
684 {
685 if (get_option('mailin_list_selected') != '')
686 {
687 global $wpdb;
688 $api_key = get_option('mailin_apikey');
689 $dove = $this->usersStatus($api_key);
690 $timezone_format = _x('Y-m-d G:i:s', 'timezone date format');
691 $timezone_format = date_i18n($timezone_format);
692 if (empty($dove['errorMsg']))
693 {
694 foreach ($dove as $valuearray)
695 {
696 foreach ($valuearray as $key => $value)
697 {
698 $sql = 'UPDATE '.MAILIN_SUBSCRIBERS.' SET create_date = '.$timezone_format.', subscribed = '.$status.' WHERE email = "'.strtolower(trim($key)).'" ';
699 $myrows = $wpdb->query($sql);
700 } // end foreach
701 } // end foreach
702 echo 'done';
703 }
704 return true;
705 } else
706 return false;
707 }
708 }
709