PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.1.27
Brevo – Email, SMS, Web Push, Chat, and more. v3.1.27
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 4 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
1367 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.27
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', 'mailin' ),
375 'requiredField' => __( 'Please fill out required fields', 'mailin' ),
376 'invalidDateFormat' => __( 'Please fill out valid date format', 'mailin' ),
377 'invalidSMSFormat' => __( 'Please fill out valid phone number', 'mailin' ),
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 $update_data = array(
805 'id' => $data['id'],
806 'email' => $email,
807 'info' => maybe_serialize( $info ),
808 );
809 SIB_Model_Users::update_element( $update_data );
810 $uniqid = $data['code'];
811 }
812 return $uniqid;
813 }
814
815 /**
816 * Use Sendinblue SMTP to send all emails
817 *
818 * @param string $to - reception email.
819 * @param string $subject - subject of email.
820 * @param string $message - message of email.
821 * @param string $headers - header of email.
822 * @param array $attachments - attachments.
823 */
824 static function wp_mail_native( $to, $subject, $message, $headers = '', $attachments = array() ) {
825 $result = require self::$plugin_dir . '/inc/function.wp_mail.php';
826 return $result;
827 }
828
829 /**
830 * To send the transactional email via Sendinblue
831 * hook wp_mail
832 *
833 * @param string $to - reception email.
834 * @param string $subject - subject of email.
835 * @param string $message - message of email.
836 * @param string $headers - header of email.
837 * @param array $attachments - attachments
838 * @param array $tags - tag.
839 * @param string $from_name - sender name.
840 * @param string $from_email - sender email.
841 * @return mixed|WP_Error
842 */
843 static function sib_email( $to, $subject, $message, $headers = '', $attachments = array(), $tags = array(), $from_name = '', $from_email = '' ) {
844 $data = [];
845 // Compact the input, apply the filters, and extract them back out.
846 extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );
847
848 if ( !empty( $attachments ) && ! is_array( $attachments ) ) {
849 $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
850 }
851
852 // From email and name.
853 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
854 if ( isset( $home_settings['sender'] ) ) {
855 $from_name = $home_settings['from_name'];
856 $from_email = $home_settings['from_email'];
857 } else {
858 $from_email = trim( get_bloginfo( 'admin_email' ) );
859 $from_name = trim( get_bloginfo( 'name' ) );
860 }
861 $from_email = apply_filters( 'wp_mail_from', $from_email );
862 $from_name = apply_filters( 'wp_mail_from_name', $from_name );
863
864 if ( !empty( $headers ) ) {
865 if( is_array( $headers ) ){
866 foreach ($headers as $key => $val) {
867 if( stripos($val, "Content-Type: text/html") !== false ) {
868 unset( $headers[$key] );
869 }
870 }
871 $headers = array_values( $headers );
872 if( count( $headers ) == 1 && $headers[0] == '' ) {
873 unset( $headers[0] );
874 }
875 }
876 if( is_string( $headers ) ){
877 $headers = str_replace("Content-Type: text/html", "", $headers);
878 }
879 if( !empty( $headers ) ){
880 $data['headers'] = $headers;
881 }
882 if ( ! is_array( $headers ) ) {
883 // Explode the headers out, so this function can take both.
884 // string headers and an array of headers.
885 $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
886 } else {
887 $tempheaders = $headers;
888 }
889 $headers = array();
890 $bcc = array();
891 // If it's actually got contents.
892 if ( ! empty( $tempheaders ) ) {
893 // Iterate through the raw headers.
894 foreach ( (array) $tempheaders as $header ) {
895 if ( strpos( $header, ':' ) === false ) {
896 if ( false !== stripos( $header, 'boundary=' ) ) {
897 $parts = preg_split( '/boundary=/i', trim( $header ) );
898 $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
899 }
900 continue;
901 }
902 // Explode them out.
903 list($name, $content) = explode( ':', trim( $header ), 2 );
904
905 // Cleanup crew.
906 $name = trim( $name );
907 $content = trim( $content );
908
909 switch ( strtolower( $name ) ) {
910 case 'content-type':
911 $headers[ trim( $name ) ] = trim( $content );
912 break;
913 case 'x-mailin-tag':
914 $headers[ trim( $name ) ] = trim( $content );
915 break;
916 case 'from':
917 if ( strpos( $content, '<' ) !== false ) {
918 // So... making my life hard again?
919 $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
920 $from_name = str_replace( '"', '', $from_name );
921 $from_name = trim( $from_name );
922
923 $from_email = substr( $content, strpos( $content, '<' ) + 1 );
924 $from_email = str_replace( '>', '', $from_email );
925 $from_email = trim( $from_email );
926 } else {
927 $from_name = '';
928 $from_email = trim( $content );
929 }
930 break;
931
932 case 'bcc':
933 if ( strpos( $content, '<') !== false )
934 {
935 $content = str_replace('<', '', $content);
936 $content = str_replace('>', '', $content);
937 }
938 $data['bcc'] = array();
939 $bcc_content = explode(',', $content);
940 foreach ($bcc_content as $key => $value) {
941 if ( ! empty( $value )) {
942 $data['bcc'][] = array('email' => $value);
943 }
944 }
945 break;
946 case 'cc':
947 if ( strpos( $content, '<') !== false )
948 {
949 $content = str_replace('<', '', $content);
950 $content = str_replace('>', '', $content);
951 }
952 $data['cc'] = array();
953 $cc_content = explode(',', $content);
954 foreach ($cc_content as $key => $value) {
955 if ( ! empty( $value )) {
956 $data['cc'][] = array('email' => $value);
957 }
958 }
959 break;
960 case 'reply-to':
961 if ( strpos( $content, '<') !== false )
962 {
963 $reply_content = substr( $content, strpos( $content, '<' ) + 1 );
964 $reply_content = str_replace( '>', '', $reply_content );
965 $reply = trim( $reply_content );
966 } else {
967 $reply = trim( $content );
968 }
969
970 if (!empty($reply)) {
971 $data['replyTo'] = ['email' => trim( $reply )];
972 }
973 break;
974 default:
975 break;
976 }
977 }
978 }
979 }
980
981 // Set destination addresses.
982 if ( ! is_array( $to ) ) {
983 $to = explode( ',', preg_replace( '/\s+/', '', $to ) ); // strip all whitespace.
984 }
985
986 $processed_to = array();
987 foreach ( $to as $email ) {
988 if ( is_array( $email ) ) {
989 $processed_to[] = $email;
990 } else {
991 $processed_to[] = ['email' => $email];
992 }
993 }
994 $data['to'] = $processed_to;
995
996
997 // Attachments.
998 $attachment_content = array();
999 if ( ! empty( $attachments ) ) {
1000 foreach ( $attachments as $attachment ) {
1001 if ( !empty( $attachment ) ) {
1002 $content = self::getAttachmentStruct( $attachment );
1003 if ( ! is_wp_error( $content ) ) {
1004 $attachment_content = array_merge( $attachment_content, $content );
1005 }
1006 }
1007 }
1008 if ( !empty( $attachment_content ) ) {
1009 $data["attachment"] = array($attachment_content);
1010 }
1011 }
1012
1013 // Common transformations for the HTML part.
1014 // If it is text/plain, New line break found.
1015 if ( strpos( $message, '</table>' ) === false && strpos( $message, '</div>' ) === false ) {
1016 if ( strpos( $message, "\n" ) !== false ) {
1017 if ( is_array( $message ) ) {
1018 foreach ( $message as &$value ) {
1019 $value['content'] = preg_replace( '#<(https?://[^*]+)>#', '$1', $value['content'] );
1020 $value['content'] = nl2br( $value['content'] );
1021 }
1022 } else {
1023 $message = preg_replace( '#<(https?://[^*]+)>#', '$1', $message );
1024 $message = nl2br( $message );
1025 }
1026 }
1027 }
1028 // Sending...
1029 $data['sender'] = ['email' => $from_email, 'name' => $from_name ];
1030 $data['subject'] = $subject;
1031 $data['htmlContent'] = $message;
1032
1033 try {
1034 $sent = SIB_API_Manager::send_email( $data );
1035 return $sent;
1036 } catch ( Exception $e ) {
1037 return new WP_Error( $e->getMessage() );
1038 }
1039 }
1040
1041 /**
1042 * @param string $path - attachment file path
1043 * @return array|WP_Error
1044 */
1045 static function getAttachmentStruct( $path ) {
1046
1047 $struct = array();
1048
1049 try {
1050
1051 if ( ! @is_file( $path ) ) {
1052 throw new Exception( $path . ' is not a valid file.' );
1053 }
1054
1055 $filename = basename( $path );
1056
1057 if ( ! function_exists( 'get_magic_quotes' ) ) {
1058 /**
1059 * @return bool
1060 */
1061 function get_magic_quotes() {
1062 return false;
1063 }
1064 }
1065 if ( ! function_exists( 'set_magic_quotes' ) ) {
1066 /**
1067 * @param $value
1068 * @return bool
1069 */
1070 function set_magic_quotes( $value ) {
1071 return true;
1072 }
1073 }
1074
1075 $isMagicQuotesSupported = version_compare( PHP_VERSION, '5.3.0', '<' )
1076 && function_exists( 'get_magic_quotes_runtime' )
1077 && function_exists( 'set_magic_quotes_runtime' );
1078
1079 if ( $isMagicQuotesSupported ) {
1080 // Escape linters check.
1081 $getMagicQuotesRuntimeFunc = 'get_magic_quotes_runtime';
1082 $setMagicQuotesRuntimeFunc = 'set_magic_quotes_runtime';
1083
1084 // Save magic quotes value.
1085 $magicQuotes = $getMagicQuotesRuntimeFunc();
1086 $setMagicQuotesRuntimeFunc (0);
1087 }
1088
1089 $file_buffer = file_get_contents( $path );
1090 $file_buffer = chunk_split( base64_encode( $file_buffer ), 76, "\n" );
1091
1092 if ( $isMagicQuotesSupported ) {
1093 // Restore magic quotes value.
1094 $setMagicQuotesRuntimeFunc($magicQuotes);
1095 }
1096
1097 $struct["name"] = $filename;
1098 $struct["content"] = $file_buffer;
1099
1100 } catch ( Exception $e ) {
1101 return new WP_Error( 'Error creating the attachment structure: ' . $e->getMessage() );
1102 }
1103
1104 return $struct;
1105 }
1106
1107 /**
1108 * Create custom page for form preview
1109 *
1110 * @param array $query_vars - query.
1111 * @return array
1112 */
1113 function sib_query_vars( $query_vars ) {
1114 $query_vars[] = 'sib_form';
1115 return $query_vars;
1116 }
1117
1118 /**
1119 * Parse request
1120 *
1121 * @param mixed $wp - object.
1122 */
1123 function sib_parse_request( &$wp ) {
1124 if ( array_key_exists( 'sib_form', $wp->query_vars ) ) {
1125 include 'inc/sib-form-preview.php';
1126 exit();
1127 }
1128 }
1129
1130 /**
1131 * Load Text domain.
1132 */
1133 static function LoadTextDomain() {
1134 // Load lang file.
1135 $i18n_file_name = 'mailin';
1136 $locale = apply_filters( 'plugin_locale', get_locale(), $i18n_file_name );
1137 // $locale = 'fr_FR';
1138 $filename = plugin_dir_path( __FILE__ ) . '/lang/' . $i18n_file_name . '-' . $locale . '.mo';
1139 load_textdomain( 'mailin', $filename );
1140 }
1141
1142 /**
1143 * Notice the language is difference than site's language
1144 */
1145 static function language_admin_notice() {
1146 if ( ! get_option( SIB_Manager::LANGUAGE_OPTION_NAME ) ) {
1147 $lang_prefix = substr( get_bloginfo( 'language' ), 0, 2 );
1148 $lang = self::getLanguageName( $lang_prefix );
1149 $class = 'error';
1150 $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 );
1151 if ( 'en' !== $lang_prefix && 'fr' !== $lang_prefix ) {
1152 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>" );
1153 }
1154 }
1155 }
1156
1157 /**
1158 * Notice wp_mail is not possible
1159 */
1160 static function wpMailNotices() {
1161 if ( self::$wp_mail_conflict ) {
1162 echo ( '<div class="error"><p>' . __( 'You cannot use Sendinblue SMTP now because wp_mail has been declared by another process or plugin. ', 'mailin' ) . '</p></div>' );
1163 }
1164 }
1165
1166 /**
1167 * Names of languages.
1168 *
1169 * @param string $prefix - language.
1170 * @return mixed
1171 */
1172 public static function getLanguageName( $prefix = 'en' ) {
1173 $lang = array();
1174 $lang['de'] = 'Deutsch';
1175 $lang['en'] = 'English';
1176 $lang['zh'] = '中文';
1177 $lang['ru'] = 'Русский';
1178 $lang['fi'] = 'suomi';
1179 $lang['fr'] = 'Français';
1180 $lang['nl'] = 'Nederlands';
1181 $lang['sv'] = 'Svenska';
1182 $lang['it'] = 'Italiano';
1183 $lang['ro'] = 'Română';
1184 $lang['hu'] = 'Magyar';
1185 $lang['ja'] = '日本語';
1186 $lang['es'] = 'Español';
1187 $lang['vi'] = 'Tiếng Việt';
1188 $lang['ar'] = 'العربية';
1189 $lang['pt'] = 'Português';
1190 $lang['pb'] = 'Português do Brasil';
1191 $lang['pl'] = 'Polski';
1192 $lang['gl'] = 'galego';
1193 $lang['tr'] = 'Turkish';
1194 $lang['et'] = 'Eesti';
1195 $lang['hr'] = 'Hrvatski';
1196 $lang['eu'] = 'Euskera';
1197 $lang['el'] = 'Ελληνικά';
1198 $lang['ua'] = 'Українська';
1199 $lang['ko'] = '한국어';
1200
1201 return $lang[ $prefix ];
1202 }
1203
1204 /**
1205 * Create language sidebar for wpml plugin.
1206 */
1207 public function sib_create_language_sidebar() {
1208 $languages = apply_filters( 'wpml_active_languages', array() );
1209 $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
1210 $action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : '';
1211 $frmID = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : '';
1212 $pID = isset( $_GET['pid'] ) ? sanitize_text_field( $_GET['pid'] ) : '';
1213 $parent = true;
1214 if ( '' !== $frmID && '' !== $pID ) {
1215 $lang = SIB_Forms_Lang::get_lang( $frmID, $pID );
1216 $parent = false;
1217 } else {
1218 $lang = ICL_LANGUAGE_CODE;
1219 if ( '' !== $frmID && '' === $pID ) {
1220 $pID = $frmID;
1221
1222 }
1223 }
1224
1225 if ( 'sib_page_form' === $page && 'edit' === $action ) {
1226 ?>
1227 <div class="panel panel-default text-left box-border-box sib-small-content">
1228 <div class="panel-heading"><strong><?php esc_attr_e( 'About Sendinblue', 'mailin' ); ?></strong></div>
1229 <div class="panel-body">
1230 <p>
1231 <label for='sib_form_language'><?php esc_attr_e( 'Language of this form:', 'mailin' ); ?> </label>
1232 <select id="sib_form_lang" name="sib_form_lang" data-selected="">
1233 <?php
1234 foreach ( $languages as $language ) {
1235 $selected = ($language['code'] == $lang) ? 'selected' : '';
1236 if ( $language['code'] == $lang && true === $parent ) {
1237 $option_text = '<option value="" ' . $selected . '>' . $language['native_name'] . '</option>';
1238 } else {
1239 $exist = SIB_Forms_Lang::get_form_ID( $pID, $language['language_code'] );
1240
1241 if ( null === $exist ) {
1242 continue;
1243 } else {
1244 $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>', sanitize_text_field( $_REQUEST['page'] ), 'edit', absint( $pID ), $language['language_code'], $selected, $language['native_name'] );
1245 }
1246 }
1247 echo $option_text ;
1248 }
1249 ?>
1250 </select>
1251 </p>
1252 <div class="sib_form_translate">
1253 <p>
1254 <label><?php esc_attr_e( 'Translate this form', 'mailin' ); ?></label>
1255 </p>
1256 <table width="100%" class="sib_form_trans_table" style="border: 1px solid #8cceea;">
1257 <tr>
1258 <?php
1259 foreach ( $languages as $language ) {
1260 if ( $language['code'] == $lang ) {
1261 continue;
1262 }
1263 ?>
1264 <th style="text-align: center;"><img
1265 src="<?php echo esc_url( $language['country_flag_url'] ); ?>"></th>
1266 <?php
1267 }
1268 ?>
1269 </tr>
1270 <tr style="background-color: #EFF8FC;">
1271 <?php
1272 foreach ( $languages as $language ) {
1273 if ( $language['code'] == $lang ) {
1274 continue;
1275 }
1276 if ( '' === $pID ) {
1277 $img_src = plugins_url( 'img/add_translation_disabled.png', __FILE__ );
1278 $td = '<img src="' . $img_src . '" style="margin:2px;">';
1279 } else {
1280 $exist = SIB_Forms_Lang::get_form_ID( $pID, $language['language_code'] );
1281
1282 if ( null === $exist ) {
1283 $img_src = plugins_url( 'img/add_translation.png', __FILE__ );
1284
1285 $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'] );
1286 $td = $href . '<img src="' . $img_src . '" style="margin:2px;"></a>';
1287 } else {
1288 $img_src = plugins_url( 'img/edit_translation.png', __FILE__ );
1289 $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;">', sanitize_text_field( $_REQUEST['page'] ), 'edit', absint( $exist ), absint( $pID ), $language['language_code'] );
1290 $td = $href . '<img src="' . $img_src . '" style="margin:2px;"></a>';
1291 }
1292 }
1293 ?>
1294 <td style="text-align: center;"><?php echo $td; ?></td>
1295 <?php
1296 }
1297 ?>
1298 </tr>
1299 </table>
1300 </div>
1301 <?php if ( isset( $_GET['pid'] ) ) { ?>
1302 <div class="sib-form-duplicate">
1303 <button class="btn btn-default sib-duplicate-btn"><?php esc_attr_e( 'Copy content from origin form', 'mailin' ); ?></button>
1304 <span class="sib-spin"><i
1305 class="fa fa-circle-o-notch fa-spin fa-lg"></i>&nbsp;&nbsp;</span>
1306 <i title="<?php echo esc_attr_e( 'Copy content from origin form', 'mailin' ); ?>"
1307 data-container="body" data-toggle="popover" data-placement="left"
1308 data-content="<?php echo esc_attr_e( 'You can copy contents from origin form. You need to translate the contents by this language.', 'mailin' ); ?>"
1309 data-html="true" class="fa fa-question-circle popover-help-form"></i>
1310 </div>
1311 <?php } ?>
1312 </div>
1313 </div>
1314 <?php
1315 }
1316 }
1317
1318 public function ajax_get_country_prefix() {
1319 check_ajax_referer( 'sib_front_ajax_nonce', 'security' );
1320 $sms_manager = new SIB_SMS_Code();
1321 $country_list = $sms_manager->get_sms_code_list();
1322 $country_list_html = '';
1323 foreach ( $country_list as $item => $value ) {
1324 $flg_url = plugins_url( 'img/flags/', __FILE__ ).strtolower($item).'.png';
1325 $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>';
1326 $country_list_html .= $item_html;
1327 }
1328 wp_send_json($country_list_html);
1329 }
1330
1331 /**
1332 * @param string $postAttribute
1333 * @param array $sibAttributes
1334 * @return null|string the corresponding sib attribute or null if not found
1335 */
1336 private function getCorrespondingSibAttribute($postAttribute, $sibAttributes)
1337 {
1338 $normalizedPostAttribute = strtoupper(sanitize_text_field($postAttribute));
1339 foreach ($sibAttributes as $sibAttribute) {
1340 if ($normalizedPostAttribute == strtoupper($sibAttribute)) {
1341 return $sibAttribute;
1342 }
1343 }
1344
1345 return null;
1346 }
1347
1348 public function my_upgrade_function() {
1349 $current_plugin_path_name = plugin_basename( __FILE__ );
1350 activate_plugin( $current_plugin_path_name );
1351 }
1352 }
1353
1354 add_action( 'sendinblue_init', 'sendinblue_init' );
1355 add_filter( 'widget_text', 'do_shortcode' );
1356
1357 /**
1358 * Plugin entry point Process.
1359 */
1360 function sendinblue_init() {
1361 SIB_Manager::LoadTextDomain();
1362 new SIB_Manager();
1363 }
1364
1365 do_action( 'sendinblue_init' );
1366 }
1367