PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.1.37
Brevo – Email, SMS, Web Push, Chat, and more. v3.1.37
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 6 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 12 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
1467 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.37
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 = 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 $from_email = apply_filters( 'wp_mail_from', $from_email );
947 $from_name = apply_filters( 'wp_mail_from_name', $from_name );
948
949 if ( !empty( $headers ) ) {
950 if( is_array( $headers ) ){
951 foreach ($headers as $key => $val) {
952 if( stripos($val, "Content-Type: text/html") !== false ) {
953 unset( $headers[$key] );
954 }
955 }
956 $headers = array_values( $headers );
957 if( count( $headers ) == 1 && $headers[0] == '' ) {
958 unset( $headers[0] );
959 }
960 }
961 if( is_string( $headers ) ){
962 $headers = str_replace("Content-Type: text/html", "", $headers);
963 }
964 if( !empty( $headers ) ){
965 $data['headers'] = $headers;
966 }
967 if ( ! is_array( $headers ) ) {
968 // Explode the headers out, so this function can take both.
969 // string headers and an array of headers.
970 $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
971 } else {
972 $tempheaders = $headers;
973 }
974 $headers = array();
975 $bcc = array();
976 // If it's actually got contents.
977 if ( ! empty( $tempheaders ) ) {
978 // Iterate through the raw headers.
979 foreach ( (array) $tempheaders as $header ) {
980 if ( strpos( $header, ':' ) === false ) {
981 if ( false !== stripos( $header, 'boundary=' ) ) {
982 $parts = preg_split( '/boundary=/i', trim( $header ) );
983 $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
984 }
985 continue;
986 }
987 // Explode them out.
988 list($name, $content) = explode( ':', trim( $header ), 2 );
989
990 // Cleanup crew.
991 $name = trim( $name );
992 $content = trim( $content );
993
994 switch ( strtolower( $name ) ) {
995 case 'content-type':
996 $headers[ trim( $name ) ] = trim( $content );
997 break;
998 case 'x-mailin-tag':
999 $headers[ trim( $name ) ] = trim( $content );
1000 break;
1001 case 'from':
1002 if ( strpos( $content, '<' ) !== false ) {
1003 // So... making my life hard again?
1004 $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
1005 $from_name = str_replace( '"', '', $from_name );
1006 $from_name = trim( $from_name );
1007
1008 $from_email = substr( $content, strpos( $content, '<' ) + 1 );
1009 $from_email = str_replace( '>', '', $from_email );
1010 $from_email = trim( $from_email );
1011 } else {
1012 $from_name = '';
1013 $from_email = trim( $content );
1014 }
1015 break;
1016
1017 case 'bcc':
1018 if ( strpos( $content, '<') !== false )
1019 {
1020 $content = str_replace('<', '', $content);
1021 $content = str_replace('>', '', $content);
1022 }
1023 $data['bcc'] = array();
1024 $bcc_content = explode(',', $content);
1025 foreach ($bcc_content as $key => $value) {
1026 if ( ! empty( $value )) {
1027 $data['bcc'][] = array('email' => $value);
1028 }
1029 }
1030 break;
1031 case 'cc':
1032 if ( strpos( $content, '<') !== false )
1033 {
1034 $content = str_replace('<', '', $content);
1035 $content = str_replace('>', '', $content);
1036 }
1037 $data['cc'] = array();
1038 $cc_content = explode(',', $content);
1039 foreach ($cc_content as $key => $value) {
1040 if ( ! empty( $value )) {
1041 $data['cc'][] = array('email' => $value);
1042 }
1043 }
1044 break;
1045 case 'reply-to':
1046 if ( strpos( $content, '<') !== false )
1047 {
1048 $reply_content = substr( $content, strpos( $content, '<' ) + 1 );
1049 $reply_content = str_replace( '>', '', $reply_content );
1050 $reply = trim( $reply_content );
1051 } else {
1052 $reply = trim( $content );
1053 }
1054
1055 if (!empty($reply)) {
1056 $data['replyTo'] = ['email' => trim( $reply )];
1057 }
1058 break;
1059 default:
1060 break;
1061 }
1062 }
1063 }
1064 }
1065
1066 // Set destination addresses.
1067 if ( ! is_array( $to ) ) {
1068 $to = explode( ',', preg_replace( '/\s+/', '', $to ) ); // strip all whitespace.
1069 }
1070
1071 $processed_to = array();
1072 foreach ( $to as $email ) {
1073 if ( is_array( $email ) ) {
1074 $processed_to[] = $email;
1075 } else {
1076 $processed_to[] = ['email' => $email];
1077 }
1078 }
1079 $data['to'] = $processed_to;
1080
1081
1082 // Attachments.
1083 $attachment_content = array();
1084 if ( ! empty( $attachments ) ) {
1085 foreach ( $attachments as $attachment ) {
1086 if ( !empty( $attachment ) ) {
1087 $content = self::getAttachmentStruct( $attachment );
1088 if ( ! is_wp_error( $content ) ) {
1089 $attachment_content = array_merge( $attachment_content, $content );
1090 }
1091 }
1092 }
1093 if ( !empty( $attachment_content ) ) {
1094 $data["attachment"] = array($attachment_content);
1095 }
1096 }
1097
1098 // Common transformations for the HTML part.
1099 // If it is text/plain, New line break found.
1100 if ( strpos( $message, '</table>' ) === false && strpos( $message, '</div>' ) === false ) {
1101 if ( strpos( $message, "\n" ) !== false ) {
1102 if ( is_array( $message ) ) {
1103 foreach ( $message as &$value ) {
1104 $value['content'] = preg_replace( '#<(https?://[^*]+)>#', '$1', $value['content'] );
1105 $value['content'] = nl2br( $value['content'] );
1106 }
1107 } else {
1108 $message = preg_replace( '#<(https?://[^*]+)>#', '$1', $message );
1109 $message = nl2br( $message );
1110 }
1111 }
1112 }
1113 // Sending...
1114 $data['sender'] = ['email' => $from_email, 'name' => $from_name ];
1115 $data['subject'] = $subject;
1116 $data['htmlContent'] = $message;
1117
1118 try {
1119 $sent = SIB_API_Manager::send_email( $data );
1120 return $sent;
1121 } catch ( Exception $e ) {
1122 return new WP_Error( $e->getMessage() );
1123 }
1124 }
1125
1126 /**
1127 * @param string $path - attachment file path
1128 * @return array|WP_Error
1129 */
1130 static function getAttachmentStruct( $path ) {
1131
1132 $struct = array();
1133
1134 try {
1135
1136 if ( ! @is_file( $path ) ) {
1137 throw new Exception( $path . ' is not a valid file.' );
1138 }
1139
1140 $filename = basename( $path );
1141
1142 if ( ! function_exists( 'get_magic_quotes' ) ) {
1143 /**
1144 * @return bool
1145 */
1146 function get_magic_quotes() {
1147 return false;
1148 }
1149 }
1150 if ( ! function_exists( 'set_magic_quotes' ) ) {
1151 /**
1152 * @param $value
1153 * @return bool
1154 */
1155 function set_magic_quotes( $value ) {
1156 return true;
1157 }
1158 }
1159
1160 $isMagicQuotesSupported = version_compare( PHP_VERSION, '5.3.0', '<' )
1161 && function_exists( 'get_magic_quotes_runtime' )
1162 && function_exists( 'set_magic_quotes_runtime' );
1163
1164 if ( $isMagicQuotesSupported ) {
1165 // Escape linters check.
1166 $getMagicQuotesRuntimeFunc = 'get_magic_quotes_runtime';
1167 $setMagicQuotesRuntimeFunc = 'set_magic_quotes_runtime';
1168
1169 // Save magic quotes value.
1170 $magicQuotes = $getMagicQuotesRuntimeFunc();
1171 $setMagicQuotesRuntimeFunc (0);
1172 }
1173
1174 $file_buffer = file_get_contents( $path );
1175 $file_buffer = chunk_split( base64_encode( $file_buffer ), 76, "\n" );
1176
1177 if ( $isMagicQuotesSupported ) {
1178 // Restore magic quotes value.
1179 $setMagicQuotesRuntimeFunc($magicQuotes);
1180 }
1181
1182 $struct["name"] = $filename;
1183 $struct["content"] = $file_buffer;
1184
1185 } catch ( Exception $e ) {
1186 return new WP_Error( 'Error creating the attachment structure: ' . $e->getMessage() );
1187 }
1188
1189 return $struct;
1190 }
1191
1192 /**
1193 * Create custom page for form preview
1194 *
1195 * @param array $query_vars - query.
1196 * @return array
1197 */
1198 function sib_query_vars( $query_vars ) {
1199 $query_vars[] = 'sib_form';
1200 return $query_vars;
1201 }
1202
1203 /**
1204 * Parse request
1205 *
1206 * @param mixed $wp - object.
1207 */
1208 function sib_parse_request( &$wp ) {
1209 if ( array_key_exists( 'sib_form', $wp->query_vars ) ) {
1210 include 'inc/sib-form-preview.php';
1211 exit();
1212 }
1213 }
1214
1215 /**
1216 * Load Text domain.
1217 */
1218 static function LoadTextDomain() {
1219 // Load lang file.
1220 $i18n_file_name = 'mailin';
1221 $locale = apply_filters( 'plugin_locale', get_locale(), $i18n_file_name );
1222 // $locale = 'fr_FR';
1223 $filename = plugin_dir_path( __FILE__ ) . '/lang/' . $i18n_file_name . '-' . $locale . '.mo';
1224 load_textdomain( 'mailin', $filename );
1225 }
1226
1227 /**
1228 * Notice the language is difference than site's language
1229 */
1230 static function language_admin_notice() {
1231 if ( ! get_option( SIB_Manager::LANGUAGE_OPTION_NAME ) ) {
1232 $lang_prefix = substr( get_bloginfo( 'language' ), 0, 2 );
1233 $lang = self::getLanguageName( $lang_prefix );
1234 $class = 'error';
1235 $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 );
1236 if ( 'en' !== $lang_prefix && 'fr' !== $lang_prefix ) {
1237 // phpcs:ignore
1238 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>" );
1239 }
1240 }
1241 }
1242
1243 /**
1244 * Notice wp_mail is not possible
1245 */
1246 static function wpMailNotices() {
1247 if ( self::$wp_mail_conflict ) {
1248 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>' );
1249 }
1250 }
1251
1252 /**
1253 * Names of languages.
1254 *
1255 * @param string $prefix - language.
1256 * @return mixed
1257 */
1258 public static function getLanguageName( $prefix = 'en' ) {
1259 $lang = array();
1260 $lang['de'] = 'Deutsch';
1261 $lang['en'] = 'English';
1262 $lang['zh'] = '中文';
1263 $lang['ru'] = 'Русский';
1264 $lang['fi'] = 'suomi';
1265 $lang['fr'] = 'Français';
1266 $lang['nl'] = 'Nederlands';
1267 $lang['sv'] = 'Svenska';
1268 $lang['it'] = 'Italiano';
1269 $lang['ro'] = 'Română';
1270 $lang['hu'] = 'Magyar';
1271 $lang['ja'] = '日本語';
1272 $lang['es'] = 'Español';
1273 $lang['vi'] = 'Tiếng Việt';
1274 $lang['ar'] = 'العربية';
1275 $lang['pt'] = 'Português';
1276 $lang['pb'] = 'Português do Brasil';
1277 $lang['pl'] = 'Polski';
1278 $lang['gl'] = 'galego';
1279 $lang['tr'] = 'Turkish';
1280 $lang['et'] = 'Eesti';
1281 $lang['hr'] = 'Hrvatski';
1282 $lang['eu'] = 'Euskera';
1283 $lang['el'] = 'Ελληνικά';
1284 $lang['ua'] = 'Українська';
1285 $lang['ko'] = '한국어';
1286
1287 return $lang[ $prefix ];
1288 }
1289
1290 /**
1291 * Create language sidebar for wpml plugin.
1292 */
1293 public function sib_create_language_sidebar() {
1294 $languages = apply_filters( 'wpml_active_languages', array() );
1295 $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
1296 $action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : '';
1297 $frmID = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : '';
1298 $pID = isset( $_GET['pid'] ) ? sanitize_text_field( $_GET['pid'] ) : '';
1299 $parent = true;
1300 if ( '' !== $frmID && '' !== $pID ) {
1301 $lang = SIB_Forms_Lang::get_lang( $frmID, $pID );
1302 $parent = false;
1303 } else {
1304 $lang = ICL_LANGUAGE_CODE;
1305 if ( '' !== $frmID && '' === $pID ) {
1306 $pID = $frmID;
1307
1308 }
1309 }
1310
1311 if ( 'sib_page_form' === $page && 'edit' === $action ) {
1312 ?>
1313 <div class="panel panel-default text-left box-border-box sib-small-content">
1314 <div class="panel-heading"><strong><?php esc_attr_e( 'About Sendinblue', 'mailin' ); ?></strong></div>
1315 <div class="panel-body">
1316 <p>
1317 <label for='sib_form_language'><?php esc_attr_e( 'Language of this form:', 'mailin' ); ?> </label>
1318 <select id="sib_form_lang" name="sib_form_lang" data-selected="">
1319 <?php
1320 foreach ( $languages as $language ) {
1321 $selected = ($language['code'] == $lang) ? 'selected' : '';
1322 if ( $language['code'] == $lang && true === $parent ) {
1323 $option_text = '<option value="" ' . $selected . '>' . $language['native_name'] . '</option>';
1324 } else {
1325 $exist = SIB_Forms_Lang::get_form_ID( $pID, $language['language_code'] );
1326
1327 if ( null === $exist ) {
1328 continue;
1329 } else {
1330 $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'] );
1331 }
1332 }
1333 echo $option_text ;
1334 }
1335 ?>
1336 </select>
1337 </p>
1338 <div class="sib_form_translate">
1339 <p>
1340 <label><?php esc_attr_e( 'Translate this form', 'mailin' ); ?></label>
1341 </p>
1342 <table width="100%" class="sib_form_trans_table" style="border: 1px solid #8cceea;">
1343 <tr>
1344 <?php
1345 foreach ( $languages as $language ) {
1346 if ( $language['code'] == $lang ) {
1347 continue;
1348 }
1349 ?>
1350 <th style="text-align: center;"><img
1351 src="<?php echo esc_url( $language['country_flag_url'] ); ?>"></th>
1352 <?php
1353 }
1354 ?>
1355 </tr>
1356 <tr style="background-color: #EFF8FC;">
1357 <?php
1358 foreach ( $languages as $language ) {
1359 if ( $language['code'] == $lang ) {
1360 continue;
1361 }
1362 if ( '' === $pID ) {
1363 $img_src = plugins_url( 'img/add_translation_disabled.png', __FILE__ );
1364 $td = '<img src="' . $img_src . '" style="margin:2px;">';
1365 } else {
1366 $exist = SIB_Forms_Lang::get_form_ID( $pID, $language['language_code'] );
1367
1368 if ( null === $exist ) {
1369 $img_src = plugins_url( 'img/add_translation.png', __FILE__ );
1370
1371 $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'] );
1372 $td = $href . '<img src="' . $img_src . '" style="margin:2px;"></a>';
1373 } else {
1374 $img_src = plugins_url( 'img/edit_translation.png', __FILE__ );
1375 $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'] );
1376 $td = $href . '<img src="' . $img_src . '" style="margin:2px;"></a>';
1377 }
1378 }
1379 ?>
1380 <td style="text-align: center;"><?php echo wp_kses($td, wp_kses_allowed_html()); ?></td>
1381 <?php
1382 }
1383 ?>
1384 </tr>
1385 </table>
1386 </div>
1387 <?php if ( isset( $_GET['pid'] ) ) { ?>
1388 <div class="sib-form-duplicate">
1389 <button class="btn btn-default sib-duplicate-btn"><?php esc_attr_e( 'Copy content from origin form', 'mailin' ); ?></button>
1390 <span class="sib-spin"><i
1391 class="fa fa-circle-o-notch fa-spin fa-lg"></i>&nbsp;&nbsp;</span>
1392 <i title="<?php echo esc_attr_e( 'Copy content from origin form', 'mailin' ); ?>"
1393 data-container="body" data-toggle="popover" data-placement="left"
1394 data-content="<?php echo esc_attr_e( 'You can copy contents from origin form. You need to translate the contents by this language.', 'mailin' ); ?>"
1395 data-html="true" class="fa fa-question-circle popover-help-form"></i>
1396 </div>
1397 <?php } ?>
1398 </div>
1399 </div>
1400 <?php
1401 }
1402 }
1403
1404 public function ajax_get_country_prefix() {
1405 check_ajax_referer( 'sib_front_ajax_nonce', 'security' );
1406 $sms_manager = new SIB_SMS_Code();
1407 $country_list = $sms_manager->get_sms_code_list();
1408 $country_list_html = '';
1409 foreach ( $country_list as $item => $value ) {
1410 $flg_url = plugins_url( 'img/flags/', __FILE__ ).strtolower($item).'.png';
1411 $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>';
1412 $country_list_html .= $item_html;
1413 }
1414 wp_send_json($country_list_html);
1415 }
1416
1417 /**
1418 * @param string $postAttribute
1419 * @param array $sibAttributes
1420 * @return null|string the corresponding sib attribute or null if not found
1421 */
1422 private function getCorrespondingSibAttribute($postAttribute, $sibAttributes)
1423 {
1424 $normalizedPostAttribute = strtoupper(sanitize_text_field($postAttribute));
1425 foreach ($sibAttributes as $sibAttribute) {
1426 if ($normalizedPostAttribute == strtoupper($sibAttribute)) {
1427 return $sibAttribute;
1428 }
1429 }
1430
1431 return null;
1432 }
1433
1434 public function my_upgrade_function() {
1435 $current_plugin_path_name = plugin_basename( __FILE__ );
1436 activate_plugin( $current_plugin_path_name );
1437 }
1438
1439 public static function wordpress_allowed_attributes()
1440 {
1441 global $allowedposttags, $allowedtags, $allowedentitynames;
1442 $attributes = [$allowedposttags, $allowedtags, $allowedentitynames, self::SIB_ATTRIBUTE];
1443 $attributes = call_user_func_array("array_merge", $attributes);
1444
1445 add_filter( 'safe_style_css', function($css_attr) {
1446 array_push($css_attr, 'display');
1447 return $css_attr;
1448 });
1449
1450 return $attributes;
1451 }
1452 }
1453
1454 add_action( 'sendinblue_init', 'sendinblue_init' );
1455 add_filter( 'widget_text', 'do_shortcode' );
1456
1457 /**
1458 * Plugin entry point Process.
1459 */
1460 function sendinblue_init() {
1461 SIB_Manager::LoadTextDomain();
1462 new SIB_Manager();
1463 }
1464
1465 do_action( 'sendinblue_init' );
1466 }
1467