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 / mailin.php
mailin Last commit date
css 12 years ago emails 13 years ago img 13 years ago js 13 years ago lang 13 years ago ajaxcall.php 13 years ago ajaxcontent.php 13 years ago ajaxmanagesubscribe.php 13 years ago ajaxsmtp.php 13 years ago api_form.php 13 years ago compatibility.php 13 years ago cron.php 13 years ago listings.php 13 years ago mailin.php 13 years ago mailin_widget.php 13 years ago mailinapi.class.php 13 years ago readme.html 13 years ago
mailin.php
505 lines
1 <?php
2 /**
3 Plugin Name: Mailin
4 Plugin URI: http://mailin.fr
5 Description: Synchronize your WordPress contacts with Mailin platform and send transactional emails easily to your customers.
6 Version: 1.5
7 Author: Mailin.fr
8 Author URI: http://www.mailin.fr
9 License: GPLv2 or later
10 */
11 /*
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 as published by the Free Software Foundation; either version 2
15 of the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 */
24 define('MAILIN_VER', '1.0.0');
25 define('WP_EMAIL_TEMPLATE_FOLDER', dirname(plugin_basename(__FILE__)));
26 define('WP_EMAIL_TEMPLATE_DIR', WP_CONTENT_DIR.'/plugins/'.WP_EMAIL_TEMPLATE_FOLDER);
27 initiallizeMailinConstants();
28 if (!class_exists('MailinApi'))
29 require_once('mailinapi.class.php');
30 require_once('compatibility.php');
31 /**
32 * init mailin plugin
33 */
34 function mailinInit()
35 {
36 mailinLoadResources();
37 //Internationalize the plugin
38 $i18n_file_name = 'mailin_lang';
39 $locale = apply_filters('plugin_locale', get_locale(), $i18n_file_name);
40 $filename = MAILIN_LANG_DIR.$i18n_file_name.'-'.$locale.'.mo';
41 load_textdomain('mailin_i18n', $filename);
42 }
43 add_action('init', 'mailinInit');
44 include_once('mailin_widget.php');
45 /**
46 * Loads the appropriate JS and CSS resources depending on
47 * settings and context (admin or not) *
48 * @return void
49 */
50 function mailinLoadResources()
51 {
52 wp_enqueue_style('mailin_wp_css', MAILIN_URL.'css/mailin_plugin.css');
53 }
54
55 /**
56 * Loads resources for the Mailin admin page
57 * @return void
58 */
59 function mailinLoadResourcesAdmin()
60 {
61 wp_enqueue_style('mailin_admin_css', MAILIN_URL.'css/admin.css');
62 }
63 add_action('load-settings_page_mailin_options', 'mailinLoadResourcesAdmin');
64 /**
65 *
66 * @param initialize smpt setting
67 */
68 function wpSmtp($phpmailer)
69 {
70 $admin_info = get_userdata(1);
71 if (!get_option('mailer') || (get_option('mailer') == 'smtp' && !get_option('mailin_smtp_host')))
72 return;
73 $phpmailer->Mailer = 'smtp';
74 if (defined('WPMS_SET_RETURN_PATH'))
75 $phpmailer->From = WPMS_SET_RETURN_PATH;
76 else
77 $phpmailer->From = $admin_info->user_email;
78
79 if (defined('WPMS_MAIL_FROM_NAME'))
80 $phpmailer->FromName = WPMS_MAIL_FROM_NAME;
81 else
82 $phpmailer->FromName = $admin_info->display_name;
83 $phpmailer->Sender = $phpmailer->From; //Return-Path
84 $phpmailer->AddReplyTo($phpmailer->From, $phpmailer->FromName); //Reply-To
85 $phpmailer->Host = get_option('mailin_smtp_host');
86 $phpmailer->SMTPSecure = get_option('mailin_smtp_ssl') == 'none' ? '' : get_option('mailin_smtp_ssl');
87 $phpmailer->Port = get_option('mailin_smtp_port');
88 $phpmailer->SMTPAuth = get_option('mailin_smtp_auth');
89 //$phpmailer->SMTPDebug = 2;
90 if ($phpmailer->SMTPAuth)
91 {
92 $phpmailer->SMTPAuth = true;
93 $phpmailer->Username = get_option('mailin_smtp_user');
94 $phpmailer->Password = get_option('mailin_smtp_pass');
95 }
96 }
97
98 $mailinsmtp = get_option('mailin_smtp');
99 $api_key = get_option('mailin_apikey');
100 $mailin_apikey_status = get_option('mailin_apikey_status');
101
102
103 if ($mailinsmtp == 1 && $api_key != '' && $mailin_apikey_status == 1)
104 add_action('phpmailer_init', 'wpSmtp');
105 register_activation_hook(__FILE__, 'mailinsmtpActivation');
106 /**
107 * Mailin smtp with default value
108 */
109 function mailinsmtpActivation()
110 {
111 $mailinsmtp_options = array('mail_from' => '',
112 'mail_from_name' => '',
113 'mailer' => 'mail',
114 'mail_set_return_path' => 'false',
115 'mailin_smtp_host' => 'localhost',
116 'mailin_smtp_port' => '25',
117 'mailin_smtp_ssl' => 'none',
118 'mailin_smtp_auth' => false,
119 'mailin_smtp_user' => '',
120 'mailin_smtp_pass' => '');
121 // Create the required options...
122 foreach ($mailinsmtp_options as $name => $val)
123 add_option($name, $val);
124 }
125 /**
126 * Update lists and campaigns on refreshing a page
127 *
128 */
129 $m_obj = new MailinApi();
130 $api_key = get_option('mailin_apikey');
131 if (is_admin() && isset($_GET['page']) && $_GET['page'] == 'mailin_options' && $api_key != '' && $_SERVER['REQUEST_METHOD'] == 'GET')
132 $m_obj->updateUserLists($api_key);
133
134 /**
135 * Gets or sets message
136 * @return string/bool depending on get/set
137 **/
138 function mailinMessages($msg = null)
139 {
140 global $mailin_msg;
141 if (!is_array($mailin_msg))
142 $mailin_msg = array();
143 if (is_null($msg))
144 return implode('', $mailin_msg);
145 $mailin_msg[] = $msg;
146 return true;
147 }
148 function mailinFormSubmit()
149 {
150 $action = '';
151 if (isset($_POST['mailin_form_action']))
152 {
153 $action = trim($_POST['mailin_form_action']);
154 if ($action == '')
155 return;
156 elseif ($action == 'sync_users')
157 {
158 $m_obj = new MailinApi();
159 if ($m_obj->syncUsers())
160 $message = '<div class="alert alert-success"" >'.__('Users synchronized successfully', 'mailin_i18n').'</div>';
161 else
162 $message = '<div class="alert alert-error" >'.__('Please choose atleast one list.', 'mailin_i18n').'</div>';
163 mailinMessages($message);
164 }elseif ($action == 'apikey_update')
165 {
166 //VALIDATE AND UPFATE API KEY
167 $m_obj = new MailinApi();
168 $m_obj->handleApikeyFormSubmit(strip_tags(stripslashes($_POST['mailin_apikey'])));
169 if (empty($m_obj->mailin_error))
170 {
171 $message = implode('<br/>', $m_obj->mailin_success);
172 $message = '<div class="alert alert-success"" >'.$message.'</div>';
173 mailinMessages($message);
174 } else
175 {
176 $message = implode('<br/>', $m_obj->mailin_error);
177 $message = '<div class="alert alert-error" >'.$message.'</div>';
178 mailinMessages($message);
179 }
180 } elseif ($action == 'update_list')
181 {
182 $mailin_list = isset($_POST['mailin_list']) ? $_POST['mailin_list'] : '';
183 $m_obj = new MailinApi();
184 $m_obj->handleUpdateListFormSubmit($mailin_list);
185 if (!empty($m_obj->mailin_error))
186 {
187 $message = implode('<br/>', $m_obj->mailin_error);
188 $message = '<div class="alert alert-error" >'.$message.'</div>';
189 mailinMessages($message);
190 }
191 if (!empty($m_obj->mailin_success))
192 {
193 $message = implode('<br/>', $m_obj->mailin_success);
194 $message = '<div class="alert alert-success"" >'.$message.'</div>';
195 mailinMessages($message);
196 }
197 } elseif ($action == 'subscribe_form_submit')
198 {
199 $m_obj = new MailinApi();
200 $m_obj->handleNewsletterSubscribeSubmit();
201 if (!empty($m_obj->mailin_error))
202 {
203 $message = implode('<br/>', $m_obj->mailin_error);
204 $message = '<div class="alert alert-error" >'.$message.'</div>';
205 mailinMessages($message);
206 }
207 if (!empty($m_obj->mailin_success))
208 {
209 $message = implode('<br/>', $m_obj->mailin_success);
210 $message = '<div class="alert alert-success"" >'.$message.'</div>';
211 mailinMessages($message);
212 }
213 }
214 }
215 }
216 /*
217 * mailin admin setting page
218 */
219 function mailinSettingsAdminPage()
220 {
221 // CHECK IF API KEY EXISTS
222 $api_key = get_option('mailin_apikey');
223 // Send test email if requested
224 if (isset($_POST['smtp_mailin']) && isset($_POST['to']))
225 {
226 $to = $_POST['to'];
227 $lang = get_bloginfo('language');
228 if ($lang == 'fr-FR')
229 {
230 $subject = '[Mailin SMTP] e-mail de test';
231 $from = 'contact@mailin.fr';
232 $fromname = 'Mailin';
233 }
234 else
235 {
236 $subject = '[Mailinblue SMTP] test email';
237 $fromname = 'Mailinblue';
238 $from = 'contact@mailinblue.com';
239 }
240 $failed = 0;
241 $message = emailTemplate();
242 define('WPMS_MAIL_FROM_NAME', $fromname);
243 define('WPMS_SET_RETURN_PATH', $from); // Sets $phpmailer->Sender if true
244 if (!empty($to) && !empty($subject) && !empty($message))
245 {
246 try {
247 $result = wp_mail($to, $subject, $message, $headers = "Content-Type: text/html\r\n", '');
248 if ($result == true)
249 {
250 $success_message = '<div id="message" class="alert alert-success"><p><strong>'.__('Mail sent', 'mailin_i18n').'</strong></p></div>';
251 mailinMessages($success_message);
252 } else{
253 $failed = 1;
254 }
255 }
256 catch (phpmailerException $e) {
257 $failed = 1;
258 }
259 } else{
260 $failed = 1;
261 }
262
263 if ($failed)
264 {
265 $error_message = '<div id="message" class="alert alert-error"><p><strong>'.__('Mail not sent', 'mailin_i18n').'</strong></p></div>';
266 mailinMessages($error_message);
267 }
268 }
269
270 ?>
271 <div class="wrap">
272 <?php
273 if (mailinMessages() != '')
274 {
275 ?>
276 <div id="mc_message" >
277 <?php
278 echo mailinMessages();
279 ?>
280 </div>
281 <?php
282 }
283 if ($api_key)
284 require 'listings.php';
285 else
286 require 'api_form.php';
287 ?>
288 </div>
289 <?php
290 }
291 add_action('admin_menu', 'adminMenus');
292 add_action('init', 'mailinFormSubmit');
293 /*
294 * show menu in admin
295 */
296 function adminMenus()
297 {
298 add_options_page('Mailin Setup', 'Mailin setup', 'administrator', 'mailin_options', 'mailinSettingsAdminPage');
299 }
300 /*
301 * show link in admin
302 */
303 function mailinActionLinks($links)
304 {
305 $settings_page = add_query_arg(array(
306 'page' => 'mailin_options'
307 ), admin_url('options-general.php'));
308 $settings_link = '<a href="'.esc_url($settings_page).'">'.__('Settings', 'mailin_i18n').'</a>';
309 array_unshift($links, $settings_link);
310 return $links;
311 }
312 add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'mailinActionLinks', 10, 1);
313 /*
314 * initilize constant
315 */
316 function initiallizeMailinConstants()
317 {
318 $locations = array('plugins' => array(
319 'dir' => WP_PLUGIN_DIR,
320 'url' => plugins_url()
321 ),
322 'template' => array(
323 'dir' => trailingslashit(get_template_directory()).'plugins/',
324 'url' => trailingslashit(get_template_directory_uri()).'plugins/'
325 ));
326 $mailin_dirbase = trailingslashit(basename(dirname(__FILE__)));
327 $mailin_dir = trailingslashit(WP_PLUGIN_DIR).$mailin_dirbase;
328 $mailin_url = trailingslashit(WP_PLUGIN_URL).$mailin_dirbase;
329 foreach ($locations as $key => $loc)
330 {
331 $dir = trailingslashit($loc['dir']).$mailin_dirbase;
332 $url = trailingslashit($loc['url']).$mailin_dirbase;
333 if (is_file($dir.basename(__FILE__)))
334 {
335 $mailin_dir = $dir;
336 $mailin_url = $url;
337 break;
338 }
339 }
340 //filesystem path
341 define('MAILIN_DIR', $mailin_dir);
342 /* Lang location */
343 define('MAILIN_LANG_DIR', trailingslashit(MAILIN_DIR).'lang/');
344 // plugin folder url
345 define('MAILIN_URL', $mailin_url);
346 global $wpdb;
347 // subscribers table name
348 define('MAILIN_SUBSCRIBERS', $wpdb->prefix.'mailin_subscribers');
349 }
350 /*
351 * Create subscribers table upon installation
352 */
353 function mailinInstall()
354 {
355 global $wpdb;
356 $sql = 'CREATE TABLE '.MAILIN_SUBSCRIBERS.' (
357 id int(11) NOT NULL AUTO_INCREMENT,
358 email VARCHAR(255) DEFAULT "" NOT NULL,
359 fname VARCHAR(55) DEFAULT "" NOT NULL,
360 lname VARCHAR(55) DEFAULT "" NOT NULL,
361 list VARCHAR(255) DEFAULT "" NOT NULL,
362 subscribed TINYINT(1) DEFAULT "1" NOT NULL,
363 client TINYINT(1) DEFAULT "0" NOT NULL,
364 create_date datetime DEFAULT "0000-00-00 00:00:00" NOT NULL,
365 UNIQUE KEY id (id)
366 );';
367 require_once(ABSPATH.'wp-admin/includes/upgrade.php');
368 dbDelta($sql);
369 }
370
371 /*
372 *mail template
373 */
374 function emailTemplate()
375 {
376 $lang = get_bloginfo('language');
377 if ($lang == 'fr-FR')
378 $file = 'mailinsmtp_conf.html';
379 else
380 $file = 'mailinsmtp_conf_en.html';
381 if (file_exists(STYLESHEETPATH.'/'.$file))
382 {
383 $header_template_path = STYLESHEETPATH.'/emails/'.$file;
384 $header_template_url = get_stylesheet_directory_uri().'/emails/'.$file;
385 } else
386 $header_template_path = WP_EMAIL_TEMPLATE_DIR.'/emails/'.$file;
387 $template_html = file_get_contents($header_template_path);
388 if ($template_html == false)
389 {
390 $ch = curl_init($header_template_url);
391 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
392 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
393 $template_html = curl_exec($ch);
394 curl_close($ch);
395 }
396 return $template_html;
397 }
398
399 /*
400 * when we deactive plugin call this function
401 */
402 function mailinRemove()
403 {
404 update_option('mailin_list_selected', '');
405 update_option('mailin_apikey', '');
406 update_option('mailin_smtp', '');
407 update_option('mailin_lists', '');
408 update_option('mailin_manage_subscribe', '');
409 update_option('mailin_apikey_status', '');
410 update_option('mailin_unsubscribe', '');
411 $mailinsmtp_options = array('mail_from' => '',
412 'mail_from_name' => '',
413 'mailer' => 'mail',
414 'mail_set_return_path' => 'false',
415 'mailin_smtp_host' => 'localhost',
416 'mailin_smtp_port' => '25',
417 'mailin_smtp_ssl' => 'none',
418 'mailin_smtp_auth' => false,
419 'mailin_smtp_user' => '',
420 'mailin_smtp_pass' => '');
421 // Create the required options...
422 foreach ($mailinsmtp_options as $name => $val)
423 update_option($name, $val);
424 }
425 /*
426 * when we delete plugin call this function
427 */
428 function mailinDelete()
429 {
430 delete_option('mailin_apikey');
431 delete_option('mailin_list_selected');
432 delete_option('widget_mailin_widget');
433 delete_option('mailin_smtp');
434 delete_option('mailin_lists');
435 delete_option('mailin_unsubscribe');
436 $mailinsmtp_options = array('mail_from' => '',
437 'mail_from_name' => '',
438 'mailer' => 'mail',
439 'mail_set_return_path' => 'false',
440 'mailin_smtp_host' => 'localhost',
441 'mailin_smtp_port' => '25',
442 'mailin_smtp_ssl' => 'none',
443 'mailin_smtp_auth' => false,
444 'mailin_smtp_user' => '',
445 'mailin_smtp_pass' => '');
446 // Create the required options...
447 foreach ($mailinsmtp_options as $name => $val)
448 delete_option($name);
449 global $wpdb;
450 $table = $wpdb->prefix.'mailin_subscribers';
451 $wpdb->query('DROP TABLE IF EXISTS '.$table);
452 }
453 /* Runs when plugin is activated */
454 register_activation_hook(__FILE__, 'mailinInstall');
455 /* Runs on plugin deactivation*/
456 register_deactivation_hook(__FILE__, 'mailinRemove');
457 /* Runs on plugin unistalling*/
458 register_uninstall_hook(__FILE__, 'mailinDelete');
459 class SiteUsers
460 {
461 public static function init()
462 {
463 // Change the user's display name after insertion
464 add_action('user_register', array(
465 __CLASS__,
466 'registerNewlyAddedUser'
467 ));
468 }
469 /*
470 * This function is called when a new user is created
471 * User is added in mailinlist
472 */
473 public static function registerNewlyAddedUser($user_id = null)
474 {
475 if ($user_id != null)
476 {
477 $info = get_userdata($user_id);
478
479
480 if (is_object($info))
481 {
482 $user = get_user_by( 'email', $info->data->user_email );
483
484 if (isset($info->data->user_email) && $info->data->user_email != '')
485 {
486
487 $user_nicename = isset($info->data->user_nicename) ? $info->data->user_nicename : '';
488 $fname = isset($user->first_name) ? $user->first_name : '';
489 $lname = isset($user->last_name) ? $user->last_name : '';
490 $selected_list = get_option('mailin_list_selected');
491 $api_key = get_option('mailin_apikey');
492 $m_obj = new MailinApi();
493 if (!$m_obj->syncronizeSetting())
494 return false;
495 $m_obj->createRegistrationUser($api_key, $info->data->user_email, $selected_list, $fname, $lname);
496 $m_obj->updateSubscribers($info->data->user_email, $selected_list, $fname, $lname, 1, 1);
497 }
498 }
499 }
500 wp_update_user($args);
501 }
502 }
503 SiteUsers::init();
504 ?>
505