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