PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.1.41
Brevo – Email, SMS, Web Push, Chat, and more. v3.1.41
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 / page / page-home.php
mailin / page Last commit date
index.php 11 years ago page-form.php 4 years ago page-home.php 4 years ago page-scenarios.php 4 years ago page-statistics.php 4 years ago
page-home.php
848 lines
1 <?php
2 /**
3 * Admin page : dashboard
4 *
5 * @package SIB_Page_Home
6 */
7
8 if ( ! class_exists( 'SIB_Page_Home' ) ) {
9 /**
10 * Page class that handles backend page <i>dashboard ( for admin )</i> with form generation and processing
11 *
12 * @package SIB_Page_Home
13 */
14 class SIB_Page_Home {
15
16 /**
17 * Page slug
18 */
19 const PAGE_ID = 'sib_page_home';
20
21 /**
22 * Page hook
23 *
24 * @var string
25 */
26 protected $page_hook;
27
28 /**
29 * Page tabs
30 *
31 * @var mixed
32 */
33 protected $tabs;
34
35 /**
36 * Constructs new page object and adds entry to WordPress admin menu
37 */
38 function __construct() {
39 add_menu_page( __( 'Sendinblue', 'mailin' ), __( 'Sendinblue', 'mailin' ), 'manage_options', self::PAGE_ID, array( &$this, 'generate' ), SIB_Manager::$plugin_url . '/img/favicon.ico' );
40 $this->page_hook = add_submenu_page( self::PAGE_ID, __( 'Home', 'mailin' ), __( 'Home', 'mailin' ), 'manage_options', self::PAGE_ID, array( &$this, 'generate' ) );
41 add_action( 'load-' . $this->page_hook, array( &$this, 'init' ) );
42 add_action( 'admin_print_scripts-' . $this->page_hook, array( $this, 'enqueue_scripts' ) );
43 add_action( 'admin_print_styles-' . $this->page_hook, array( $this, 'enqueue_styles' ) );
44 }
45
46 /**
47 * Init Process
48 */
49 function Init() {
50 if ( ( isset( $_GET['sib_action'] ) ) && ( 'logout' === sanitize_text_field($_GET['sib_action'] )) ) {
51 $this->logout();
52 }
53 }
54
55 /**
56 * Enqueue scripts of plugin
57 */
58 function enqueue_scripts() {
59 wp_enqueue_script( 'sib-admin-js' );
60 wp_enqueue_script( 'sib-bootstrap-js' );
61 wp_enqueue_script( 'sib-chosen-js' );
62 wp_localize_script(
63 'sib-admin-js', 'ajax_sib_object',
64 array(
65 'ajax_url' => admin_url( 'admin-ajax.php' ),
66 'ajax_nonce' => wp_create_nonce( 'ajax_sib_admin_nonce' ),
67 )
68 );
69 }
70
71 /**
72 * Enqueue style sheets of plugin
73 */
74 function enqueue_styles() {
75 wp_enqueue_style( 'sib-admin-css' );
76 wp_enqueue_style( 'sib-bootstrap-css' );
77 wp_enqueue_style( 'sib-chosen-css' );
78 wp_enqueue_style( 'sib-fontawesome-css' );
79 }
80
81 /** Generate page script */
82 function generate() {
83 ?>
84 <div id="wrap" class="wrap box-border-box container-fluid">
85 <h2><img id="logo-img" src="<?php echo esc_url( SIB_Manager::$plugin_url . '/img/logo.png' ); ?>"></h2>
86 <div class="row">
87 <div id="wrap-left" class="box-border-box col-md-9">
88 <div id="sib-message-box" class="row alert alert-success" style="display: none;">
89 <p id="sib-message-body"></p>
90 </div>
91 <?php
92 if ( SIB_Manager::is_done_validation(false)) {
93 $this->generate_main_content();
94 } else {
95 $this->generate_welcome_content();
96 }
97 ?>
98 </div>
99 <div id="wrap-right-side" class="box-border-box col-md-3">
100 <?php
101 self::generate_side_bar();
102 ?>
103 </div>
104 </div>
105 </div>
106 <?php
107 }
108
109 /** Generate welcome page before validation */
110 function generate_welcome_content() {
111 ?>
112
113 <div id="main-content" class="sib-content">
114 <input type="hidden" id="cur_refer_url" value="<?php echo esc_url( add_query_arg( array( 'page' => 'sib_page_home' ), admin_url( 'admin.php' ) ) ); ?> ">
115 <div class="card sib-small-content">
116 <div class="card-header">
117 <span style="color: #777777;"><?php esc_attr_e( 'Step', 'mailin' ); ?> 1&nbsp;|&nbsp;</span><strong><?php esc_attr_e( 'Create a Sendinblue Account', 'mailin' ); ?></strong>
118 </div>
119 <div class="card-body">
120 <div class="col-md-9">
121 <p><?php esc_attr_e( 'By creating a free Sendinblue account, you will be able to send confirmation emails and:', 'mailin' ); ?></p>
122 <ul class="sib-home-feature">
123 <li><span class="glyphicon glyphicon-ok" style="font-size: 12px;"></span>&nbsp;&nbsp;<?php esc_attr_e( 'Collect your contacts and upload your lists', 'mailin' ); ?></li>
124 <li><span class="glyphicon glyphicon-ok" style="font-size: 12px;"></span>&nbsp;&nbsp;<?php esc_attr_e( 'Use Sendinblue SMTP to send your transactional emails', 'mailin' ); ?></li>
125 <li class="home-read-more-content"><span class="glyphicon glyphicon-ok" style="font-size: 12px;"></span>&nbsp;&nbsp;<?php esc_attr_e( 'Email marketing builders', 'mailin' ); ?></li>
126 <li class="home-read-more-content"><span class="glyphicon glyphicon-ok" style="font-size: 12px;"></span>&nbsp;&nbsp;<?php esc_attr_e( 'Create and schedule your email marketing campaigns', 'mailin' ); ?></li>
127 <li class="home-read-more-content"><span class="glyphicon glyphicon-ok" style="font-size: 12px;"></span>&nbsp;&nbsp;<?php esc_attr_e( 'Try all of', 'mailin' ); ?>&nbsp;<a href="https://www.sendinblue.com/features/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank"><?php esc_attr_e( 'Sendinblue\'s features', 'mailin' ); ?></a></li>
128 </ul>
129 <a href="https://www.sendinblue.com/users/signup?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" class="btn btn-primary" target="_blank" style="margin-top: 10px;"><?php esc_attr_e( 'Create an account', 'mailin' ); ?></a>
130 </div>
131 </div>
132 </div>
133 <div class="card sib-small-content">
134 <div class="card-header">
135 <span style="color: #777777;"><?php esc_attr_e( 'Step', 'mailin' ); ?> 2&nbsp;|&nbsp;</span><strong><?php esc_attr_e( 'Activate your account with your API key v3', 'mailin' ); ?></strong>
136 </div>
137 <div class="card-body">
138 <div class="col-md-9 row">
139 <div id="success-alert" class="alert alert-success" role="alert" style="display: none;"><?php esc_attr_e( 'You successfully activate your account.', 'mailin' ); ?></div>
140 <input type="hidden" id="general_error" value="<?php esc_attr_e( 'Please input a valid API v3 key', 'mailin' ); ?>">
141 <input type="hidden" id="curl_no_exist_error" value="<?php esc_attr_e( 'Please install curl on site to use sendinblue plugin.', 'mailin' ); ?>">
142 <input type="hidden" id="curl_error" value="<?php esc_attr_e( 'Curl error.', 'mailin' ); ?>">
143 <div id="failure-alert" class="alert alert-danger" role="alert" style="display: none;"><?php esc_attr_e( 'Please input a valid API v3 key.', 'mailin' ); ?></div>
144 <p>
145 <?php esc_attr_e( 'Once you have created a Sendinblue account, activate this plugin to send all of your transactional emails via Sendinblue SMTP. Sendinblue optimizes email delivery to ensure emails reach the inbox.', 'mailin' ); ?><br>
146 <?php esc_attr_e( 'To activate your plugin, enter your API v3 Access key.', 'mailin' ); ?><br>
147 </p>
148 <p>
149 <a href="https://my.sendinblue.com/advanced/apikey/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank"><i class="fa fa-angle-right"></i>&nbsp;<?php esc_attr_e( 'Get your API key from your account', 'mailin' ); ?></a>
150 </p>
151 <p>
152 <div class="col-md-7">
153 <p class="col-md-12"><input id="sib_access_key" type="text" class="col-md-10" style="margin-top: 10px;" placeholder="xkeysib-xxxxxx"></p>
154 <p class="col-md-12"><button type="button" id="sib_validate_btn" class="col-md-4 btn btn-primary"><span class="sib-spin"><i class="fa fa-circle-o-notch fa-spin fa-lg"></i>&nbsp;&nbsp;</span><?php esc_attr_e( 'Login', 'mailin' ); ?></button></p>
155 </div>
156 </p>
157 </div>
158 </div>
159 </div>
160 </div>
161 <?php
162 }
163
164 /** Generate main home page after validation */
165 function generate_main_content() {
166
167 // display account info.
168 $account_settings = SIB_API_Manager::get_account_info();
169 $account_email = $account_settings['account_email'];
170 $account_user_name = isset( $account_settings['account_user_name'] ) ? $account_settings['account_user_name'] : '';
171 $account_data = isset( $account_settings['account_data'] ) ? $account_settings['account_data'] : '';
172 // check smtp available.
173 $smtp_status = SIB_API_Manager::get_smtp_status();
174
175 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
176 // for upgrade to 2.6.0 from old version.
177 if ( ! isset( $home_settings['activate_ma'] ) ) {
178 $home_settings['activate_ma'] = 'no';
179 }
180 // set default sender info.
181 $senders = SIB_API_Manager::get_sender_lists();
182 if (is_array( $senders) && (!isset( $home_settings['sender'] ) || (count($senders) == 1 && $home_settings['from_email'] != $senders[0]['from_email']))) {
183 $home_settings['sender'] = $senders[0]['id'];
184 $home_settings['from_name'] = $senders[0]['from_name'];
185 $home_settings['from_email'] = $senders[0]['from_email'];
186 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
187 }
188
189 // Users Sync part.
190 $currentUsers = count_users();
191 $isSynced = get_option( 'sib_sync_users', '0' );
192 $isEnableSync = '0';
193 if ( $isSynced != $currentUsers['total_users'] ) {
194 $isEnableSync = '1';
195 /* translators: %s: total users */
196 $desc = sprintf( esc_attr__( 'You have %s existing users. Do you want to add them to Sendinblue?', 'mailin' ), $currentUsers['total_users'] );
197 self::print_sync_popup();
198 } else {
199 $desc = esc_attr__( 'All your users have been added to a Sendinblue list.','mailin' );
200 }
201 ?>
202
203 <div id="main-content" class="sib-content">
204 <input type="hidden" id="cur_refer_url" value="<?php echo esc_url( add_query_arg( array( 'page' => 'sib_page_home' ), admin_url( 'admin.php' ) ) ); ?> ">
205 <!-- Account Info -->
206 <div class="card sib-small-content">
207 <div class="card-header">
208 <strong><?php esc_attr_e( 'My Account', 'mailin' ); ?></strong>
209 </div>
210 <div class="card-body">
211 <div class="col-md-12">
212 <span><b><?php esc_attr_e( 'You are currently logged in as : ', 'mailin' ); ?></b></span>
213 <div style="margin-bottom: 10px;">
214 <p class="col-md-12" style="margin-top: 5px;">
215 <?php echo esc_attr( $account_user_name ); ?>&nbsp;-&nbsp;<?php echo esc_attr( $account_email ); ?><br>
216 <?php
217 $count = count( $account_data );
218 for ( $i = 0; $i < $count; $i ++ ) {
219 if ( isset($account_data[$i]['type']) )
220 {
221 echo esc_attr( $account_data[ $i ]['type'] ) . ' - ' . esc_attr( $account_data[ $i ]['credits'] ) . ' ' . esc_attr__( 'credits', 'mailin' ) . '<br>';
222 }
223 }
224 ?>
225 <a class="text-decoration-none" href="<?php echo esc_url( add_query_arg( 'sib_action', 'logout' ) ); ?>"><i class="fa fa-angle-right"></i>&nbsp;<?php esc_attr_e( 'Log out', 'mailin' ); ?></a>
226 </p>
227 </div>
228
229 <span><b><?php esc_attr_e( 'Contacts', 'mailin' ); ?></b></span>
230 </div>
231 <div class="row" style="padding-top: 10px;">
232 <div class="col-md-6">
233 <p style="margin-top: 5px;">
234 <a id="sib_list_link" class="text-decoration-none" href="https://my.sendinblue.com/users/list/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank"><i class="fa fa-angle-right"></i>&nbsp;<?php esc_attr_e( 'Access to the list of all my contacts', 'mailin' ); ?></a>
235 </p>
236 </div>
237 <div class="col-md-6 row">
238 <p class="col-md-7">
239 <b><?php echo esc_attr__( 'Users Synchronisation', 'mailin' ); ?></b><br>
240 <?php echo esc_attr( $desc ); ?><br>
241 </p>
242 <div class="col-md-5">
243 <a <?= '1' === $isEnableSync ? 'id="sib-sync-btn" data-bs-toggle="modal" data-bs-target="#syncUsers"' : 'disabled href="javascript:void(0)"'; ?> class="<?= '1' !== $isEnableSync ? 'disabled not-allowed shadow-none' : ''; ?> btn btn-primary" style="margin-top: 28px; " name="<?php echo esc_attr__( 'Users Synchronisation', 'mailin' ); ?>" href="#"><?php esc_attr_e( 'Sync my users', 'mailin' ); ?></a>
244 </div>
245 </div>
246 </div>
247 </div>
248 </div>
249 <!-- Transactional Email -->
250 <div class="card sib-small-content">
251 <div class="card-header">
252 <strong><?php esc_attr_e( 'Transactional emails', 'mailin' ); ?></strong>
253 </div>
254 <div class="card-body">
255 <?php
256 if ( 'disabled' == $smtp_status ) :
257 ?>
258 <div id="smtp-failure-alert" class="col-md-12 sib_alert alert alert-danger" role="alert"><?php esc_attr_e( 'Unfortunately, your "Transactional emails" are not activated because your Sendinblue SMTP account is not active. Please send an email to contact@sendinblue.com in order to ask for SMTP account activation', 'mailin' ); ?></div>
259 <?php
260 endif;
261 ?>
262 <div id="success-alert" class="col-md-12 sib_alert alert alert-success" role="alert" style="display: none;"><?php esc_attr_e( 'Mail Sent.', 'mailin' ); ?></div>
263 <div id="failure-alert" class="col-md-12 sib_alert alert alert-danger" role="alert" style="display: none;"><?php esc_attr_e( 'Please input valid email.', 'mailin' ); ?></div>
264 <div class="row">
265 <p class="col-md-4 text-left"><?php esc_attr_e( 'Activate email through Sendinblue', 'mailin' ); ?></p>
266 <div class="col-md-3">
267 <label class="col-md-5"><input type="radio" name="activate_email" id="activate_email_radio_yes" value="yes"
268 <?php
269 checked( $home_settings['activate_email'], 'yes' );
270 if ( 'disabled' === $smtp_status ) {
271 echo ' disabled';
272 }
273 ?>
274 >&nbsp;<?php esc_attr_e( 'Yes', 'mailin' ); ?></label>
275 <label class="col-md-5"><input type="radio" name="activate_email" id="activate_email_radio_no" value="no" <?php checked( $home_settings['activate_email'], 'no' ); ?>>&nbsp;<?php esc_attr_e( 'No', 'mailin' ); ?></label>
276 </div>
277 <div class="col-md-5">
278 <small style="font-style: italic;"><?php esc_attr_e( 'Choose "Yes" if you want to use Sendinblue SMTP to send transactional emails', 'mailin' ); ?></small>
279 </div>
280 </div>
281 <div id="email_send_field"
282 <?php
283 if ( 'yes' !== $home_settings['activate_email'] ) {
284 echo 'style="display:none;"';
285 }
286 ?>
287 >
288 <div class="row" style="margin-bottom: 10px;">
289 <p class="col-md-4 text-left"><?php esc_attr_e( 'Choose your sender', 'mailin' ); ?></p>
290 <div class="col-md-3">
291 <select id="sender_list" class="col-md-12">
292 <?php
293 $senders = SIB_API_Manager::get_sender_lists();
294 foreach ( $senders as $sender ) {
295 echo "<option value='" . esc_attr( $sender['id'] ) . "' " . selected( $home_settings['sender'], $sender['id'] ) . '>' . esc_attr( $sender['from_name'] ) . '&nbsp;&lt;' . esc_attr( $sender['from_email'] ) . '&gt;</option>';
296 }
297 ?>
298 </select>
299 </div>
300 <div class="col-md-5">
301 <a class="text-decoration-none" href="https://account.sendinblue.com/senders/" style="font-style: italic;" target="_blank" ><i class="fa fa-angle-right"></i>&nbsp;<?php esc_attr_e( 'Create a new sender', 'mailin' ); ?></a>
302 </div>
303 </div>
304 <div class="row">
305 <p class="col-md-4 text-left"><?php esc_attr_e( 'Enter email to send a test', 'mailin' ); ?></p>
306 <div class="col-md-3">
307 <input id="activate_email" type="email" class="col-md-12">
308 <button type="button" id="send_email_btn" class="col-md-12 btn btn-primary"><span class="sib-spin"><i class="fa fa-circle-o-notch fa-spin fa-lg"></i>&nbsp;&nbsp;</span><?php esc_attr_e( 'Send email', 'mailin' ); ?></button>
309 </div>
310 <div class="col-md-5">
311 <small style="font-style: italic;"><?php esc_attr_e( 'Select here the email address you want to send a test email to.', 'mailin' ); ?></small>
312 </div>
313 </div>
314 </div>
315 </div>
316 </div>
317 <!-- Marketing Automation -->
318 <div class="card sib-small-content">
319 <div class="card-header">
320 <strong><?php esc_attr_e( 'Automation', 'mailin' ); ?></strong>
321 </div>
322 <div class="card-body">
323 <div class="sib-ma-alert sib-ma-active alert alert-success" role="alert" style="display: none;"><?php esc_attr_e( 'Your Marketing Automation script is installed correctly.', 'mailin' ); ?></div>
324 <div class="sib-ma-alert sib-ma-inactive alert alert-danger" role="alert" style="display: none;"><?php esc_attr_e( 'Your Marketing Automation script has been uninstalled', 'mailin' ); ?></div>
325 <div class="sib-ma-alert sib-ma-disabled alert alert-danger" role="alert" style="display: none;"><?php esc_attr_e( 'To activate Marketing Automation, please go to your Sendinblue\'s account or contact us at contact@sendinblue.com', 'mailin' ); ?></div>
326 <input type="hidden" id="sib-ma-unistall" value="<?php esc_attr_e( 'Your Marketing Automation script will be uninstalled, you won\'t have access to any Marketing Automation data and workflows', 'mailin' ); ?>">
327 <div class="row">
328 <p class="col-md-4 text-left"><?php esc_attr_e( 'Activate Marketing Automation through Sendinblue', 'mailin' ); ?></p>
329 <div class="col-md-3">
330 <label class="col-md-5"><input type="radio" name="activate_ma" id="activate_ma_radio_yes" value="yes"
331 <?php
332 checked( $home_settings['activate_ma'], 'yes' );
333 ?>
334 >&nbsp;<?php esc_attr_e( 'Yes', 'mailin' ); ?></label>
335 <label class="col-md-5"><input type="radio" name="activate_ma" id="activate_ma_radio_no" value="no" <?php checked( $home_settings['activate_ma'], 'no' ); ?>>&nbsp;<?php esc_attr_e( 'No', 'mailin' ); ?></label>
336 </div>
337 <div class="col-md-5">
338 <small style="font-style: italic;"><?php esc_attr_e( 'Choose "Yes" if you want to use Sendinblue Automation to track your website activity', 'mailin' ); ?></small>
339 </div>
340 </div>
341 <div class="row" style="">
342 <p class="col-md-4 text-left" style="font-size: 13px; font-style: italic;"><?php printf( esc_attr__( '%s Explore our resource %s to learn more about Sendinblue Automation', 'mailin' ), '<a class="text-decoration-none" href="https://help.sendinblue.com/hc/en-us/articles/208775609/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank">', '</a>' ); ?></p>
343 <div class="col-md-3">
344 <button type="button" id="validate_ma_btn" class="col-md-12 btn btn-primary"><span class="sib-spin"><i class="fa fa-circle-o-notch fa-spin fa-lg"></i>&nbsp;&nbsp;</span><?php esc_attr_e( 'Activate', 'mailin' ); ?></button>
345 </div>
346 <div class="col-md-5">
347 </div>
348 </div>
349 </div>
350 </div>
351
352 </div>
353 <?php
354 }
355
356 /**
357 * Generate a language box on the plugin admin page.
358 */
359 public static function generate_side_bar() {
360 do_action( 'sib_language_sidebar' );
361 ?>
362
363 <div class="card text-left box-border-box sib-small-content">
364 <div class="card-header"><strong><?php esc_attr_e( 'About Sendinblue', 'mailin' ); ?></strong></div>
365 <div class="card-body">
366 <p><?php esc_attr_e( 'Sendinblue is an online software that helps you build and grow relationships through marketing and transactional emails, marketing automation, and text messages.', 'mailin' ); ?></p>
367 <ul class="sib-widget-menu list-group">
368 <li>
369 <a class="text-decoration-none" href="https://www.sendinblue.com/about/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank"><i class="fa fa-angle-right"></i> &nbsp;<?php esc_attr_e( 'Who we are', 'mailin' ); ?></a>
370 </li>
371 <li>
372 <a class="text-decoration-none" href="https://www.sendinblue.com/pricing/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank"><i class="fa fa-angle-right"></i> &nbsp;<?php esc_attr_e( 'Pricing', 'mailin' ); ?></a>
373 </li>
374 <li>
375 <a class="text-decoration-none" href="https://www.sendinblue.com/features/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank"><i class="fa fa-angle-right"></i> &nbsp;<?php esc_attr_e( 'Features', 'mailin' ); ?></a>
376 </li>
377 </ul>
378 </div>
379
380 </div>
381 <div class="card text-left box-border-box sib-small-content">
382 <div class="card-header"><strong><?php esc_attr_e( 'Need Help?', 'mailin' ); ?></strong></div>
383 <div class="card-body">
384 <p><?php esc_attr_e( 'Do you have a question or need more information?', 'mailin' ); ?></p>
385 <ul class="sib-widget-menu list-group">
386 <li><a class="text-decoration-none" href="https://help.sendinblue.com/hc/en-us/sections/202171729/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank"><i class="fa fa-angle-right"></i> &nbsp;<?php esc_attr_e( 'Tutorials', 'mailin' ); ?></a></li>
387 <li><a class="text-decoration-none" href="https://resources.sendinblue.com/category/faq/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank"><i class="fa fa-angle-right"></i> &nbsp;<?php esc_attr_e( 'FAQ', 'mailin' ); ?></a></li>
388 </ul>
389 <hr>
390 </div>
391 </div>
392 <div class="card text-left box-border-box sib-small-content">
393 <div class="card-header"><strong><?php esc_attr_e( 'Recommend this plugin', 'mailin' ); ?></strong></div>
394 <div class="card-body">
395 <p><?php esc_attr_e( 'Let everyone know you like this plugin through a review!' ,'mailin' ); ?></p>
396 <ul class="sib-widget-menu list-group">
397 <li><a class="text-decoration-none" href="http://wordpress.org/support/view/plugin-reviews/mailin" target="_blank"><i class="fa fa-angle-right"></i> &nbsp;<?php esc_attr_e( 'Recommend the Sendinblue plugin', 'mailin' ); ?></a></li>
398 </ul>
399 </div>
400 </div>
401 <?php
402 }
403
404 /**
405 * Get narration script
406 *
407 * @param string $title - pop up title.
408 * @param string $text - pop up content text.
409 */
410 static function get_narration_script( $title, $text ) {
411 ?>
412 <i title="<?php echo esc_attr( $title ); ?>" data-bs-toggle="popover" data-bs-placement="right" data-bs-content="<?php echo esc_attr( $text ); ?>" data-html="true" class="fa fa-question-circle popover-help-form"></i>
413 <?php
414 }
415
416 /** Print disable mode popup */
417 static function print_disable_popup() {
418 ?>
419 <div class="modal fade sib-disable-modal">
420 <div class="modal-dialog">
421 <div class="modal-content">
422 <div class="modal-header">
423 <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true" style="font-size: 22px;">&times;</span><span class="sr-only">Close</span></button>
424 <h4 class="modal-title"><?php esc_attr_e( 'Sendinblue','mailin' ); ?></h4>
425 </div>
426 <div class="modal-body" style="padding: 30px;">
427 <p>
428 <?php esc_attr_e( 'You are currently not logged in. Create an account or log in to benefit from all of Sendinblue\'s features an your WordPress site.', 'mailin' ); ?>
429 </p>
430 <ul>
431 <li> <span class="glyphicon glyphicon-ok" style="font-size: 12px;"></span>&nbsp;&nbsp;<?php esc_attr_e( 'Collect and manage your contacts', 'mailin' ); ?></li>
432 <li> <span class="glyphicon glyphicon-ok" style="font-size: 12px;"></span>&nbsp;&nbsp;<?php esc_attr_e( 'Send transactional emails via SMTP or API', 'mailin' ); ?></li>
433 <li> <span class="glyphicon glyphicon-ok" style="font-size: 12px;"></span>&nbsp;&nbsp;<?php esc_attr_e( 'Real time statistics and email tracking', 'mailin' ); ?></li>
434 <li> <span class="glyphicon glyphicon-ok" style="font-size: 12px;"></span>&nbsp;&nbsp;<?php esc_attr_e( 'Edit and send email marketing', 'mailin' ); ?></li>
435 </ul>
436 <div class="row" style="margin-top: 40px;">
437 <div class="col-md-6">
438 <a href="https://www.sendinblue.com/users/login/" target="_blank"><i><?php esc_attr_e( 'Have an account?', 'mailin' ); ?></i></a>
439 </div>
440 <div class="col-md-6">
441 <a href="https://www.sendinblue.com/users/signup/" target="_blank" class="btn btn-default"><i class="fa fa-angle-double-right"></i>&nbsp;<?php esc_attr_e( 'Free Subscribe Now', 'mailin' ); ?>&nbsp;<i class="fa fa-angle-double-left"></i></a>
442 </div>
443 </div>
444 </div>
445
446 </div><!-- /.modal-content -->
447 </div><!-- /.modal-dialog -->
448 </div><!-- /.modal -->
449 <button id="sib-disable-popup" class="btn btn-primary" data-toggle="modal" data-target=".sib-disable-modal" style="display: none;">sss</button>
450 <script>
451 jQuery(document).ready(function() {
452 jQuery('.sib-disable-modal').modal();
453
454 jQuery('.sib-disable-modal').on('hidden.bs.modal', function() {
455 window.location.href = '<?php echo esc_url( add_query_arg( 'page', 'sib_page_home', admin_url( 'admin.php' ) ) ); ?>';
456 });
457 });
458
459 </script>
460
461 <?php
462 }
463
464 /** Print user sync popup */
465 static function print_sync_popup() {
466 ?>
467 <div class="modal fade sib-sync-modal" id="syncUsers">
468 <div class="modal-dialog">
469 <div class="modal-content">
470 <div class="modal-header">
471 <h5 class="modal-title"><?php esc_attr_e( 'Users Synchronisation','mailin' ); ?></h5>
472 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
473 </div>
474 <div class="modal-body sync-modal-body" style="padding: 10px;">
475 <div id="sync-failure" class="sib_alert alert alert-danger" style="margin-bottom: 0px;display: none;"></div>
476 <form id="sib-sync-form">
477 <!-- roles -->
478 <div class="row sync-row" style="margin-top: 0;">
479 <b><p><?php esc_attr_e( 'Roles to sync', 'mailin' ); ?></p></b>
480 <?php foreach ( wp_roles()->roles as $role_name => $role_info ) : ?>
481 <div class="col-md-6">
482 <span class="" style="display: block;float:left;padding-left: 16px;"><input type="checkbox" id="<?php echo esc_attr( $role_name ); ?>" value="<?php echo esc_attr( $role_name ); ?>" name="sync_role" checked><label for="<?php echo esc_attr( $role_name ); ?>" style="margin: 4px 24px 0 7px;font-weight: normal;"><?php esc_attr_e( ucfirst($role_name), 'mailin' ); ?></label></span>
483 </div>
484 <?php endforeach; ?>
485 </div>
486 <!-- lists -->
487 <?php $lists = SIB_API_Manager::get_lists(); ?>
488 <div class="row sync-row">
489 <b><p><?php esc_attr_e( 'Sync Lists', 'mailin' ); ?></p></b>
490 <div class="row" style="margin-top: 0;">
491 <div class="col-md-6">
492 <p><?php esc_attr_e( 'Choose the Sendinblue list in which you want to add your existing customers:', 'mailin' ); ?></p>
493 </div>
494 <div class="col-md-6">
495 <select data-placeholder="Please select the list" id="sib_select_list" name="list_id" multiple="true">
496 <?php foreach ( $lists as $list ) : ?>
497 <option value="<?php echo esc_attr( $list['id'] ); ?>"><?php echo esc_attr( $list['name'] ); ?></option>
498 <?php endforeach; ?>
499 </select>
500 </div>
501 </div>
502 </div>
503 <!-- Match Attributes -->
504 <?php
505 // available WordPress attributes.
506 $wpAttrs = array(
507 'first_name' => __( 'First Name','mailin' ),
508 'last_name' => __( 'Last Name','mailin' ),
509 'user_url' => __( 'Website URL','mailin' ),
510 'roles' => __( 'User Role','mailin' ),
511 'user_login' => __( 'Username','mailin' ),
512 'nickname' => __( 'Nickname','mailin' ),
513 'user_registered' => __( 'User Registration Date','mailin' ),
514 'display_name' => __( 'Display Name','mailin' ),
515 'description' => __( 'Description about user','mailin' ),
516 );
517 // available sendinblue attributes.
518 $sibAllAttrs = SIB_API_Manager::get_attributes();
519 $sibAttrs = $sibAllAttrs['attributes']['normal_attributes'];
520 ?>
521 <div class="row sync-row" id="sync-attr-area">
522 <b><p><?php esc_attr_e( 'Match Attributes', 'mailin' ); ?></p></b>
523 <div class="row" style="padding: 5px;margin-top: 0;">
524 <div class="row" style="margin-top: 0;">
525 <div class="col-md-6">
526 <p><?php esc_attr_e( 'WordPress Users Attributes', 'mailin' ); ?></p>
527 </div>
528 <div class="col-md-6">
529 <p><?php esc_attr_e( 'Sendinblue Contact Attributes', 'mailin' ); ?></p>
530 </div>
531 </div>
532 </div>
533
534 <div class="col-md-11 sync-attr-line">
535 <div class="row sync-attr" style="padding: 5px;border-top: dotted 1px #dedede;border-bottom: dotted 1px #dedede;margin-top: 0;">
536 <div class="col-md-5">
537 <select class="sync-wp-attr" name="" style="width: 100%;">
538 <?php foreach ( $wpAttrs as $id => $label ) : ?>
539 <option value="<?php echo esc_attr( $id ); ?>"><?php echo esc_attr( $label ); ?></option>
540 <?php endforeach; ?>
541 </select>
542 </div>
543 <div class="col-md-1" style="padding-left: 10px;padding-top: 3px;"><span class="dashicons dashicons-leftright"></span></div>
544 <div class="col-md-5">
545 <select class="sync-sib-attr" name="" style="width: 100%;">
546 <?php foreach ( $sibAttrs as $attr ) : ?>
547 <option value="<?php echo esc_attr( $attr['name'] ); ?>"><?php echo esc_attr( $attr['name'] ); ?></option>
548 <?php endforeach; ?>
549 </select>
550 </div>
551 <div class="col-md-1" style="padding-top: 3px;">
552 <a href="javascript:void(0)" class="sync-attr-dismiss" style="display: none;"><span class="dashicons dashicons-dismiss"></span></a>
553 </div>
554 <input type="hidden" class="sync-match" name="<?php echo esc_attr( $sibAttrs[0]['name'] ); ?>" value="first_name">
555 </div>
556 </div>
557 <div class="col-md-1 sync-attr-plus-col">
558 <div class="row sync-attr-plus">
559 <a href="javascript:void(0)"><span class="dashicons dashicons-plus-alt "></span></a>
560 </div>
561 </div>
562 </div>
563 <!-- Apply button -->
564 <div class="col-md-12 mt-2">
565 <a href="javascript:void(0)" id="sib_sync_users_btn" class="btn btn-primary" style="float: right;"><?php esc_attr_e( 'Apply', 'mailin' ); ?></a>
566 </div>
567 </form>
568 </div>
569 </div><!-- /.modal-content -->
570 </div><!-- /.modal-dialog -->
571 </div><!-- /.modal -->
572 <?php
573 }
574
575 /** Ajax module for validation (Home - welcome) */
576 public static function ajax_validation_process() {
577 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
578 $access_key = isset( $_POST['access_key'] ) ? sanitize_text_field( wp_unslash( $_POST['access_key'] ) ) : '';
579 try {
580 update_option(SIB_Manager::API_KEY_V3_OPTION_NAME, $access_key);
581 $apiClient = new SendinblueApiClient();
582 $response = $apiClient->getAccount();
583 if ( $apiClient->getLastResponseCode() === SendinblueApiClient::RESPONSE_CODE_OK ) {
584 self::processInstallationInfo("login");
585 // create tables for users and forms.
586 SIB_Model_Users::createTable();
587 SIB_Forms::createTable(); // create default form also
588
589 // If the client don't have attributes regarding Double OptIn then we will create these.
590 SIB_API_Manager::create_default_dopt();
591 $message = 'success';
592 } else {
593 delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME);
594 $message = isset($response['code']) ? $response['code'] . ': ' . $response['message'] :'Please input a valid API v3 key';
595 }
596 } catch ( Exception $e ) {
597 $message = $e->getMessage();
598 delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME);
599 } finally {
600 wp_send_json($message);
601 }
602 }
603
604 /** Ajax module to change activate marketing automation option */
605 public static function ajax_validate_ma() {
606 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
607 $main_settings = get_option( SIB_Manager::MAIN_OPTION_NAME );
608 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
609 $ma_key = $main_settings['ma_key'];
610 if ( '' != $ma_key ) {
611 $option_val = isset( $_POST['option_val'] ) ? sanitize_text_field( wp_unslash( $_POST['option_val'] ) ) : 'no';
612 $home_settings['activate_ma'] = $option_val;
613 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
614 wp_send_json( $option_val );
615 } else {
616 $home_settings['activate_ma'] = 'no';
617 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
618 wp_send_json( 'disabled' );
619 }
620 }
621
622 /** Ajax module to change activate email option */
623 public static function ajax_activate_email_change() {
624 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
625 $option_val = isset( $_POST['option_val'] ) ? sanitize_text_field( wp_unslash( $_POST['option_val'] ) ) : 'no';
626 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
627 $home_settings['activate_email'] = $option_val;
628 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
629 wp_send_json( $option_val );
630 }
631
632 /** Ajax module to change sender detail */
633 public static function ajax_sender_change() {
634 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
635 $sender_id = isset( $_POST['sender'] ) ? sanitize_text_field( wp_unslash( $_POST['sender'] ) ) : ''; // sender id.
636 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
637 $home_settings['sender'] = $sender_id;
638 $senders = SIB_API_Manager::get_sender_lists();
639 foreach ( $senders as $sender ) {
640 if ( $sender['id'] == $sender_id ) {
641 $home_settings['from_name'] = $sender['from_name'];
642 $home_settings['from_email'] = $sender['from_email'];
643 }
644 }
645 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
646 wp_send_json( 'success' );
647 }
648
649 /** Ajax module for send a test email */
650 public static function ajax_send_email() {
651 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
652
653 $subject = __( '[Sendinblue SMTP] test email', 'mailin' );
654 // Get sender info.
655 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
656 if ( isset( $home_settings['sender'] ) ) {
657 $fromname = $home_settings['from_name'];
658 $from_email = $home_settings['from_email'];
659 } else {
660 $from_email = __( 'no-reply@sendinblue.com', 'mailin' );
661 $fromname = __( 'Sendinblue', 'mailin' );
662 }
663
664 $from = array( $from_email, $fromname );
665 $email_templates = SIB_API_Manager::get_email_template( 'test' );
666
667 $html = $email_templates['html_content'];
668
669 $html = str_replace( '{title}', $subject, $html );
670
671 $mailin = new SendinblueApiClient();
672
673 $data = [
674 'sender' => [
675 'name' => $fromname,
676 'email' => $from_email,
677 ],
678 'replyTo' => [
679 'email' => $from_email,
680 ],
681 'to' => [
682 [
683 'email' => sanitize_email($_POST['email'])
684 ]
685 ],
686 'subject' => $subject,
687 'htmlContent' => $html
688 ];
689 $mailin->sendEmail( $data );
690
691 wp_send_json( 'success' );
692 }
693
694 /** Ajax module for remove all transient value */
695 public static function ajax_remove_cache() {
696 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
697 wp_send_json( 'success' );
698 }
699
700 /** Ajax module for sync wp users to contact list */
701 public static function ajax_sync_users() {
702 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
703
704 // phpcs:ignore
705 $postData = isset( $_POST['data'] ) ? $_POST['data'] : array();
706
707 if ( ! isset( $postData['sync_role'] ) ) {
708 wp_send_json(
709 array(
710 'code' => 'empty_role',
711 'message' => __( 'Please select a user role.','mailin' ),
712 )
713 );}
714 if ( isset( $postData['errAttr'] ) ) {
715 wp_send_json(
716 array(
717 'code' => 'attr_duplicated',
718 'message' => sprintf( esc_attr__( 'The attribute %s is duplicated. You can select one at a time.','mailin' ), '<b>' . esc_html($postData['errAttr']) . '</b>' ),
719 )
720 );}
721
722 $roles = (array) $postData['sync_role']; // array or string.
723 $listIDs = array_map('intval', (array) $postData['list_id']);
724
725 unset( $postData['sync_role'] );
726 unset( $postData['list_id'] );
727
728 $usersData = 'EMAIL';
729 foreach ( $postData as $attrSibName => $attrWP ) {
730 $usersData .= ';' . sanitize_text_field($attrSibName);
731 }
732
733 // sync users to sendinblue.
734 // create body data like csv.
735 // NAME;SURNAME;EMAIL\nName1;Surname1;example1@example.net\nName2;Surname2;example2@example.net.
736 $contentData = '';
737 $usersCount = 0;
738 foreach ( $roles as $role ) {
739 $users = get_users(
740 array(
741 'role' => sanitize_text_field($role),
742 )
743 );
744 if ( empty( $users ) ) {
745 continue;
746 }
747 $usersCount += count($users);
748 foreach ( $users as $user ) {
749 $userId = $user->ID;
750 $user_info = get_userdata( $userId );
751 $userData = $user_info->user_email;
752 foreach ( $postData as $attrSibName => $attrWP ) {
753 if ( $attrWP == 'roles' )
754 {
755 $userData .= ';' . implode( ', ', $user_info->$attrWP ) ;
756 }
757 else {
758 $userData .= ';' . $user_info->$attrWP;
759 }
760
761 }
762 $contentData .= "\n" . strip_tags($userData);
763 }
764 }
765 if ( '' == $contentData ) {
766 wp_send_json(
767 array(
768 'code' => 'empty_users',
769 'message' => __( 'There is not any user in the roles.','mailin' ),
770 )
771 );}
772
773 $usersData .= $contentData;
774 $result = SIB_API_Manager::sync_users( $usersData, $listIDs );
775 update_option('sib_sync_users', $usersCount);
776 wp_send_json( $result );
777 }
778
779 /** Logout process */
780 function logout() {
781 self::processInstallationInfo("logout");
782 $setting = array();
783 update_option( SIB_Manager::MAIN_OPTION_NAME, $setting );
784 delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME);
785
786 $home_settings = array(
787 'activate_email' => 'no',
788 'activate_ma' => 'no',
789 );
790 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
791
792 // remove sync users option.
793 delete_option( 'sib_sync_users' );
794 // remove all transients.
795 SIB_API_Manager::remove_transients();
796
797 // remove all forms.
798 SIB_Forms::removeAllForms();
799 SIB_Forms_Lang::remove_all_trans();
800
801 wp_safe_redirect( add_query_arg( 'page', self::PAGE_ID, admin_url( 'admin.php' ) ) );
802 exit();
803 }
804
805 public static function processInstallationInfo($action)
806 {
807 global $wp_version;
808
809 if($action == "login")
810 {
811 $apiClient = new SendinblueApiClient();
812
813 $params["partnerName"] = "WORDPRESS";
814 $params["active"] = true;
815 $params["plugin_version"] = SendinblueApiClient::PLUGIN_VERSION;
816 if(!empty($wp_version))
817 {
818 $params["shop_version"] = $wp_version;
819 }
820 $params["shop_url"] = get_home_url();
821 $params["created_at"] = gmdate("Y-m-d\TH:i:s\Z");
822 $params["activated_at"] = gmdate("Y-m-d\TH:i:s\Z");
823 $params["type"] = "sib";
824 $response = $apiClient->createInstallationInfo($params);
825 if ( $apiClient->getLastResponseCode() === SendinblueApiClient::RESPONSE_CODE_CREATED )
826 {
827 if(!empty($response["id"]))
828 {
829 update_option(SIB_Manager::INSTALLATION_ID, $response["id"]);
830 }
831 }
832 }
833 elseif($action == "logout")
834 {
835 $installationId = get_option( SIB_Manager::INSTALLATION_ID );
836 if(!empty($installationId))
837 {
838 $apiClient = new SendinblueApiClient();
839 $params["active"] = false;
840 $params["deactivated_at"] = gmdate("Y-m-d\TH:i:s\Z");
841 $apiClient->updateInstallationInfo($installationId, $params);
842 }
843 }
844 }
845 }
846
847 }
848