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