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