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