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