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