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