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