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