PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.1.34
Brevo – Email, SMS, Web Push, Chat, and more. v3.1.34
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 5 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
1466 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.34
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.min.js', array( 'jquery' ), null );
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' ), null );
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(), null, 'all' );
437 wp_register_style( 'sib-fontawesome-css', self::$plugin_url . '/css/fontawesome/css/font-awesome.css', array(), null, '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 = $general_settings['ma_key'];
577 $output = '<script type="text/javascript">
578 (function() {window.sib ={equeue:[],client_key:"'. $ma_key .'"};/* OPTIONAL: email for identify request*/
579 window.sib.email_id = "'. $ma_email .'";
580 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();})();
581 </script>';
582 echo $output;
583 }
584 }
585
586 /**
587 * Register widget
588 */
589 function sib_create_widget() {
590 register_widget( 'SIB_Widget_Subscribe' );
591 }
592
593 /**
594 * Display form on front page
595 *
596 * @param string $frmID - form ID.
597 * @param string $lang - form language.
598 */
599 function generate_form_box( $frmID = '-1', $lang = '' ) {
600 if ( 'oldForm' == $frmID ) {
601 $frmID = get_option( 'sib_old_form_id' );
602 } elseif ( '' != $lang ) {
603 $trans_id = SIB_Forms_Lang::get_form_ID( $frmID, $lang );
604 if ( null != $trans_id ) {
605 $frmID = $trans_id;
606 }
607 }
608
609 $formData = SIB_Forms::getForm( $frmID );
610
611 if ( empty( $formData ) ) {
612 return;
613 }
614 // Add Google recaptcha
615 if( '0' != $formData['gCaptcha'] ) {
616 if( '1' == $formData['gCaptcha'] ) { // For old forms.
617 $formData['html'] = preg_replace( '/([\s\S]*?)<div class="g-recaptcha"[\s\S]*?data-size="invisible"><\/div>/', '$1', $formData['html'] );
618 }
619 if ( '3' == $formData['gCaptcha'] ) // The case of using google recaptcha.
620 {
621 ?>
622 <script type="text/javascript" charset="utf-8">
623 var gCaptchaSibWidget;
624 var onloadSibCallback = function() {
625 var recaptchas = document.querySelectorAll('div[id=sib_captcha]');
626 for( i = 0; i < recaptchas.length; i++) {
627 gCaptchaSibWidget = grecaptcha.render(recaptchas[i], {
628 'sitekey' : '<?php echo $formData["gCaptcha_site"] ?>'
629 });
630 }
631 }
632 </script>
633 <?php
634 }
635 else { // The case of using google invisible recaptcha.
636 ?>
637 <script type="text/javascript">
638 var gCaptchaSibWidget;
639 var onloadSibCallback = function() {
640 var element = document.getElementsByClassName('sib-default-btn');
641 gCaptchaSibWidget = grecaptcha.render(element[0],{
642 'sitekey' : '<?php echo $formData["gCaptcha_site"] ?>',
643 'callback' : sibVerifyCallback
644 });
645 };
646 </script>
647 <?php
648 }
649 ?>
650 <script src="https://www.google.com/recaptcha/api.js?onload=onloadSibCallback&render=explicit" async defer></script>
651 <?php
652 }
653
654 ?>
655 <form id="sib_signup_form_<?php echo esc_attr( $frmID ); ?>" method="post" class="sib_signup_form">
656 <div class="sib_loader" style="display:none;"><img
657 src="<?php echo esc_url( includes_url() ); ?>images/spinner.gif" alt="loader"></div>
658 <input type="hidden" name="sib_form_action" value="subscribe_form_submit">
659 <input type="hidden" name="sib_form_id" value="<?php echo esc_attr( $frmID ); ?>">
660 <input type="hidden" name="sib_form_alert_notice" value="<?php echo esc_attr($formData['requiredMsg']); ?>">
661 <input type="hidden" name="sib_security" value="<?php echo esc_attr( wp_create_nonce( 'sib_front_ajax_nonce' ) ); ?>">
662 <div class="sib_signup_box_inside_<?php echo esc_attr( $frmID ); ?>">
663 <div style="/*display:none*/" class="sib_msg_disp">
664 </div>
665 <?php
666 // phpcs:ignore
667 echo stripcslashes($formData['html']);
668 ?>
669 </div>
670 </form>
671 <style>
672 <?php
673
674 if ( ! $formData['dependTheme'] ) {
675 // Custom css.
676 $formData['css'] = str_replace( '[form]', 'form#sib_signup_form_' . $frmID, $formData['css'] );
677 echo $formData['css'];
678 }
679 $msgCss = str_replace( '[form]', 'form#sib_signup_form_' . $frmID, SIB_Forms::getDefaultMessageCss() );
680 echo $msgCss;
681 ?>
682 </style>
683 <?php
684 }
685
686 /**
687 * Shortcode for sign up form
688 *
689 * @param array $atts - shortcode parameter.
690 * @return string
691 */
692 function sibwp_form_shortcode( $atts ) {
693 $pull_atts = shortcode_atts(
694 array(
695 'id' => 'oldForm', // We will return 'oldForm' for shortcode of old form.
696 ), $atts
697 );
698 $frmID = $pull_atts['id'];
699 $lang = defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : '';
700
701 ob_start();
702 $this->generate_form_box( $frmID, $lang );
703
704 $output_string = ob_get_contents();
705 ob_end_clean();
706 return $output_string;
707 }
708
709 /**
710 * Sign up process
711 */
712 function signup_process() {
713 //Handling of backslash added by WP because magic quotes are enabled by default
714 array_walk_recursive( $_POST, function(&$value) {
715 $value = stripslashes($value);
716 });
717
718 if ( empty( $_POST['sib_security'] ) ) {
719 wp_send_json(
720 array(
721 'status' => 'sib_security',
722 'msg' => 'Token not found.',
723 )
724 );
725 }
726 $formID = isset( $_POST['sib_form_id'] ) ? sanitize_text_field( $_POST['sib_form_id'] ) : 1;
727 if ( 'oldForm' == $formID ) {
728 $formID = get_option( 'sib_old_form_id' );
729 }
730 $formData = SIB_Forms::getForm( $formID );
731
732 if (!SIB_Manager::is_done_validation(false) || 0 == count($formData)) {
733 wp_send_json(
734 array(
735 'status' => 'failure',
736 'msg' => array("errorMsg" => "Something wrong occurred"),
737 )
738 );
739 }
740
741 if ( '0' != $formData['gCaptcha'] ) {
742 if ( ! isset( $_POST['g-recaptcha-response'] ) || empty( $_POST['g-recaptcha-response'] ) ) {
743 wp_send_json(
744 array(
745 'status' => 'gcaptchaEmpty',
746 'msg' => 'Please click on the reCAPTCHA box.',
747 )
748 );
749 }
750 $secret = $formData['gCaptcha_secret'];
751
752 $data = array(
753 'secret' => $secret,
754 'response' => sanitize_text_field( $_POST['g-recaptcha-response'] ),
755 );
756
757 $args = [
758 'method' => 'POST',
759 ];
760
761 try {
762 $data = wp_remote_retrieve_body(wp_remote_request(sprintf(self::RECAPTCHA_API_TEMPLATE, http_build_query($data)), $args));
763 $responseData = json_decode($data);
764 if ( ! $responseData->success ) {
765 wp_send_json(
766 array(
767 'status' => 'gcaptchaFail',
768 'msg' => 'Robot verification failed, please try again.',
769 )
770 );
771 }
772 } catch (Exception $exception) {
773 wp_send_json(
774 array(
775 'status' => 'gcaptchaFail',
776 'msg' => $exception->getMessage(),
777 )
778 );
779 }
780 }
781
782 $listID = $formData['listID'];
783 if (empty($listID)) {
784 $listID = array();
785 }
786 $interestingLists = isset( $_POST['interestingLists']) ? array_map( 'sanitize_text_field', $_POST['interestingLists'] ) : array();
787 $expectedLists = isset( $_POST['listIDs'] ) ? array_map( 'sanitize_text_field', $_POST['listIDs'] ) : array();
788 if ( empty($interestingLists) )
789 {
790 $unlinkedLists = [];
791 }
792 else{
793 $unwantedLists = array_diff( $interestingLists, $expectedLists );
794 $unlinkedLists = array_diff( $unwantedLists, $listID);
795 $listID = array_unique(array_merge( $listID, $expectedLists ));
796 }
797
798 $email = isset( $_POST['email'] ) ? sanitize_email( $_POST['email'] ) : '';
799 if ( ! is_email( $email ) ) {
800 return;
801 }
802
803 $isDoubleOptin = $formData['isDopt'];
804 $isOptin = $formData['isOpt'];
805 $redirectUrlInEmail = $formData['redirectInEmail'];
806 $redirectUrlInForm = $formData['redirectInForm'];
807
808 $info = array();
809 $attributes = explode( ',', $formData['attributes'] ); // String to array.
810 if ( isset( $attributes ) && is_array( $attributes ) ) {
811 foreach ( $_POST as $postAttribute => $postAttributeValue ) {
812 $correspondingSibAttribute = $this->getCorrespondingSibAttribute($postAttribute, $attributes);
813 if (!empty($correspondingSibAttribute)) {
814 $info[ $correspondingSibAttribute ] = sanitize_text_field( $postAttributeValue );
815 }
816 }
817 }
818 $templateID = $formData['templateID'];
819
820 if ( $isDoubleOptin ) {
821 /*
822 * Double optin process
823 * 1. add record to db
824 * 2. send confirmation email with activate code
825 */
826 $result = "success";
827 // Send a double optin confirm email.
828 if ( 'success' == $result ) {
829 // Add a recode with activate code in db.
830 $activateCode = $this->create_activate_code( $email, $info, $formID, $listID, $redirectUrlInEmail, $unlinkedLists );
831 SIB_API_Manager::send_comfirm_email( $email, 'double-optin', $templateID, $info, $activateCode );
832 }
833 } elseif ( $isOptin ) {
834 $result = SIB_API_Manager::create_subscriber( $email, $listID, $info, 'confirm', $unlinkedLists );
835 if ( 'success' == $result ) {
836 // Send a confirm email.
837 SIB_API_Manager::send_comfirm_email( $email, 'confirm', $templateID, $info );
838 }
839 } else {
840 $result = SIB_API_Manager::create_subscriber( $email, $listID, $info, 'simple', $unlinkedLists );
841 }
842 $msg = array(
843 'successMsg' => $formData['successMsg'],
844 'errorMsg' => $formData['errorMsg'],
845 'existMsg' => $formData['existMsg'],
846 'invalidMsg' => $formData['invalidMsg'],
847 );
848
849 wp_send_json(
850 array(
851 'status' => $result,
852 'msg' => $msg,
853 'redirect' => $redirectUrlInForm,
854 )
855 );
856 }
857
858 /**
859 * Create activate code for Double optin
860 *
861 * @param string $email - user email.
862 * @param array $info - info.
863 * @param string $formID - form ID.
864 * @param array $listIDs - lists.
865 * @param string $redirectUrl - redirect url.
866 * @return string - activate code.
867 */
868 function create_activate_code( $email, $info, $formID, $listIDs, $redirectUrl, $unlinkedLists = null ) {
869 $data = SIB_Model_Users::get_data_by_email( $email, $formID );
870 $date = gmdate( 'Y-m-d H:i:s' );
871 if ( $unlinkedLists != null )
872 {
873 $info['unlinkedLists'] = $unlinkedLists;
874 }
875 if ( false == $data ) {
876 $uniqid = uniqid();
877 $data = array(
878 'email' => $email,
879 'code' => $uniqid,
880 'info' => maybe_serialize( $info ),
881 'frmid' => $formID,
882 'listIDs' => maybe_serialize( $listIDs ),
883 'redirectUrl' => $redirectUrl,
884 'user_added_date' => $date,
885 );
886 SIB_Model_Users::add_record( $data );
887 } else {
888 $update_data = array(
889 'id' => $data['id'],
890 'email' => $email,
891 'info' => maybe_serialize( $info ),
892 );
893 SIB_Model_Users::update_element( $update_data );
894 $uniqid = $data['code'];
895 }
896 return $uniqid;
897 }
898
899 /**
900 * Use Sendinblue SMTP to send all emails
901 *
902 * @param string $to - reception email.
903 * @param string $subject - subject of email.
904 * @param string $message - message of email.
905 * @param string $headers - header of email.
906 * @param array $attachments - attachments.
907 */
908 static function wp_mail_native( $to, $subject, $message, $headers = '', $attachments = array() ) {
909 $result = require self::$plugin_dir . '/inc/function.wp_mail.php';
910 return $result;
911 }
912
913 /**
914 * To send the transactional email via Sendinblue
915 * hook wp_mail
916 *
917 * @param string $to - reception email.
918 * @param string $subject - subject of email.
919 * @param string $message - message of email.
920 * @param string $headers - header of email.
921 * @param array $attachments - attachments
922 * @param array $tags - tag.
923 * @param string $from_name - sender name.
924 * @param string $from_email - sender email.
925 * @return mixed|WP_Error
926 */
927 static function sib_email( $to, $subject, $message, $headers = '', $attachments = array(), $tags = array(), $from_name = '', $from_email = '' ) {
928 $data = [];
929 // Compact the input, apply the filters, and extract them back out.
930 extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );
931
932 if ( !empty( $attachments ) && ! is_array( $attachments ) ) {
933 $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
934 }
935
936 // From email and name.
937 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
938 if ( isset( $home_settings['sender'] ) ) {
939 $from_name = $home_settings['from_name'];
940 $from_email = $home_settings['from_email'];
941 } else {
942 $from_email = trim( get_bloginfo( 'admin_email' ) );
943 $from_name = trim( get_bloginfo( 'name' ) );
944 }
945 $from_email = apply_filters( 'wp_mail_from', $from_email );
946 $from_name = apply_filters( 'wp_mail_from_name', $from_name );
947
948 if ( !empty( $headers ) ) {
949 if( is_array( $headers ) ){
950 foreach ($headers as $key => $val) {
951 if( stripos($val, "Content-Type: text/html") !== false ) {
952 unset( $headers[$key] );
953 }
954 }
955 $headers = array_values( $headers );
956 if( count( $headers ) == 1 && $headers[0] == '' ) {
957 unset( $headers[0] );
958 }
959 }
960 if( is_string( $headers ) ){
961 $headers = str_replace("Content-Type: text/html", "", $headers);
962 }
963 if( !empty( $headers ) ){
964 $data['headers'] = $headers;
965 }
966 if ( ! is_array( $headers ) ) {
967 // Explode the headers out, so this function can take both.
968 // string headers and an array of headers.
969 $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
970 } else {
971 $tempheaders = $headers;
972 }
973 $headers = array();
974 $bcc = array();
975 // If it's actually got contents.
976 if ( ! empty( $tempheaders ) ) {
977 // Iterate through the raw headers.
978 foreach ( (array) $tempheaders as $header ) {
979 if ( strpos( $header, ':' ) === false ) {
980 if ( false !== stripos( $header, 'boundary=' ) ) {
981 $parts = preg_split( '/boundary=/i', trim( $header ) );
982 $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
983 }
984 continue;
985 }
986 // Explode them out.
987 list($name, $content) = explode( ':', trim( $header ), 2 );
988
989 // Cleanup crew.
990 $name = trim( $name );
991 $content = trim( $content );
992
993 switch ( strtolower( $name ) ) {
994 case 'content-type':
995 $headers[ trim( $name ) ] = trim( $content );
996 break;
997 case 'x-mailin-tag':
998 $headers[ trim( $name ) ] = trim( $content );
999 break;
1000 case 'from':
1001 if ( strpos( $content, '<' ) !== false ) {
1002 // So... making my life hard again?
1003 $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
1004 $from_name = str_replace( '"', '', $from_name );
1005 $from_name = trim( $from_name );
1006
1007 $from_email = substr( $content, strpos( $content, '<' ) + 1 );
1008 $from_email = str_replace( '>', '', $from_email );
1009 $from_email = trim( $from_email );
1010 } else {
1011 $from_name = '';
1012 $from_email = trim( $content );
1013 }
1014 break;
1015
1016 case 'bcc':
1017 if ( strpos( $content, '<') !== false )
1018 {
1019 $content = str_replace('<', '', $content);
1020 $content = str_replace('>', '', $content);
1021 }
1022 $data['bcc'] = array();
1023 $bcc_content = explode(',', $content);
1024 foreach ($bcc_content as $key => $value) {
1025 if ( ! empty( $value )) {
1026 $data['bcc'][] = array('email' => $value);
1027 }
1028 }
1029 break;
1030 case 'cc':
1031 if ( strpos( $content, '<') !== false )
1032 {
1033 $content = str_replace('<', '', $content);
1034 $content = str_replace('>', '', $content);
1035 }
1036 $data['cc'] = array();
1037 $cc_content = explode(',', $content);
1038 foreach ($cc_content as $key => $value) {
1039 if ( ! empty( $value )) {
1040 $data['cc'][] = array('email' => $value);
1041 }
1042 }
1043 break;
1044 case 'reply-to':
1045 if ( strpos( $content, '<') !== false )
1046 {
1047 $reply_content = substr( $content, strpos( $content, '<' ) + 1 );
1048 $reply_content = str_replace( '>', '', $reply_content );
1049 $reply = trim( $reply_content );
1050 } else {
1051 $reply = trim( $content );
1052 }
1053
1054 if (!empty($reply)) {
1055 $data['replyTo'] = ['email' => trim( $reply )];
1056 }
1057 break;
1058 default:
1059 break;
1060 }
1061 }
1062 }
1063 }
1064
1065 // Set destination addresses.
1066 if ( ! is_array( $to ) ) {
1067 $to = explode( ',', preg_replace( '/\s+/', '', $to ) ); // strip all whitespace.
1068 }
1069
1070 $processed_to = array();
1071 foreach ( $to as $email ) {
1072 if ( is_array( $email ) ) {
1073 $processed_to[] = $email;
1074 } else {
1075 $processed_to[] = ['email' => $email];
1076 }
1077 }
1078 $data['to'] = $processed_to;
1079
1080
1081 // Attachments.
1082 $attachment_content = array();
1083 if ( ! empty( $attachments ) ) {
1084 foreach ( $attachments as $attachment ) {
1085 if ( !empty( $attachment ) ) {
1086 $content = self::getAttachmentStruct( $attachment );
1087 if ( ! is_wp_error( $content ) ) {
1088 $attachment_content = array_merge( $attachment_content, $content );
1089 }
1090 }
1091 }
1092 if ( !empty( $attachment_content ) ) {
1093 $data["attachment"] = array($attachment_content);
1094 }
1095 }
1096
1097 // Common transformations for the HTML part.
1098 // If it is text/plain, New line break found.
1099 if ( strpos( $message, '</table>' ) === false && strpos( $message, '</div>' ) === false ) {
1100 if ( strpos( $message, "\n" ) !== false ) {
1101 if ( is_array( $message ) ) {
1102 foreach ( $message as &$value ) {
1103 $value['content'] = preg_replace( '#<(https?://[^*]+)>#', '$1', $value['content'] );
1104 $value['content'] = nl2br( $value['content'] );
1105 }
1106 } else {
1107 $message = preg_replace( '#<(https?://[^*]+)>#', '$1', $message );
1108 $message = nl2br( $message );
1109 }
1110 }
1111 }
1112 // Sending...
1113 $data['sender'] = ['email' => $from_email, 'name' => $from_name ];
1114 $data['subject'] = $subject;
1115 $data['htmlContent'] = $message;
1116
1117 try {
1118 $sent = SIB_API_Manager::send_email( $data );
1119 return $sent;
1120 } catch ( Exception $e ) {
1121 return new WP_Error( $e->getMessage() );
1122 }
1123 }
1124
1125 /**
1126 * @param string $path - attachment file path
1127 * @return array|WP_Error
1128 */
1129 static function getAttachmentStruct( $path ) {
1130
1131 $struct = array();
1132
1133 try {
1134
1135 if ( ! @is_file( $path ) ) {
1136 throw new Exception( $path . ' is not a valid file.' );
1137 }
1138
1139 $filename = basename( $path );
1140
1141 if ( ! function_exists( 'get_magic_quotes' ) ) {
1142 /**
1143 * @return bool
1144 */
1145 function get_magic_quotes() {
1146 return false;
1147 }
1148 }
1149 if ( ! function_exists( 'set_magic_quotes' ) ) {
1150 /**
1151 * @param $value
1152 * @return bool
1153 */
1154 function set_magic_quotes( $value ) {
1155 return true;
1156 }
1157 }
1158
1159 $isMagicQuotesSupported = version_compare( PHP_VERSION, '5.3.0', '<' )
1160 && function_exists( 'get_magic_quotes_runtime' )
1161 && function_exists( 'set_magic_quotes_runtime' );
1162
1163 if ( $isMagicQuotesSupported ) {
1164 // Escape linters check.
1165 $getMagicQuotesRuntimeFunc = 'get_magic_quotes_runtime';
1166 $setMagicQuotesRuntimeFunc = 'set_magic_quotes_runtime';
1167
1168 // Save magic quotes value.
1169 $magicQuotes = $getMagicQuotesRuntimeFunc();
1170 $setMagicQuotesRuntimeFunc (0);
1171 }
1172
1173 $file_buffer = file_get_contents( $path );
1174 $file_buffer = chunk_split( base64_encode( $file_buffer ), 76, "\n" );
1175
1176 if ( $isMagicQuotesSupported ) {
1177 // Restore magic quotes value.
1178 $setMagicQuotesRuntimeFunc($magicQuotes);
1179 }
1180
1181 $struct["name"] = $filename;
1182 $struct["content"] = $file_buffer;
1183
1184 } catch ( Exception $e ) {
1185 return new WP_Error( 'Error creating the attachment structure: ' . $e->getMessage() );
1186 }
1187
1188 return $struct;
1189 }
1190
1191 /**
1192 * Create custom page for form preview
1193 *
1194 * @param array $query_vars - query.
1195 * @return array
1196 */
1197 function sib_query_vars( $query_vars ) {
1198 $query_vars[] = 'sib_form';
1199 return $query_vars;
1200 }
1201
1202 /**
1203 * Parse request
1204 *
1205 * @param mixed $wp - object.
1206 */
1207 function sib_parse_request( &$wp ) {
1208 if ( array_key_exists( 'sib_form', $wp->query_vars ) ) {
1209 include 'inc/sib-form-preview.php';
1210 exit();
1211 }
1212 }
1213
1214 /**
1215 * Load Text domain.
1216 */
1217 static function LoadTextDomain() {
1218 // Load lang file.
1219 $i18n_file_name = 'mailin';
1220 $locale = apply_filters( 'plugin_locale', get_locale(), $i18n_file_name );
1221 // $locale = 'fr_FR';
1222 $filename = plugin_dir_path( __FILE__ ) . '/lang/' . $i18n_file_name . '-' . $locale . '.mo';
1223 load_textdomain( 'mailin', $filename );
1224 }
1225
1226 /**
1227 * Notice the language is difference than site's language
1228 */
1229 static function language_admin_notice() {
1230 if ( ! get_option( SIB_Manager::LANGUAGE_OPTION_NAME ) ) {
1231 $lang_prefix = substr( get_bloginfo( 'language' ), 0, 2 );
1232 $lang = self::getLanguageName( $lang_prefix );
1233 $class = 'error';
1234 $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 );
1235 if ( 'en' !== $lang_prefix && 'fr' !== $lang_prefix ) {
1236 // phpcs:ignore
1237 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>" );
1238 }
1239 }
1240 }
1241
1242 /**
1243 * Notice wp_mail is not possible
1244 */
1245 static function wpMailNotices() {
1246 if ( self::$wp_mail_conflict ) {
1247 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>' );
1248 }
1249 }
1250
1251 /**
1252 * Names of languages.
1253 *
1254 * @param string $prefix - language.
1255 * @return mixed
1256 */
1257 public static function getLanguageName( $prefix = 'en' ) {
1258 $lang = array();
1259 $lang['de'] = 'Deutsch';
1260 $lang['en'] = 'English';
1261 $lang['zh'] = '中文';
1262 $lang['ru'] = 'Русский';
1263 $lang['fi'] = 'suomi';
1264 $lang['fr'] = 'Français';
1265 $lang['nl'] = 'Nederlands';
1266 $lang['sv'] = 'Svenska';
1267 $lang['it'] = 'Italiano';
1268 $lang['ro'] = 'Română';
1269 $lang['hu'] = 'Magyar';
1270 $lang['ja'] = '日本語';
1271 $lang['es'] = 'Español';
1272 $lang['vi'] = 'Tiếng Việt';
1273 $lang['ar'] = 'العربية';
1274 $lang['pt'] = 'Português';
1275 $lang['pb'] = 'Português do Brasil';
1276 $lang['pl'] = 'Polski';
1277 $lang['gl'] = 'galego';
1278 $lang['tr'] = 'Turkish';
1279 $lang['et'] = 'Eesti';
1280 $lang['hr'] = 'Hrvatski';
1281 $lang['eu'] = 'Euskera';
1282 $lang['el'] = 'Ελληνικά';
1283 $lang['ua'] = 'Українська';
1284 $lang['ko'] = '한국어';
1285
1286 return $lang[ $prefix ];
1287 }
1288
1289 /**
1290 * Create language sidebar for wpml plugin.
1291 */
1292 public function sib_create_language_sidebar() {
1293 $languages = apply_filters( 'wpml_active_languages', array() );
1294 $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
1295 $action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : '';
1296 $frmID = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : '';
1297 $pID = isset( $_GET['pid'] ) ? sanitize_text_field( $_GET['pid'] ) : '';
1298 $parent = true;
1299 if ( '' !== $frmID && '' !== $pID ) {
1300 $lang = SIB_Forms_Lang::get_lang( $frmID, $pID );
1301 $parent = false;
1302 } else {
1303 $lang = ICL_LANGUAGE_CODE;
1304 if ( '' !== $frmID && '' === $pID ) {
1305 $pID = $frmID;
1306
1307 }
1308 }
1309
1310 if ( 'sib_page_form' === $page && 'edit' === $action ) {
1311 ?>
1312 <div class="panel panel-default text-left box-border-box sib-small-content">
1313 <div class="panel-heading"><strong><?php esc_attr_e( 'About Sendinblue', 'mailin' ); ?></strong></div>
1314 <div class="panel-body">
1315 <p>
1316 <label for='sib_form_language'><?php esc_attr_e( 'Language of this form:', 'mailin' ); ?> </label>
1317 <select id="sib_form_lang" name="sib_form_lang" data-selected="">
1318 <?php
1319 foreach ( $languages as $language ) {
1320 $selected = ($language['code'] == $lang) ? 'selected' : '';
1321 if ( $language['code'] == $lang && true === $parent ) {
1322 $option_text = '<option value="" ' . $selected . '>' . $language['native_name'] . '</option>';
1323 } else {
1324 $exist = SIB_Forms_Lang::get_form_ID( $pID, $language['language_code'] );
1325
1326 if ( null === $exist ) {
1327 continue;
1328 } else {
1329 $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'] );
1330 }
1331 }
1332 echo $option_text ;
1333 }
1334 ?>
1335 </select>
1336 </p>
1337 <div class="sib_form_translate">
1338 <p>
1339 <label><?php esc_attr_e( 'Translate this form', 'mailin' ); ?></label>
1340 </p>
1341 <table width="100%" class="sib_form_trans_table" style="border: 1px solid #8cceea;">
1342 <tr>
1343 <?php
1344 foreach ( $languages as $language ) {
1345 if ( $language['code'] == $lang ) {
1346 continue;
1347 }
1348 ?>
1349 <th style="text-align: center;"><img
1350 src="<?php echo esc_url( $language['country_flag_url'] ); ?>"></th>
1351 <?php
1352 }
1353 ?>
1354 </tr>
1355 <tr style="background-color: #EFF8FC;">
1356 <?php
1357 foreach ( $languages as $language ) {
1358 if ( $language['code'] == $lang ) {
1359 continue;
1360 }
1361 if ( '' === $pID ) {
1362 $img_src = plugins_url( 'img/add_translation_disabled.png', __FILE__ );
1363 $td = '<img src="' . $img_src . '" style="margin:2px;">';
1364 } else {
1365 $exist = SIB_Forms_Lang::get_form_ID( $pID, $language['language_code'] );
1366
1367 if ( null === $exist ) {
1368 $img_src = plugins_url( 'img/add_translation.png', __FILE__ );
1369
1370 $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'] );
1371 $td = $href . '<img src="' . $img_src . '" style="margin:2px;"></a>';
1372 } else {
1373 $img_src = plugins_url( 'img/edit_translation.png', __FILE__ );
1374 $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'] );
1375 $td = $href . '<img src="' . $img_src . '" style="margin:2px;"></a>';
1376 }
1377 }
1378 ?>
1379 <td style="text-align: center;"><?php echo $td; ?></td>
1380 <?php
1381 }
1382 ?>
1383 </tr>
1384 </table>
1385 </div>
1386 <?php if ( isset( $_GET['pid'] ) ) { ?>
1387 <div class="sib-form-duplicate">
1388 <button class="btn btn-default sib-duplicate-btn"><?php esc_attr_e( 'Copy content from origin form', 'mailin' ); ?></button>
1389 <span class="sib-spin"><i
1390 class="fa fa-circle-o-notch fa-spin fa-lg"></i>&nbsp;&nbsp;</span>
1391 <i title="<?php echo esc_attr_e( 'Copy content from origin form', 'mailin' ); ?>"
1392 data-container="body" data-toggle="popover" data-placement="left"
1393 data-content="<?php echo esc_attr_e( 'You can copy contents from origin form. You need to translate the contents by this language.', 'mailin' ); ?>"
1394 data-html="true" class="fa fa-question-circle popover-help-form"></i>
1395 </div>
1396 <?php } ?>
1397 </div>
1398 </div>
1399 <?php
1400 }
1401 }
1402
1403 public function ajax_get_country_prefix() {
1404 check_ajax_referer( 'sib_front_ajax_nonce', 'security' );
1405 $sms_manager = new SIB_SMS_Code();
1406 $country_list = $sms_manager->get_sms_code_list();
1407 $country_list_html = '';
1408 foreach ( $country_list as $item => $value ) {
1409 $flg_url = plugins_url( 'img/flags/', __FILE__ ).strtolower($item).'.png';
1410 $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>';
1411 $country_list_html .= $item_html;
1412 }
1413 wp_send_json($country_list_html);
1414 }
1415
1416 /**
1417 * @param string $postAttribute
1418 * @param array $sibAttributes
1419 * @return null|string the corresponding sib attribute or null if not found
1420 */
1421 private function getCorrespondingSibAttribute($postAttribute, $sibAttributes)
1422 {
1423 $normalizedPostAttribute = strtoupper(sanitize_text_field($postAttribute));
1424 foreach ($sibAttributes as $sibAttribute) {
1425 if ($normalizedPostAttribute == strtoupper($sibAttribute)) {
1426 return $sibAttribute;
1427 }
1428 }
1429
1430 return null;
1431 }
1432
1433 public function my_upgrade_function() {
1434 $current_plugin_path_name = plugin_basename( __FILE__ );
1435 activate_plugin( $current_plugin_path_name );
1436 }
1437
1438 public static function wordpress_allowed_attributes()
1439 {
1440 global $allowedposttags, $allowedtags, $allowedentitynames;
1441 $attributes = [$allowedposttags, $allowedtags, $allowedentitynames, self::SIB_ATTRIBUTE];
1442 $attributes = call_user_func_array("array_merge", $attributes);
1443
1444 add_filter( 'safe_style_css', function($css_attr) {
1445 array_push($css_attr, 'display');
1446 return $css_attr;
1447 });
1448
1449 return $attributes;
1450 }
1451 }
1452
1453 add_action( 'sendinblue_init', 'sendinblue_init' );
1454 add_filter( 'widget_text', 'do_shortcode' );
1455
1456 /**
1457 * Plugin entry point Process.
1458 */
1459 function sendinblue_init() {
1460 SIB_Manager::LoadTextDomain();
1461 new SIB_Manager();
1462 }
1463
1464 do_action( 'sendinblue_init' );
1465 }
1466