PluginProbe
Brevo – Email, SMS, Web Push, Chat, and more. / 3.1.32
Brevo – Email, SMS, Web Push, Chat, and more. v3.1.32
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 All 140 releases
mailin / sendinblue.php
sendinblue.php
1,369 lines 47.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Newsletter, SMTP, Email marketing and Subscribe forms by Sendinblue
4 * Plugin URI: https://www.sendinblue.com/?r=wporg
5 * Description: Manage your contact lists, subscription forms and all email and marketing-related topics from your wp panel, within one single plugin
6 * Version: 3.1.32
7 * Author: Sendinblue
8 * Author URI: https://www.sendinblue.com/?r=wporg
9 * License: GPLv2 or later
10 *
11 * @package SIB
12 */
13
14 /*
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License
17 as published by the Free Software Foundation; either version 2
18 of the License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27
28 /**
29 * Application entry point. Contains plugin startup class that loads on <i> sendinblue_init </i> action.
30 */
31 if ( ! class_exists( 'Mailin' ) ) {
32 require_once( 'inc/mailin.php' );
33 }
34 if ( ! class_exists( 'SendinblueApiClient' ) ) {
35 require_once( 'inc/SendinblueApiClient.php' );
36 }
37 if ( ! class_exists( 'SendinblueAccount' ) ) {
38 require_once( 'inc/SendinblueAccount.php' );
39 }
40 // For marketing automation.
41 if ( ! class_exists( 'Sendinblue' ) ) {
42 require_once( 'inc/sendinblue.php' );
43 }
44
45 if ( ! class_exists( 'SIB_Manager' ) ) {
46 register_deactivation_hook( __FILE__, array( 'SIB_Manager', 'deactivate' ) );
47 register_activation_hook( __FILE__, array( 'SIB_Manager', 'install' ) );
48 register_uninstall_hook( __FILE__, array( 'SIB_Manager', 'uninstall' ) );
49
50 require_once( 'page/page-home.php' );
51 require_once( 'page/page-form.php' );
52 require_once( 'page/page-statistics.php' );
53 require_once( 'page/page-scenarios.php' );
54 require_once( 'widget/widget_form.php' );
55 require_once( 'inc/table-forms.php' );
56 require_once( 'inc/sib-api-manager.php' );
57 require_once( 'inc/sib-sms-code.php' );
58 require_once( 'model/model-forms.php' );
59 require_once( 'model/model-users.php' );
60 require_once( 'model/model-lang.php' );
61 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
62 require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
63 /**
64 * Class SIB_Manager
65 */
66 class SIB_Manager {
67
68 /** Main setting option name */
69 const MAIN_OPTION_NAME = 'sib_main_option';
70
71 /** Home setting option name */
72 const HOME_OPTION_NAME = 'sib_home_option';
73
74 /** Access token option name */
75 const ACCESS_TOKEN_OPTION_NAME = 'sib_token_store';
76
77 /** Plugin language notice option name */
78 const LANGUAGE_OPTION_NAME = 'sib_language_notice_option';
79
80 /** Form preview option name */
81 const PREVIEW_OPTION_NAME = 'sib_preview_form';
82
83 const API_KEY_V3_OPTION_NAME = 'sib_api_key_v3';
84
85 const RECAPTCHA_API_TEMPLATE = 'https://www.google.com/recaptcha/api/siteverify?%s';
86
87 /** Installation id option name */
88 const INSTALLATION_ID = 'sib_installation_id';
89
90 /**
91 * API key
92 *
93 * @var $access_key
94 */
95 public static $access_key;
96
97 /**
98 * Store instance
99 *
100 * @var $instance
101 */
102 public static $instance;
103
104 /**
105 * Plugin directory path value. set in constructor
106 *
107 * @var $plugin_dir
108 */
109 public static $plugin_dir;
110
111 /**
112 * Plugin url. set in constructor
113 *
114 * @var $plugin_url
115 */
116 public static $plugin_url;
117
118 /**
119 * Plugin name. set in constructor
120 *
121 * @var $plugin_name
122 */
123 public static $plugin_name;
124
125 /**
126 * Check if wp_mail is declared
127 *
128 * @var $wp_mail_conflict
129 */
130 static $wp_mail_conflict;
131
132 /**
133 * Class constructor
134 * Sets plugin url and directory and adds hooks to <i>init</i>. <i>admin_menu</i>
135 */
136 function __construct() {
137 // get basic info.
138 self::$plugin_dir = plugin_dir_path( __FILE__ );
139 self::$plugin_url = plugins_url( '', __FILE__ );
140 self::$plugin_name = plugin_basename( __FILE__ );
141
142 self::$wp_mail_conflict = false;
143
144 // api key for sendinblue.
145 $general_settings = get_option( self::MAIN_OPTION_NAME, array() );
146 self::$access_key = isset( $general_settings['access_key'] ) ? $general_settings['access_key'] : '';
147
148 self::$instance = $this;
149 add_action( 'upgrader_process_complete', array( &$this, 'my_upgrade_function' ), 10, 2);
150 add_action( 'admin_init', array( &$this, 'admin_init' ), 9999 );
151 add_action( 'admin_menu', array( &$this, 'admin_menu' ), 9999 );
152
153 add_action( 'wp_print_scripts', array( &$this, 'frontend_register_scripts' ), 9999 );
154 add_action( 'wp_enqueue_scripts', array( &$this, 'wp_head_ac' ), 999 );
155
156 // create custom url for form preview.
157 add_filter( 'query_vars', array( &$this, 'sib_query_vars' ) );
158 add_action( 'parse_request', array( &$this, 'sib_parse_request' ) );
159
160 add_action( 'wp_ajax_sib_validate_process', array( 'SIB_Page_Home', 'ajax_validation_process' ) );
161 add_action( 'wp_ajax_sib_validate_ma', array( 'SIB_Page_Home', 'ajax_validate_ma' ) );
162 add_action( 'wp_ajax_sib_activate_email_change', array( 'SIB_Page_Home', 'ajax_activate_email_change' ) );
163 add_action( 'wp_ajax_sib_sender_change', array( 'SIB_Page_Home', 'ajax_sender_change' ) );
164 add_action( 'wp_ajax_sib_send_email', array( 'SIB_Page_Home', 'ajax_send_email' ) );
165 add_action( 'wp_ajax_sib_remove_cache', array( 'SIB_Page_Home', 'ajax_remove_cache' ) );
166 add_action( 'wp_ajax_sib_sync_users', array( 'SIB_Page_Home', 'ajax_sync_users' ) );
167
168 add_action( 'wp_ajax_sib_change_template', array( 'SIB_Page_Form', 'ajax_change_template' ) );
169 add_action( 'wp_ajax_sib_get_lists', array( 'SIB_Page_Form', 'ajax_get_lists' ) );
170 add_action( 'wp_ajax_sib_get_templates', array( 'SIB_Page_Form', 'ajax_get_templates' ) );
171 add_action( 'wp_ajax_sib_get_attributes', array( 'SIB_Page_Form', 'ajax_get_attributes' ) );
172 add_action( 'wp_ajax_sib_update_form_html', array( 'SIB_Page_Form', 'ajax_update_html' ) );
173 add_action( 'wp_ajax_sib_copy_origin_form', array( 'SIB_Page_Form', 'ajax_copy_origin_form' ) );
174
175 add_action( 'wp_ajax_sib_get_country_prefix', array( $this, 'ajax_get_country_prefix' ) );
176 add_action( 'wp_ajax_nopriv_sib_get_country_prefix', array( $this, 'ajax_get_country_prefix' ) );
177
178 add_action( 'init', array( &$this, 'init' ) );
179
180 add_action( 'wp_login', array( &$this, 'sib_wp_login_identify' ), 10, 2 );
181
182 // change sib tables name on prior(2.6.9) versions.
183 SIB_Model_Users::add_prefix();
184 SIB_Forms::add_prefix();
185 SIB_Forms::modify_datatype();
186
187 if ( self::is_api_key_set() ) {
188 add_shortcode( 'sibwp_form', array( &$this, 'sibwp_form_shortcode' ) );
189 // register widget.
190 add_action( 'widgets_init', array( &$this, 'sib_create_widget' ) );
191
192 // create forms tables and create default form.
193 SIB_Forms::createTable();
194 // create users table.
195 SIB_Model_Users::createTable();
196 // add columns for old versions
197 SIB_Forms::alterTable();
198 SIB_Model_Users::add_user_added_date_column();
199 }
200
201 $use_api_version = get_option( 'sib_use_apiv2', '0' );
202 if ( '0' === $use_api_version ) {
203 self::uninstall();
204 update_option( 'sib_use_apiv2', '1' );
205 }
206
207 // Wpml plugin part.
208 if ( ! function_exists( 'is_plugin_active_for_network' ) ) :
209 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
210 endif;
211 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) || is_plugin_active_for_network( 'sitepress-multilingual-cms/sitepress.php' ) ) {
212 SIB_Forms_Lang::createTable();
213 add_action( 'sib_language_sidebar', array( $this, 'sib_create_language_sidebar' ) );
214 }
215
216 /**
217 * Hook wp_mail to send transactional emails
218 */
219
220 // check if wp_mail function is already declared by others.
221 if ( function_exists( 'wp_mail' ) ) {
222 self::$wp_mail_conflict = true;
223 }
224 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME, array() );
225
226 if( 'yes' === $home_settings['activate_email'] )
227 {
228 if ( false === self::$wp_mail_conflict ) {
229 /**
230 * Declare wp_mail function for Sendinblue SMTP module
231 *
232 * @param string $to - receiption email.
233 * @param string $subject - subject of email.
234 * @param string $message - message content.
235 * @param string $headers - header of email.
236 * @param array $attachments - attachments.
237 * @return bool
238 */
239 function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
240 $message = str_replace( 'NF_SIB', '', $message );
241 $message = str_replace( 'WC_SIB', '', $message );
242 try {
243 $sent = SIB_Manager::sib_email( $to, $subject, $message, $headers, $attachments );
244 if ( is_wp_error( $sent ) || ! isset( $sent['code'] ) || 'success' !== $sent['code'] ) {
245 try{
246 return true;
247 }catch( Exception $e ){
248 return false;
249 }
250 }
251 return true;
252 } catch ( Exception $e ) {
253 return false;
254 }
255 }
256 } else {
257 add_action( 'admin_notices', array( &$this, 'wpMailNotices' ) );
258 return;
259 }
260 }
261 }
262
263 /**
264 * Add identify tag for login users
265 *
266 * @param string $user_login - user login name.
267 * @param array $user - user.
268 */
269 function sib_wp_login_identify( $user_login, $user ) {
270
271 $userEmail = $user->user_email;
272 $data = array(
273 'email_id' => $userEmail,
274 'name' => $user_login,
275 );
276 SIB_API_Manager::identify_user( $data );
277 }
278
279 /**
280 * Initialize method. called on <i>init</i> action
281 */
282 function init() {
283 // Sign up process.
284 if ( isset( $_POST['sib_form_action'] ) && ( 'subscribe_form_submit' == sanitize_text_field($_POST['sib_form_action']) ) ) {
285 $this->signup_process();
286 }
287 // Subscribe.
288 if ( isset( $_GET['sib_action'] ) && ( 'subscribe' == sanitize_text_field($_GET['sib_action']) ) ) {
289 $code = isset( $_GET['code'] ) ? sanitize_text_field( $_GET['code'] ) : '';
290 $contact_info = SIB_Model_Users::get_data_by_code( $code );
291 $user_added_date = $contact_info['user_added_date'];
292 $current_date = gmdate( 'Y-m-d H:i:s' );
293 $date_diff = strtotime( $current_date ) - strtotime( $user_added_date );
294 if ( $date_diff > 5 ) {
295 SIB_API_Manager::subscribe( $contact_info );
296 } else {
297 $type = 'Bot Event';
298 SIB_API_Manager::template_subscribe( $type );
299 }
300 exit;
301 }
302 // Dismiss language notice.
303 if ( isset( $_GET['dismiss_admin_lang_notice'] ) && '1' == sanitize_text_field($_GET['dismiss_admin_lang_notice']) ) {
304 update_option( SIB_Manager::LANGUAGE_OPTION_NAME, true );
305 wp_safe_redirect( $_SERVER['HTTP_REFERER'] );
306 exit();
307 }
308
309 add_action( 'wp_head', array( &$this, 'install_ma_script' ) );
310 }
311
312 /**
313 * Hook admin_init
314 */
315 function admin_init() {
316 add_action( 'admin_action_sib_setting_subscription', array( 'SIB_Page_Form', 'save_setting_subscription' ) );
317 add_action( 'admin_action_nopriv_sib_setting_subscription', array( 'SIB_Page_Form', 'save_setting_subscription' ) );
318 SIB_Manager::LoadTextDomain();
319 $this->register_scripts();
320 $this->register_styles();
321 }
322
323 /**
324 * Hook admin_menu
325 */
326 function admin_menu() {
327 SIB_Manager::LoadTextDomain();
328 new SIB_Page_Home();
329 new SIB_Page_Form();
330 new SIB_Page_Statistics();
331 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
332 if ( isset( $home_settings['activate_ma'] ) && 'yes' == $home_settings['activate_ma'] ) {
333 new SIB_Page_Scenarios();
334 }
335
336 }
337
338 /**
339 * Register script for admin page
340 */
341 function register_scripts() {
342 wp_register_script( 'sib-bootstrap-js', self::$plugin_url . '/js/bootstrap/js/bootstrap.min.js', array( 'jquery' ), null );
343 wp_register_script( 'sib-admin-js', self::$plugin_url . '/js/admin.js', array( 'jquery' ), filemtime( self::$plugin_dir . '/js/admin.js' ) );
344 wp_register_script( 'sib-chosen-js', self::$plugin_url . '/js/chosen.jquery.min.js', array( 'jquery' ), null );
345 wp_enqueue_script('jquery-ui-datepicker');
346 wp_enqueue_script('jquery-ui-spinner');
347 }
348
349 /**
350 * Register stylesheet for admin page
351 */
352 function register_styles() {
353 wp_register_style( 'sib-bootstrap-css', self::$plugin_url . '/js/bootstrap/css/bootstrap.css', array(), null, 'all' );
354 wp_register_style( 'sib-fontawesome-css', self::$plugin_url . '/css/fontawesome/css/font-awesome.css', array(), null, 'all' );
355 wp_register_style( 'sib-chosen-css', self::$plugin_url . '/css/chosen.min.css' );
356 wp_register_style( 'sib-admin-css', self::$plugin_url . '/css/admin.css', array(), filemtime( self::$plugin_dir . '/css/admin.css' ), 'all' );
357 }
358
359 /**
360 * Registers scripts for frontend
361 */
362 function frontend_register_scripts() {
363
364 }
365
366 /**
367 * Enqueue script on front page
368 */
369 function wp_head_ac() {
370 wp_enqueue_script( 'sib-front-js', self::$plugin_url . '/js/mailin-front.js', array( 'jquery' ), filemtime( self::$plugin_dir . '/js/mailin-front.js' ), false );
371 wp_enqueue_style( 'sib-front-css', self::$plugin_url.'/css/mailin-front.css', array(), array(), 'all');
372 wp_localize_script(
373 'sib-front-js', 'sibErrMsg', array(
374 'invalidMail' => __( 'Please fill out valid email address', 'mailin' ),
375 'requiredField' => __( 'Please fill out required fields', 'mailin' ),
376 'invalidDateFormat' => __( 'Please fill out valid date format', 'mailin' ),
377 'invalidSMSFormat' => __( 'Please fill out valid phone number', 'mailin' ),
378 )
379 );
380 wp_localize_script(
381 'sib-front-js', 'ajax_sib_front_object',
382 array(
383 'ajax_url' => admin_url( 'admin-ajax.php' ),
384 'ajax_nonce' => wp_create_nonce( 'sib_front_ajax_nonce' ),
385 'flag_url' => plugins_url('img/flags/', __FILE__ ),
386 )
387 );
388 }
389
390 /**
391 * Install method is called once install this plugin.
392 * create tables, default option ...
393 */
394 static function install() {
395 $general_settings = get_option( self::MAIN_OPTION_NAME, array() );
396 $access_key = isset( $general_settings['access_key'] ) ? $general_settings['access_key'] : '';
397 if ( '' === $access_key ) {
398 // Default option when activate.
399 $home_settings = array(
400 'activate_email' => 'no',
401 'activate_ma' => 'no',
402 );
403 update_option( self::HOME_OPTION_NAME, $home_settings );
404 }
405 }
406
407 /**
408 * Uninstall method is called once uninstall this plugin
409 * delete tables, options that used in plugin
410 */
411 static function uninstall() {
412 $setting = array();
413 update_option( SIB_Manager::MAIN_OPTION_NAME, $setting );
414
415 $home_settings = array(
416 'activate_email' => 'no',
417 'activate_ma' => 'no',
418 );
419 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
420
421 // Delete access_token.
422 $token_settings = array();
423 update_option( SIB_Manager::ACCESS_TOKEN_OPTION_NAME, $token_settings );
424 delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME);
425 // Empty tables.
426 SIB_Model_Users::removeTable();
427 SIB_Forms::removeTable();
428 SIB_Forms_Lang::removeTable();
429
430 // Remove all transient.
431 SIB_API_Manager::remove_transients();
432 }
433
434 /**
435 * Deactivate method is called once deactivate this plugin
436 */
437 static function deactivate() {
438 update_option( SIB_Manager::LANGUAGE_OPTION_NAME, false );
439 // Remove sync users option.
440 delete_option( 'sib_sync_users' );
441 // Remove all transient.
442 SIB_API_Manager::remove_transients();
443 }
444
445 /**
446 * Check if plugin is logged in.
447 *
448 * @param bool $redirect
449 * @return bool
450 */
451 static function is_done_validation($redirect = true) {
452 if (self::is_api_key_set()) {
453 $apiClient = new SendinblueApiClient();
454 $apiClient->getAccount();
455 if ( SendinblueApiClient::RESPONSE_CODE_OK === $apiClient->getLastResponseCode() ) {
456 return true;
457 } elseif (SendinblueApiClient::RESPONSE_CODE_UNAUTHORIZED === $apiClient->getLastResponseCode()) {
458 delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME);
459 }
460 }
461
462 if ($redirect) {
463 self::redirect_to_sib_plugin_homepage();
464 }
465
466 return false;
467 }
468
469 static function redirect_to_sib_plugin_homepage() {
470 wp_safe_redirect(add_query_arg('page', SIB_Page_Home::PAGE_ID, admin_url('admin.php')));
471 }
472
473 /**
474 * @return bool
475 */
476 static function is_api_key_set() {
477 $api_key = get_option(SIB_Manager::API_KEY_V3_OPTION_NAME);
478 return !empty($api_key);
479 }
480
481 /**
482 * Install marketing automation script in header
483 */
484 function install_ma_script() {
485 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME, array() );
486 if ( isset( $home_settings['activate_ma'] ) && 'yes' == $home_settings['activate_ma'] ) {
487 $general_settings = get_option( SIB_Manager::MAIN_OPTION_NAME, array() );
488 $ma_email = '';
489 $current_user = wp_get_current_user();
490 if ( $current_user instanceof WP_User ) {
491 $ma_email = $current_user->user_email;
492 }
493 $ma_key = $general_settings['ma_key'];
494 $output = '<script type="text/javascript">
495 (function() {window.sib ={equeue:[],client_key:"'. $ma_key .'"};/* OPTIONAL: email for identify request*/
496 window.sib.email_id = "'. $ma_email .'";
497 window.sendinblue = {}; for (var j = [\'track\', \'identify\', \'trackLink\', \'page\'], i = 0; i < j.length; i++) { (function(k) { window.sendinblue[k] = function() { var arg = Array.prototype.slice.call(arguments); (window.sib[k] || function() { var t = {}; t[k] = arg; window.sib.equeue.push(t);})(arg[0], arg[1], arg[2]);};})(j[i]);}var n = document.createElement("script"),i = document.getElementsByTagName("script")[0]; n.type = "text/javascript", n.id = "sendinblue-js", n.async = !0, n.src = "https://sibautomation.com/sa.js?key=" + window.sib.client_key, i.parentNode.insertBefore(n, i), window.sendinblue.page();})();
498 </script>';
499 echo $output;
500 }
501 }
502
503 /**
504 * Register widget
505 */
506 function sib_create_widget() {
507 register_widget( 'SIB_Widget_Subscribe' );
508 }
509
510 /**
511 * Display form on front page
512 *
513 * @param string $frmID - form ID.
514 * @param string $lang - form language.
515 */
516 function generate_form_box( $frmID = '-1', $lang = '' ) {
517 if ( 'oldForm' == $frmID ) {
518 $frmID = get_option( 'sib_old_form_id' );
519 } elseif ( '' != $lang ) {
520 $trans_id = SIB_Forms_Lang::get_form_ID( $frmID, $lang );
521 if ( null != $trans_id ) {
522 $frmID = $trans_id;
523 }
524 }
525
526 $formData = SIB_Forms::getForm( $frmID );
527
528 if ( empty( $formData ) ) {
529 return;
530 }
531 // Add Google recaptcha
532 if( '0' != $formData['gCaptcha'] ) {
533 if( '1' == $formData['gCaptcha'] ) { // For old forms.
534 $formData['html'] = preg_replace( '/([\s\S]*?)<div class="g-recaptcha"[\s\S]*?data-size="invisible"><\/div>/', '$1', $formData['html'] );
535 }
536 if ( '3' == $formData['gCaptcha'] ) // The case of using google recaptcha.
537 {
538 ?>
539 <script type="text/javascript" charset="utf-8">
540 var gCaptchaSibWidget;
541 var onloadSibCallback = function() {
542 var recaptchas = document.querySelectorAll('div[id=sib_captcha]');
543 for( i = 0; i < recaptchas.length; i++) {
544 gCaptchaSibWidget = grecaptcha.render(recaptchas[i], {
545 'sitekey' : '<?php echo $formData["gCaptcha_site"] ?>'
546 });
547 }
548 }
549 </script>
550 <?php
551 }
552 else { // The case of using google invisible recaptcha.
553 ?>
554 <script type="text/javascript">
555 var gCaptchaSibWidget;
556 var onloadSibCallback = function() {
557 var element = document.getElementsByClassName('sib-default-btn');
558 gCaptchaSibWidget = grecaptcha.render(element[0],{
559 'sitekey' : '<?php echo $formData["gCaptcha_site"] ?>',
560 'callback' : sibVerifyCallback
561 });
562 };
563 </script>
564 <?php
565 }
566 ?>
567 <script src="https://www.google.com/recaptcha/api.js?onload=onloadSibCallback&render=explicit" async defer></script>
568 <?php
569 }
570
571 ?>
572 <form id="sib_signup_form_<?php echo esc_attr( $frmID ); ?>" method="post" class="sib_signup_form">
573 <div class="sib_loader" style="display:none;"><img
574 src="<?php echo esc_url( includes_url() ); ?>images/spinner.gif" alt="loader"></div>
575 <input type="hidden" name="sib_form_action" value="subscribe_form_submit">
576 <input type="hidden" name="sib_form_id" value="<?php echo esc_attr( $frmID ); ?>">
577 <input type="hidden" name="sib_form_alert_notice" value="<?php echo esc_attr($formData['requiredMsg']); ?>">
578 <input type="hidden" name="sib_security" value="<?php echo esc_attr( wp_create_nonce( 'sib_front_ajax_nonce' ) ); ?>">
579 <div class="sib_signup_box_inside_<?php echo esc_attr( $frmID ); ?>">
580 <div style="/*display:none*/" class="sib_msg_disp">
581 </div>
582 <?php
583 // phpcs:ignore
584 echo stripcslashes($formData['html']);
585 ?>
586 </div>
587 </form>
588 <style>
589 <?php
590
591 if ( ! $formData['dependTheme'] ) {
592 // Custom css.
593 $formData['css'] = str_replace( '[form]', 'form#sib_signup_form_' . $frmID, $formData['css'] );
594 echo $formData['css'];
595 }
596 $msgCss = str_replace( '[form]', 'form#sib_signup_form_' . $frmID, SIB_Forms::getDefaultMessageCss() );
597 echo $msgCss;
598 ?>
599 </style>
600 <?php
601 }
602
603 /**
604 * Shortcode for sign up form
605 *
606 * @param array $atts - shortcode parameter.
607 * @return string
608 */
609 function sibwp_form_shortcode( $atts ) {
610 $pull_atts = shortcode_atts(
611 array(
612 'id' => 'oldForm', // We will return 'oldForm' for shortcode of old form.
613 ), $atts
614 );
615 $frmID = $pull_atts['id'];
616 $lang = defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : '';
617
618 ob_start();
619 $this->generate_form_box( $frmID, $lang );
620
621 $output_string = ob_get_contents();
622 ob_end_clean();
623 return $output_string;
624 }
625
626 /**
627 * Sign up process
628 */
629 function signup_process() {
630 //Handling of backslash added by WP because magic quotes are enabled by default
631 array_walk_recursive( $_POST, function(&$value) {
632 $value = stripslashes($value);
633 });
634
635 if ( empty( $_POST['sib_security'] ) ) {
636 wp_send_json(
637 array(
638 'status' => 'sib_security',
639 'msg' => 'Token not found.',
640 )
641 );
642 }
643 $formID = isset( $_POST['sib_form_id'] ) ? sanitize_text_field( $_POST['sib_form_id'] ) : 1;
644 if ( 'oldForm' == $formID ) {
645 $formID = get_option( 'sib_old_form_id' );
646 }
647 $formData = SIB_Forms::getForm( $formID );
648
649 if (!SIB_Manager::is_done_validation(false) || 0 == count($formData)) {
650 wp_send_json(
651 array(
652 'status' => 'failure',
653 'msg' => array("errorMsg" => "Something wrong occurred"),
654 )
655 );
656 }
657
658 if ( '0' != $formData['gCaptcha'] ) {
659 if ( ! isset( $_POST['g-recaptcha-response'] ) || empty( $_POST['g-recaptcha-response'] ) ) {
660 wp_send_json(
661 array(
662 'status' => 'gcaptchaEmpty',
663 'msg' => 'Please click on the reCAPTCHA box.',
664 )
665 );
666 }
667 $secret = $formData['gCaptcha_secret'];
668
669 $data = array(
670 'secret' => $secret,
671 'response' => sanitize_text_field( $_POST['g-recaptcha-response'] ),
672 );
673
674 $args = [
675 'method' => 'POST',
676 ];
677
678 try {
679 $data = wp_remote_retrieve_body(wp_remote_request(sprintf(self::RECAPTCHA_API_TEMPLATE, http_build_query($data)), $args));
680 $responseData = json_decode($data);
681 if ( ! $responseData->success ) {
682 wp_send_json(
683 array(
684 'status' => 'gcaptchaFail',
685 'msg' => 'Robot verification failed, please try again.',
686 )
687 );
688 }
689 } catch (Exception $exception) {
690 wp_send_json(
691 array(
692 'status' => 'gcaptchaFail',
693 'msg' => $exception->getMessage(),
694 )
695 );
696 }
697 }
698
699 $listID = $formData['listID'];
700 if (empty($listID)) {
701 $listID = array();
702 }
703 $interestingLists = isset( $_POST['interestingLists']) ? array_map( 'sanitize_text_field', $_POST['interestingLists'] ) : array();
704 $expectedLists = isset( $_POST['listIDs'] ) ? array_map( 'sanitize_text_field', $_POST['listIDs'] ) : array();
705 if ( empty($interestingLists) )
706 {
707 $unlinkedLists = [];
708 }
709 else{
710 $unwantedLists = array_diff( $interestingLists, $expectedLists );
711 $unlinkedLists = array_diff( $unwantedLists, $listID);
712 $listID = array_unique(array_merge( $listID, $expectedLists ));
713 }
714
715 $email = isset( $_POST['email'] ) ? sanitize_email( $_POST['email'] ) : '';
716 if ( ! is_email( $email ) ) {
717 return;
718 }
719
720 $isDoubleOptin = $formData['isDopt'];
721 $isOptin = $formData['isOpt'];
722 $redirectUrlInEmail = $formData['redirectInEmail'];
723 $redirectUrlInForm = $formData['redirectInForm'];
724
725 $info = array();
726 $attributes = explode( ',', $formData['attributes'] ); // String to array.
727 if ( isset( $attributes ) && is_array( $attributes ) ) {
728 foreach ( $_POST as $postAttribute => $postAttributeValue ) {
729 $correspondingSibAttribute = $this->getCorrespondingSibAttribute($postAttribute, $attributes);
730 if (!empty($correspondingSibAttribute)) {
731 $info[ $correspondingSibAttribute ] = sanitize_text_field( $postAttributeValue );
732 }
733 }
734 }
735 $templateID = $formData['templateID'];
736
737 if ( $isDoubleOptin ) {
738 /*
739 * Double optin process
740 * 1. add record to db
741 * 2. send confirmation email with activate code
742 */
743 $result = "success";
744 // Send a double optin confirm email.
745 if ( 'success' == $result ) {
746 // Add a recode with activate code in db.
747 $activateCode = $this->create_activate_code( $email, $info, $formID, $listID, $redirectUrlInEmail, $unlinkedLists );
748 SIB_API_Manager::send_comfirm_email( $email, 'double-optin', $templateID, $info, $activateCode );
749 }
750 } elseif ( $isOptin ) {
751 $result = SIB_API_Manager::create_subscriber( $email, $listID, $info, 'confirm', $unlinkedLists );
752 if ( 'success' == $result ) {
753 // Send a confirm email.
754 SIB_API_Manager::send_comfirm_email( $email, 'confirm', $templateID, $info );
755 }
756 } else {
757 $result = SIB_API_Manager::create_subscriber( $email, $listID, $info, 'simple', $unlinkedLists );
758 }
759 $msg = array(
760 'successMsg' => $formData['successMsg'],
761 'errorMsg' => $formData['errorMsg'],
762 'existMsg' => $formData['existMsg'],
763 'invalidMsg' => $formData['invalidMsg'],
764 );
765
766 wp_send_json(
767 array(
768 'status' => $result,
769 'msg' => $msg,
770 'redirect' => $redirectUrlInForm,
771 )
772 );
773 }
774
775 /**
776 * Create activate code for Double optin
777 *
778 * @param string $email - user email.
779 * @param array $info - info.
780 * @param string $formID - form ID.
781 * @param array $listIDs - lists.
782 * @param string $redirectUrl - redirect url.
783 * @return string - activate code.
784 */
785 function create_activate_code( $email, $info, $formID, $listIDs, $redirectUrl, $unlinkedLists = null ) {
786 $data = SIB_Model_Users::get_data_by_email( $email, $formID );
787 $date = gmdate( 'Y-m-d H:i:s' );
788 if ( $unlinkedLists != null )
789 {
790 $info['unlinkedLists'] = $unlinkedLists;
791 }
792 if ( false == $data ) {
793 $uniqid = uniqid();
794 $data = array(
795 'email' => $email,
796 'code' => $uniqid,
797 'info' => maybe_serialize( $info ),
798 'frmid' => $formID,
799 'listIDs' => maybe_serialize( $listIDs ),
800 'redirectUrl' => $redirectUrl,
801 'user_added_date' => $date,
802 );
803 SIB_Model_Users::add_record( $data );
804 } else {
805 $update_data = array(
806 'id' => $data['id'],
807 'email' => $email,
808 'info' => maybe_serialize( $info ),
809 );
810 SIB_Model_Users::update_element( $update_data );
811 $uniqid = $data['code'];
812 }
813 return $uniqid;
814 }
815
816 /**
817 * Use Sendinblue SMTP to send all emails
818 *
819 * @param string $to - reception email.
820 * @param string $subject - subject of email.
821 * @param string $message - message of email.
822 * @param string $headers - header of email.
823 * @param array $attachments - attachments.
824 */
825 static function wp_mail_native( $to, $subject, $message, $headers = '', $attachments = array() ) {
826 $result = require self::$plugin_dir . '/inc/function.wp_mail.php';
827 return $result;
828 }
829
830 /**
831 * To send the transactional email via Sendinblue
832 * hook wp_mail
833 *
834 * @param string $to - reception email.
835 * @param string $subject - subject of email.
836 * @param string $message - message of email.
837 * @param string $headers - header of email.
838 * @param array $attachments - attachments
839 * @param array $tags - tag.
840 * @param string $from_name - sender name.
841 * @param string $from_email - sender email.
842 * @return mixed|WP_Error
843 */
844 static function sib_email( $to, $subject, $message, $headers = '', $attachments = array(), $tags = array(), $from_name = '', $from_email = '' ) {
845 $data = [];
846 // Compact the input, apply the filters, and extract them back out.
847 extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );
848
849 if ( !empty( $attachments ) && ! is_array( $attachments ) ) {
850 $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
851 }
852
853 // From email and name.
854 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
855 if ( isset( $home_settings['sender'] ) ) {
856 $from_name = $home_settings['from_name'];
857 $from_email = $home_settings['from_email'];
858 } else {
859 $from_email = trim( get_bloginfo( 'admin_email' ) );
860 $from_name = trim( get_bloginfo( 'name' ) );
861 }
862 $from_email = apply_filters( 'wp_mail_from', $from_email );
863 $from_name = apply_filters( 'wp_mail_from_name', $from_name );
864
865 if ( !empty( $headers ) ) {
866 if( is_array( $headers ) ){
867 foreach ($headers as $key => $val) {
868 if( stripos($val, "Content-Type: text/html") !== false ) {
869 unset( $headers[$key] );
870 }
871 }
872 $headers = array_values( $headers );
873 if( count( $headers ) == 1 && $headers[0] == '' ) {
874 unset( $headers[0] );
875 }
876 }
877 if( is_string( $headers ) ){
878 $headers = str_replace("Content-Type: text/html", "", $headers);
879 }
880 if( !empty( $headers ) ){
881 $data['headers'] = $headers;
882 }
883 if ( ! is_array( $headers ) ) {
884 // Explode the headers out, so this function can take both.
885 // string headers and an array of headers.
886 $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
887 } else {
888 $tempheaders = $headers;
889 }
890 $headers = array();
891 $bcc = array();
892 // If it's actually got contents.
893 if ( ! empty( $tempheaders ) ) {
894 // Iterate through the raw headers.
895 foreach ( (array) $tempheaders as $header ) {
896 if ( strpos( $header, ':' ) === false ) {
897 if ( false !== stripos( $header, 'boundary=' ) ) {
898 $parts = preg_split( '/boundary=/i', trim( $header ) );
899 $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
900 }
901 continue;
902 }
903 // Explode them out.
904 list($name, $content) = explode( ':', trim( $header ), 2 );
905
906 // Cleanup crew.
907 $name = trim( $name );
908 $content = trim( $content );
909
910 switch ( strtolower( $name ) ) {
911 case 'content-type':
912 $headers[ trim( $name ) ] = trim( $content );
913 break;
914 case 'x-mailin-tag':
915 $headers[ trim( $name ) ] = trim( $content );
916 break;
917 case 'from':
918 if ( strpos( $content, '<' ) !== false ) {
919 // So... making my life hard again?
920 $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
921 $from_name = str_replace( '"', '', $from_name );
922 $from_name = trim( $from_name );
923
924 $from_email = substr( $content, strpos( $content, '<' ) + 1 );
925 $from_email = str_replace( '>', '', $from_email );
926 $from_email = trim( $from_email );
927 } else {
928 $from_name = '';
929 $from_email = trim( $content );
930 }
931 break;
932
933 case 'bcc':
934 if ( strpos( $content, '<') !== false )
935 {
936 $content = str_replace('<', '', $content);
937 $content = str_replace('>', '', $content);
938 }
939 $data['bcc'] = array();
940 $bcc_content = explode(',', $content);
941 foreach ($bcc_content as $key => $value) {
942 if ( ! empty( $value )) {
943 $data['bcc'][] = array('email' => $value);
944 }
945 }
946 break;
947 case 'cc':
948 if ( strpos( $content, '<') !== false )
949 {
950 $content = str_replace('<', '', $content);
951 $content = str_replace('>', '', $content);
952 }
953 $data['cc'] = array();
954 $cc_content = explode(',', $content);
955 foreach ($cc_content as $key => $value) {
956 if ( ! empty( $value )) {
957 $data['cc'][] = array('email' => $value);
958 }
959 }
960 break;
961 case 'reply-to':
962 if ( strpos( $content, '<') !== false )
963 {
964 $reply_content = substr( $content, strpos( $content, '<' ) + 1 );
965 $reply_content = str_replace( '>', '', $reply_content );
966 $reply = trim( $reply_content );
967 } else {
968 $reply = trim( $content );
969 }
970
971 if (!empty($reply)) {
972 $data['replyTo'] = ['email' => trim( $reply )];
973 }
974 break;
975 default:
976 break;
977 }
978 }
979 }
980 }
981
982 // Set destination addresses.
983 if ( ! is_array( $to ) ) {
984 $to = explode( ',', preg_replace( '/\s+/', '', $to ) ); // strip all whitespace.
985 }
986
987 $processed_to = array();
988 foreach ( $to as $email ) {
989 if ( is_array( $email ) ) {
990 $processed_to[] = $email;
991 } else {
992 $processed_to[] = ['email' => $email];
993 }
994 }
995 $data['to'] = $processed_to;
996
997
998 // Attachments.
999 $attachment_content = array();
1000 if ( ! empty( $attachments ) ) {
1001 foreach ( $attachments as $attachment ) {
1002 if ( !empty( $attachment ) ) {
1003 $content = self::getAttachmentStruct( $attachment );
1004 if ( ! is_wp_error( $content ) ) {
1005 $attachment_content = array_merge( $attachment_content, $content );
1006 }
1007 }
1008 }
1009 if ( !empty( $attachment_content ) ) {
1010 $data["attachment"] = array($attachment_content);
1011 }
1012 }
1013
1014 // Common transformations for the HTML part.
1015 // If it is text/plain, New line break found.
1016 if ( strpos( $message, '</table>' ) === false && strpos( $message, '</div>' ) === false ) {
1017 if ( strpos( $message, "\n" ) !== false ) {
1018 if ( is_array( $message ) ) {
1019 foreach ( $message as &$value ) {
1020 $value['content'] = preg_replace( '#<(https?://[^*]+)>#', '$1', $value['content'] );
1021 $value['content'] = nl2br( $value['content'] );
1022 }
1023 } else {
1024 $message = preg_replace( '#<(https?://[^*]+)>#', '$1', $message );
1025 $message = nl2br( $message );
1026 }
1027 }
1028 }
1029 // Sending...
1030 $data['sender'] = ['email' => $from_email, 'name' => $from_name ];
1031 $data['subject'] = $subject;
1032 $data['htmlContent'] = $message;
1033
1034 try {
1035 $sent = SIB_API_Manager::send_email( $data );
1036 return $sent;
1037 } catch ( Exception $e ) {
1038 return new WP_Error( $e->getMessage() );
1039 }
1040 }
1041
1042 /**
1043 * @param string $path - attachment file path
1044 * @return array|WP_Error
1045 */
1046 static function getAttachmentStruct( $path ) {
1047
1048 $struct = array();
1049
1050 try {
1051
1052 if ( ! @is_file( $path ) ) {
1053 throw new Exception( $path . ' is not a valid file.' );
1054 }
1055
1056 $filename = basename( $path );
1057
1058 if ( ! function_exists( 'get_magic_quotes' ) ) {
1059 /**
1060 * @return bool
1061 */
1062 function get_magic_quotes() {
1063 return false;
1064 }
1065 }
1066 if ( ! function_exists( 'set_magic_quotes' ) ) {
1067 /**
1068 * @param $value
1069 * @return bool
1070 */
1071 function set_magic_quotes( $value ) {
1072 return true;
1073 }
1074 }
1075
1076 $isMagicQuotesSupported = version_compare( PHP_VERSION, '5.3.0', '<' )
1077 && function_exists( 'get_magic_quotes_runtime' )
1078 && function_exists( 'set_magic_quotes_runtime' );
1079
1080 if ( $isMagicQuotesSupported ) {
1081 // Escape linters check.
1082 $getMagicQuotesRuntimeFunc = 'get_magic_quotes_runtime';
1083 $setMagicQuotesRuntimeFunc = 'set_magic_quotes_runtime';
1084
1085 // Save magic quotes value.
1086 $magicQuotes = $getMagicQuotesRuntimeFunc();
1087 $setMagicQuotesRuntimeFunc (0);
1088 }
1089
1090 $file_buffer = file_get_contents( $path );
1091 $file_buffer = chunk_split( base64_encode( $file_buffer ), 76, "\n" );
1092
1093 if ( $isMagicQuotesSupported ) {
1094 // Restore magic quotes value.
1095 $setMagicQuotesRuntimeFunc($magicQuotes);
1096 }
1097
1098 $struct["name"] = $filename;
1099 $struct["content"] = $file_buffer;
1100
1101 } catch ( Exception $e ) {
1102 return new WP_Error( 'Error creating the attachment structure: ' . $e->getMessage() );
1103 }
1104
1105 return $struct;
1106 }
1107
1108 /**
1109 * Create custom page for form preview
1110 *
1111 * @param array $query_vars - query.
1112 * @return array
1113 */
1114 function sib_query_vars( $query_vars ) {
1115 $query_vars[] = 'sib_form';
1116 return $query_vars;
1117 }
1118
1119 /**
1120 * Parse request
1121 *
1122 * @param mixed $wp - object.
1123 */
1124 function sib_parse_request( &$wp ) {
1125 if ( array_key_exists( 'sib_form', $wp->query_vars ) ) {
1126 include 'inc/sib-form-preview.php';
1127 exit();
1128 }
1129 }
1130
1131 /**
1132 * Load Text domain.
1133 */
1134 static function LoadTextDomain() {
1135 // Load lang file.
1136 $i18n_file_name = 'mailin';
1137 $locale = apply_filters( 'plugin_locale', get_locale(), $i18n_file_name );
1138 // $locale = 'fr_FR';
1139 $filename = plugin_dir_path( __FILE__ ) . '/lang/' . $i18n_file_name . '-' . $locale . '.mo';
1140 load_textdomain( 'mailin', $filename );
1141 }
1142
1143 /**
1144 * Notice the language is difference than site's language
1145 */
1146 static function language_admin_notice() {
1147 if ( ! get_option( SIB_Manager::LANGUAGE_OPTION_NAME ) ) {
1148 $lang_prefix = substr( get_bloginfo( 'language' ), 0, 2 );
1149 $lang = self::getLanguageName( $lang_prefix );
1150 $class = 'error';
1151 $message = sprintf( 'Please note that your Sendinblue account is in %s, but Sendinblue WordPress plugin is only available in English / French for now. Sorry for inconvenience.', $lang );
1152 if ( 'en' !== $lang_prefix && 'fr' !== $lang_prefix ) {
1153 // phpcs:ignore
1154 echo ( "<div class=\"$class\" style='margin-left: 2px;margin-bottom: 4px;'> <p>$message<a class='' href='?dismiss_admin_lang_notice=1'> No problem...</a></p></div>" );
1155 }
1156 }
1157 }
1158
1159 /**
1160 * Notice wp_mail is not possible
1161 */
1162 static function wpMailNotices() {
1163 if ( self::$wp_mail_conflict ) {
1164 echo ( '<div class="error"><p>' . __( 'You cannot use Sendinblue SMTP now because wp_mail has been declared by another process or plugin. ', 'mailin' ) . '</p></div>' );
1165 }
1166 }
1167
1168 /**
1169 * Names of languages.
1170 *
1171 * @param string $prefix - language.
1172 * @return mixed
1173 */
1174 public static function getLanguageName( $prefix = 'en' ) {
1175 $lang = array();
1176 $lang['de'] = 'Deutsch';
1177 $lang['en'] = 'English';
1178 $lang['zh'] = '中文';
1179 $lang['ru'] = 'Русский';
1180 $lang['fi'] = 'suomi';
1181 $lang['fr'] = 'Français';
1182 $lang['nl'] = 'Nederlands';
1183 $lang['sv'] = 'Svenska';
1184 $lang['it'] = 'Italiano';
1185 $lang['ro'] = 'Română';
1186 $lang['hu'] = 'Magyar';
1187 $lang['ja'] = '日本語';
1188 $lang['es'] = 'Español';
1189 $lang['vi'] = 'Tiếng Việt';
1190 $lang['ar'] = 'العربية';
1191 $lang['pt'] = 'Português';
1192 $lang['pb'] = 'Português do Brasil';
1193 $lang['pl'] = 'Polski';
1194 $lang['gl'] = 'galego';
1195 $lang['tr'] = 'Turkish';
1196 $lang['et'] = 'Eesti';
1197 $lang['hr'] = 'Hrvatski';
1198 $lang['eu'] = 'Euskera';
1199 $lang['el'] = 'Ελληνικά';
1200 $lang['ua'] = 'Українська';
1201 $lang['ko'] = '한국어';
1202
1203 return $lang[ $prefix ];
1204 }
1205
1206 /**
1207 * Create language sidebar for wpml plugin.
1208 */
1209 public function sib_create_language_sidebar() {
1210 $languages = apply_filters( 'wpml_active_languages', array() );
1211 $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
1212 $action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : '';
1213 $frmID = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : '';
1214 $pID = isset( $_GET['pid'] ) ? sanitize_text_field( $_GET['pid'] ) : '';
1215 $parent = true;
1216 if ( '' !== $frmID && '' !== $pID ) {
1217 $lang = SIB_Forms_Lang::get_lang( $frmID, $pID );
1218 $parent = false;
1219 } else {
1220 $lang = ICL_LANGUAGE_CODE;
1221 if ( '' !== $frmID && '' === $pID ) {
1222 $pID = $frmID;
1223
1224 }
1225 }
1226
1227 if ( 'sib_page_form' === $page && 'edit' === $action ) {
1228 ?>
1229 <div class="panel panel-default text-left box-border-box sib-small-content">
1230 <div class="panel-heading"><strong><?php esc_attr_e( 'About Sendinblue', 'mailin' ); ?></strong></div>
1231 <div class="panel-body">
1232 <p>
1233 <label for='sib_form_language'><?php esc_attr_e( 'Language of this form:', 'mailin' ); ?> </label>
1234 <select id="sib_form_lang" name="sib_form_lang" data-selected="">
1235 <?php
1236 foreach ( $languages as $language ) {
1237 $selected = ($language['code'] == $lang) ? 'selected' : '';
1238 if ( $language['code'] == $lang && true === $parent ) {
1239 $option_text = '<option value="" ' . $selected . '>' . $language['native_name'] . '</option>';
1240 } else {
1241 $exist = SIB_Forms_Lang::get_form_ID( $pID, $language['language_code'] );
1242
1243 if ( null === $exist ) {
1244 continue;
1245 } else {
1246 $option_text = ( 'selected' === $selected ) ? sprintf( '<option value="" selected>%s</option>', $language['native_name'] ) : sprintf( '<option value="?page=%s&action=%s&pid=%s&lang=%s" %s >%s</option>', sanitize_text_field( $_REQUEST['page'] ), 'edit', absint( $pID ), $language['language_code'], $selected, $language['native_name'] );
1247 }
1248 }
1249 echo $option_text ;
1250 }
1251 ?>
1252 </select>
1253 </p>
1254 <div class="sib_form_translate">
1255 <p>
1256 <label><?php esc_attr_e( 'Translate this form', 'mailin' ); ?></label>
1257 </p>
1258 <table width="100%" class="sib_form_trans_table" style="border: 1px solid #8cceea;">
1259 <tr>
1260 <?php
1261 foreach ( $languages as $language ) {
1262 if ( $language['code'] == $lang ) {
1263 continue;
1264 }
1265 ?>
1266 <th style="text-align: center;"><img
1267 src="<?php echo esc_url( $language['country_flag_url'] ); ?>"></th>
1268 <?php
1269 }
1270 ?>
1271 </tr>
1272 <tr style="background-color: #EFF8FC;">
1273 <?php
1274 foreach ( $languages as $language ) {
1275 if ( $language['code'] == $lang ) {
1276 continue;
1277 }
1278 if ( '' === $pID ) {
1279 $img_src = plugins_url( 'img/add_translation_disabled.png', __FILE__ );
1280 $td = '<img src="' . $img_src . '" style="margin:2px;">';
1281 } else {
1282 $exist = SIB_Forms_Lang::get_form_ID( $pID, $language['language_code'] );
1283
1284 if ( null === $exist ) {
1285 $img_src = plugins_url( 'img/add_translation.png', __FILE__ );
1286
1287 $href = sprintf( '<a class="sib-form-redirect" href="?page=%s&action=%s&pid=%s&lang=%s" style="width: 20px; text-align: center;padding: 2px 1px;">', esc_attr( $_REQUEST['page'] ), 'edit', absint( $pID ), $language['language_code'] );
1288 $td = $href . '<img src="' . $img_src . '" style="margin:2px;"></a>';
1289 } else {
1290 $img_src = plugins_url( 'img/edit_translation.png', __FILE__ );
1291 $href = sprintf( '<a class="sib-form-redirect" href="?page=%s&action=%s&id=%s&pid=%s&lang=%s" style="width: 20px; text-align: center;padding: 2px 1px;">', sanitize_text_field( $_REQUEST['page'] ), 'edit', absint( $exist ), absint( $pID ), $language['language_code'] );
1292 $td = $href . '<img src="' . $img_src . '" style="margin:2px;"></a>';
1293 }
1294 }
1295 ?>
1296 <td style="text-align: center;"><?php echo $td; ?></td>
1297 <?php
1298 }
1299 ?>
1300 </tr>
1301 </table>
1302 </div>
1303 <?php if ( isset( $_GET['pid'] ) ) { ?>
1304 <div class="sib-form-duplicate">
1305 <button class="btn btn-default sib-duplicate-btn"><?php esc_attr_e( 'Copy content from origin form', 'mailin' ); ?></button>
1306 <span class="sib-spin"><i
1307 class="fa fa-circle-o-notch fa-spin fa-lg"></i>&nbsp;&nbsp;</span>
1308 <i title="<?php echo esc_attr_e( 'Copy content from origin form', 'mailin' ); ?>"
1309 data-container="body" data-toggle="popover" data-placement="left"
1310 data-content="<?php echo esc_attr_e( 'You can copy contents from origin form. You need to translate the contents by this language.', 'mailin' ); ?>"
1311 data-html="true" class="fa fa-question-circle popover-help-form"></i>
1312 </div>
1313 <?php } ?>
1314 </div>
1315 </div>
1316 <?php
1317 }
1318 }
1319
1320 public function ajax_get_country_prefix() {
1321 check_ajax_referer( 'sib_front_ajax_nonce', 'security' );
1322 $sms_manager = new SIB_SMS_Code();
1323 $country_list = $sms_manager->get_sms_code_list();
1324 $country_list_html = '';
1325 foreach ( $country_list as $item => $value ) {
1326 $flg_url = plugins_url( 'img/flags/', __FILE__ ).strtolower($item).'.png';
1327 $item_html = '<li class="sib-country-prefix" data-country-code="'.$item.'" data-dial-code="'.$value["code"].'"><div class="sib-flag-box"><div class="sib-flag '.$item.'" style="background-image: url('.$flg_url.')"></div><span>'.$value['name'].'</span><span class="sib-dial-code">+'.$value['code'].'</span></div></li>';
1328 $country_list_html .= $item_html;
1329 }
1330 wp_send_json($country_list_html);
1331 }
1332
1333 /**
1334 * @param string $postAttribute
1335 * @param array $sibAttributes
1336 * @return null|string the corresponding sib attribute or null if not found
1337 */
1338 private function getCorrespondingSibAttribute($postAttribute, $sibAttributes)
1339 {
1340 $normalizedPostAttribute = strtoupper(sanitize_text_field($postAttribute));
1341 foreach ($sibAttributes as $sibAttribute) {
1342 if ($normalizedPostAttribute == strtoupper($sibAttribute)) {
1343 return $sibAttribute;
1344 }
1345 }
1346
1347 return null;
1348 }
1349
1350 public function my_upgrade_function() {
1351 $current_plugin_path_name = plugin_basename( __FILE__ );
1352 activate_plugin( $current_plugin_path_name );
1353 }
1354 }
1355
1356 add_action( 'sendinblue_init', 'sendinblue_init' );
1357 add_filter( 'widget_text', 'do_shortcode' );
1358
1359 /**
1360 * Plugin entry point Process.
1361 */
1362 function sendinblue_init() {
1363 SIB_Manager::LoadTextDomain();
1364 new SIB_Manager();
1365 }
1366
1367 do_action( 'sendinblue_init' );
1368 }
1369