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