PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.3.4
Brevo – Email, SMS, Web Push, Chat, and more. v3.3.4
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 1 year ago page-home.php 8 months ago page-push.php 1 year ago
page-home.php
987 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 global $wp_roles;
40 $wp_roles->add_cap( 'administrator', 'view_custom_menu' );
41 $wp_roles->add_cap( 'editor', 'view_custom_menu' );
42
43 add_menu_page( __( 'Brevo', 'mailin' ), __( 'Brevo', 'mailin' ), 'view_custom_menu', self::PAGE_ID, array( &$this, 'generate' ), SIB_Manager::$plugin_url . '/img/favicon.ico' );
44 $this->page_hook = add_submenu_page( self::PAGE_ID, __( 'Home', 'mailin' ), __( 'Home', 'mailin' ), 'view_custom_menu', self::PAGE_ID, array( &$this, 'generate' ) );
45 add_action( 'load-' . $this->page_hook, array( &$this, 'init' ) );
46 add_action( 'admin_print_scripts-' . $this->page_hook, array( $this, 'enqueue_scripts' ) );
47 add_action( 'admin_print_styles-' . $this->page_hook, array( $this, 'enqueue_styles' ) );
48 }
49
50 /**
51 * Init Process
52 */
53 function Init() {
54 if ( ( isset( $_GET['sib_action'] ) ) && ( 'logout' === sanitize_text_field($_GET['sib_action'] )) ) {
55 $logout_nonce = $_GET['_wpnonce'] ?? null;
56 if( wp_verify_nonce($logout_nonce , 'brevo_logout_url' ) ) {
57 $this->logout();
58 }
59 }
60 }
61
62 /**
63 * Enqueue scripts of plugin
64 */
65 function enqueue_scripts() {
66 wp_enqueue_script( 'sib-admin-js' );
67 wp_enqueue_script( 'sib-bootstrap-js' );
68 wp_enqueue_script( 'sib-chosen-js' );
69 wp_localize_script(
70 'sib-admin-js', 'ajax_sib_object',
71 array(
72 'ajax_url' => admin_url( 'admin-ajax.php' ),
73 'ajax_nonce' => wp_create_nonce( 'ajax_sib_admin_nonce' ),
74 )
75 );
76 }
77
78 /**
79 * Enqueue style sheets of plugin
80 */
81 function enqueue_styles() {
82 wp_enqueue_style( 'sib-admin-css' );
83 wp_enqueue_style( 'sib-bootstrap-css' );
84 wp_enqueue_style( 'sib-chosen-css' );
85 wp_enqueue_style( 'sib-fontawesome-css' );
86 }
87
88 /** Generate page script */
89 function generate() {
90 ?>
91 <div id="wrap" class="wrap box-border-box container-fluid">
92 <svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" fill="currentColor" viewBox="0 0 32 32">
93 <circle cx="16" cy="16" r="16" fill="#0B996E"/>
94 <path fill="#fff" d="M21.002 14.54c.99-.97 1.453-2.089 1.453-3.45 0-2.814-2.07-4.69-5.19-4.69H9.6v20h6.18c4.698 0 8.22-2.874 8.22-6.686 0-2.089-1.081-3.964-2.998-5.174Zm-8.62-5.538h4.573c1.545 0 2.565.877 2.565 2.208 0 1.513-1.329 2.663-4.048 3.54-1.854.574-2.688 1.059-2.997 1.634l-.094.001V9.002Zm3.151 14.796h-3.152v-3.085c0-1.362 1.175-2.693 2.813-3.208 1.453-.484 2.657-.969 3.677-1.482 1.36.787 2.194 2.148 2.194 3.57 0 2.42-2.35 4.205-5.532 4.205Z"/>
95 </svg>
96 <svg xmlns="http://www.w3.org/2000/svg" width="80" height="25" fill="currentColor" viewBox="0 0 90 31">
97 <path fill="#0B996E" d="M73.825 19.012c0-4.037 2.55-6.877 6.175-6.877 3.626 0 6.216 2.838 6.216 6.877s-2.59 6.715-6.216 6.715c-3.626 0-6.175-2.799-6.175-6.715Zm-3.785 0c0 5.957 4.144 10.155 9.96 10.155 5.816 0 10-4.198 10-10.155 0-5.957-4.143-10.314-10-10.314s-9.96 4.278-9.96 10.314ZM50.717 8.937l7.81 19.989h3.665l7.81-19.989h-3.945L60.399 24.37h-.08L54.662 8.937h-3.945Zm-15.18 9.354c.239-3.678 2.67-6.156 5.977-6.156 2.867 0 5.02 1.84 5.338 4.598h-6.614c-2.35 0-3.626.28-4.58 1.56h-.12v-.002Zm-3.784.6c0 5.957 4.183 10.274 9.96 10.274 3.904 0 7.33-1.998 8.804-5.158l-3.187-1.6c-1.115 2.08-3.267 3.319-5.618 3.319-2.83 0-5.379-2.16-5.379-4.238 0-1.08.718-1.56 1.753-1.56h12.63v-1.079c0-5.997-3.825-10.155-9.323-10.155-5.497 0-9.641 4.279-9.641 10.195M20.916 28.924h3.586V16.653c0-2.639 1.632-4.518 3.905-4.518.956 0 1.951.32 2.43.758.36-.96.917-1.918 1.753-2.878-.957-.799-2.59-1.32-4.184-1.32-4.382 0-7.49 3.279-7.49 7.956v12.274-.001Zm-17.33-13.23V5.937h5.896c1.992 0 3.307 1.16 3.307 2.919 0 1.998-1.713 3.518-5.218 4.677-2.39.759-3.466 1.399-3.865 2.16h-.12Zm0 9.794v-4.077c0-1.799 1.514-3.558 3.626-4.238 1.873-.64 3.425-1.28 4.74-1.958 1.754 1.04 2.829 2.837 2.829 4.717 0 3.198-3.028 5.556-7.132 5.556H3.586ZM0 28.926h7.968c6.057 0 10.597-3.798 10.597-8.835 0-2.759-1.393-5.237-3.864-6.836 1.275-1.28 1.873-2.76 1.873-4.559 0-3.717-2.67-6.196-6.693-6.196H0v26.426Z"/>
98 </svg>
99
100 <div class="row">
101 <div id="wrap-left" class="box-border-box col-md-9">
102 <div id="sib-message-box" class="row alert alert-success" style="display: none;">
103 <p id="sib-message-body"></p>
104 </div>
105 <?php
106 if ( SIB_Manager::is_done_validation(false)) {
107 $this->generate_main_content();
108 } else {
109 $this->generate_welcome_content();
110 }
111 ?>
112 </div>
113 <div id="wrap-right-side" class="box-border-box col-md-3">
114 <?php
115 self::generate_side_bar();
116 ?>
117 </div>
118 </div>
119 </div>
120 <?php
121 }
122
123 /** Generate welcome page before validation */
124 function generate_welcome_content() {
125 ?>
126
127 <div id="main-content" class="sib-content">
128 <input type="hidden" id="cur_refer_url" value="<?php echo esc_url( add_query_arg( array( 'page' => 'sib_page_home' ), admin_url( 'admin.php' ) ) ); ?> ">
129 <div class="card sib-small-content">
130 <div class="card-header">
131 <span style="color: #777777;"><?php esc_attr_e( 'Step', 'mailin' ); ?> 1&nbsp;|&nbsp;</span><strong><?php esc_attr_e( 'Create a Brevo Account', 'mailin' ); ?></strong>
132 </div>
133 <div class="card-body">
134 <div class="col-md-9">
135 <p><?php esc_attr_e( 'By creating a free Brevo account, you will be able to send confirmation emails and:', 'mailin' ); ?></p>
136 <ul class="sib-home-feature">
137 <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>
138 <li><span class="glyphicon glyphicon-ok" style="font-size: 12px;"></span>&nbsp;&nbsp;<?php esc_attr_e( 'Use Brevo SMTP to send your transactional emails', 'mailin' ); ?></li>
139 <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>
140 <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>
141 <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.brevo.com/features/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank" rel="noopener"><?php esc_attr_e( 'Brevo\'s features', 'mailin' ); ?></a></li>
142 </ul>
143 <a href="https://www.brevo.com/users/signup?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" class="btn btn-success" target="_blank" rel="noopener" style="margin-top: 10px;"><?php esc_attr_e( 'Create an account', 'mailin' ); ?></a>
144 </div>
145 </div>
146 </div>
147 <div class="card sib-small-content">
148 <div class="card-header">
149 <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>
150 </div>
151 <div class="card-body">
152 <div class="col-md-9 row">
153 <div id="success-alert" class="alert alert-success" role="alert" style="display: none;"><?php esc_attr_e( 'You successfully activate your account.', 'mailin' ); ?></div>
154 <input type="hidden" id="general_error" value="<?php esc_attr_e( 'Please input a valid API v3 key', 'mailin' ); ?>">
155 <input type="hidden" id="curl_no_exist_error" value="<?php esc_attr_e( 'Please install curl on site to use brevo plugin.', 'mailin' ); ?>">
156 <input type="hidden" id="curl_error" value="<?php esc_attr_e( 'Curl error.', 'mailin' ); ?>">
157 <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>
158 <p>
159 <?php esc_attr_e( 'Once you have created a Brevo account, activate this plugin to send all of your transactional emails via Brevo SMTP. Brevo optimizes email delivery to ensure emails reach the inbox.', 'mailin' ); ?><br>
160 <?php esc_attr_e( 'To activate your plugin, enter your API v3 Access key.', 'mailin' ); ?><br>
161 </p>
162 <p>
163 <a href="https://app.brevo.com/settings/keys/api?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank" rel="noopener"><i class="fa fa-angle-right"></i>&nbsp;<?php esc_attr_e( 'Get your API key from your account', 'mailin' ); ?></a>
164 </p>
165 <p>
166 <div class="col-md-7">
167 <p class="col-md-12"><input id="sib_access_key" type="text" class="col-md-10" style="margin-top: 10px;" placeholder="xkeysib-xxxxxx"></p>
168 <p class="col-md-12"><button type="button" id="sib_validate_btn" class="col-md-4 btn btn-success"><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>
169 </div>
170 </p>
171 </div>
172 </div>
173 </div>
174 </div>
175 <?php
176 }
177
178 /** Generate main home page after validation */
179 function generate_main_content() {
180
181 // display account info.
182 $account_settings = SIB_API_Manager::get_account_info();
183 $account_email = $account_settings['account_email'];
184 $account_user_name = isset( $account_settings['account_user_name'] ) ? $account_settings['account_user_name'] : '';
185 $account_data = isset( $account_settings['account_data'] ) ? $account_settings['account_data'] : '';
186 // check smtp available.
187 $smtp_status = SIB_API_Manager::get_smtp_status();
188
189 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
190 $push_activated = SIB_Push_Utils::is_push_active();
191 $contactSyncMessage = SIB_Push_Utils::is_contact_sync_active()
192 ? sprintf(
193 // translators: %1$s: advanced settings, $2%s deactivate push notifications link
194 __( 'To stop creating contacts from push subscribers, %1$s. To disable notifications entirely, %2$s.', 'mailin' ),
195 '<a href="'.add_query_arg( 'page', SIB_Page_Push::PAGE_ID, admin_url( 'admin.php' ) ).'#/settings/advanced" style="font-size:12px;">' . __( 'go to Advanced settings', 'mailin' ) . '</a>',
196 '<a href="#" style="font-size:12px;" id="deactivate_push_btn">' . __( 'turn off Web push', 'mailin' ) . '</a>'
197 )
198 : sprintf(
199 // translators: %1$s: advanced settings, $2%s deactivate push notifications link
200 __( 'To use Brevo segments and lists, enable contact creation from push subscribers %1$s. To stop notifications completely, %2$s.', 'mailin' ),
201 '<a href="'.add_query_arg( 'page', SIB_Page_Push::PAGE_ID, admin_url( 'admin.php' ) ).'#/settings/advanced" style="font-size:12px;">' . __( 'in Advanced settings', 'mailin' ) . '</a>',
202 '<a href="#" style="font-size:12px;" id="deactivate_push_btn">' . __( 'turn off Web push', 'mailin' ) . '</a>'
203 );
204
205 /* printf(
206 ); */
207 $show_push = SIB_Push_Settings::getSettings()->getShowPush();
208 $push_app = null;
209 try { $push_app = SIB_Push_Utils::get_push_application(300); } catch (Exception $e) { }
210
211 $is_ma_active = SIB_Manager::is_ma_active();
212
213 // set default sender info.
214 $senders = SIB_API_Manager::get_sender_lists();
215 if (is_array( $senders) && (!isset( $home_settings['sender'] ) || (count($senders) == 1 && $home_settings['from_email'] != $senders[0]['from_email']))) {
216 $home_settings['sender'] = $senders[0]['id'];
217 $home_settings['from_name'] = $senders[0]['from_name'];
218 $home_settings['from_email'] = $senders[0]['from_email'];
219 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
220 }
221
222 // Users Sync part.
223 $currentUsers = count_users();
224 $isSynced = get_option( 'sib_sync_users', '0' );
225 $isEnableSync = '0';
226 if ( $isSynced != $currentUsers['total_users'] ) {
227 $isEnableSync = '1';
228 /* translators: %s: total users */
229 $desc = sprintf( esc_attr__( 'You have %s existing users. Do you want to add them to Brevo?', 'mailin' ), $currentUsers['total_users'] );
230 self::print_sync_popup();
231 } else {
232 $desc = esc_attr__( 'All your users have been added to a Brevo list.','mailin' );
233 }
234 ?>
235
236 <div id="main-content" class="sib-content">
237 <input type="hidden" id="cur_refer_url" value="<?php echo esc_url( add_query_arg( array( 'page' => 'sib_page_home' ), admin_url( 'admin.php' ) ) ); ?> ">
238 <!-- Account Info -->
239 <div class="card sib-small-content">
240 <div class="card-header">
241 <strong><?php esc_attr_e( 'My Account', 'mailin' ); ?></strong>
242 </div>
243 <div class="card-body">
244 <div class="col-md-12">
245 <span><b><?php esc_attr_e( 'You are currently logged in as : ', 'mailin' ); ?></b></span>
246 <div style="margin-bottom: 10px;">
247 <p class="col-md-12" style="margin-top: 5px;">
248 <?php echo esc_attr( $account_user_name ); ?>&nbsp;-&nbsp;<?php echo esc_attr( $account_email ); ?><br>
249 <?php
250 $count = count( $account_data );
251 for ( $i = 0; $i < $count; $i ++ ) {
252 if ( isset($account_data[$i]['type']) )
253 {
254 echo esc_attr( $account_data[ $i ]['type'] ) . ' - ' . esc_attr( $account_data[ $i ]['credits'] ) . ' ' . esc_attr__( 'credits', 'mailin' ) . '<br>';
255 }
256 }
257 ?>
258 <?php if ($show_push): ?>
259 Web push -
260 <?php
261 $isEnterpriseClient = isset($account_settings['enterprise']) ? $account_settings['enterprise'] : false;
262 $isFreeClient = !empty(array_filter($account_data, function($entry) {
263 return isset($entry['type']) && $entry['type'] === 'free';
264 }));
265 echo $isEnterpriseClient ? esc_attr('unlimited') : '<strong>' . esc_attr('free') . '</strong> '. esc_attr('up to') . ' ' . number_format($isFreeClient ? 10000 : 100000);
266 ?>
267 <?php esc_attr_e( 'subscribers', 'mailin' ); ?><br>
268 <?php endif; ?>
269
270 <a class="text-decoration-none" href="<?php
271 $nonce = wp_create_nonce( 'brevo_logout_url' );
272 echo esc_url(
273 add_query_arg(array(
274 'page' => 'sib_page_home',
275 'sib_action' => 'logout',
276 '_wpnonce' => $nonce
277 ), "")
278 );?>" >
279 <i class="fa fa-angle-right"></i>&nbsp;<?php esc_attr_e( 'Log out', 'mailin' ); ?></a>
280 </p>
281 </div>
282
283 <span><b><?php esc_attr_e( 'Contacts', 'mailin' ); ?></b></span>
284 </div>
285 <div class="row" style="padding-top: 10px;">
286 <div class="col-md-6">
287 <p style="margin-top: 5px;">
288 <a id="sib_list_link" class="text-decoration-none" href="https://app.brevo.com/contact/list/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank" rel="noopener"><i class="fa fa-angle-right"></i>&nbsp;<?php esc_attr_e( 'Access to the list of all my contacts', 'mailin' ); ?></a>
289 </p>
290 </div>
291 <div class="col-md-6 row">
292 <p class="col-md-7">
293 <b><?php echo esc_attr__( 'Users Synchronisation', 'mailin' ); ?></b><br>
294 <?php echo esc_attr( $desc ); ?><br>
295 </p>
296 <div class="col-md-5">
297 <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-success" style="margin-top: 28px; " name="<?php echo esc_attr__( 'Users Synchronisation', 'mailin' ); ?>" href="#"><?php esc_attr_e( 'Sync my users', 'mailin' ); ?></a>
298 </div>
299 </div>
300 </div>
301 </div>
302 </div>
303 <!-- Transactional Email -->
304 <div class="card sib-small-content">
305 <div class="card-header">
306 <strong><?php esc_attr_e( 'Transactional emails', 'mailin' ); ?></strong>
307 </div>
308 <div class="card-body">
309 <?php
310 if ( 'disabled' == $smtp_status ) :
311 ?>
312 <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 Brevo SMTP account is not active. Please send an email to contact@brevo.com in order to ask for SMTP account activation', 'mailin' ); ?></div>
313 <?php
314 endif;
315 ?>
316 <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>
317 <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>
318 <div class="row">
319 <p class="col-md-4 text-left"><?php esc_attr_e( 'Activate email through Brevo', 'mailin' ); ?></p>
320 <div class="col-md-3">
321 <label class="col-md-5"><input type="radio" name="activate_email" id="activate_email_radio_yes" value="yes"
322 <?php
323 checked( $home_settings['activate_email'], 'yes' );
324 if ( 'disabled' === $smtp_status ) {
325 echo ' disabled';
326 }
327 ?>
328 >&nbsp;<?php esc_attr_e( 'Yes', 'mailin' ); ?></label>
329 <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>
330 </div>
331 <div class="col-md-5">
332 <small style="font-style: italic;"><?php esc_attr_e( 'Choose "Yes" if you want to use Brevo SMTP to send transactional emails', 'mailin' ); ?></small>
333 </div>
334 </div>
335 <div id="email_send_field"
336 <?php
337 if ( 'yes' !== $home_settings['activate_email'] ) {
338 echo 'style="display:none;"';
339 }
340 ?>
341 >
342 <div class="row" style="margin-bottom: 10px;">
343 <p class="col-md-4 text-left"><?php esc_attr_e( 'Choose your sender', 'mailin' ); ?></p>
344 <div class="col-md-3">
345 <select id="sender_list" class="col-md-12">
346 <?php
347 $senders = SIB_API_Manager::get_sender_lists();
348 foreach ( $senders as $sender ) {
349 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>';
350 }
351 ?>
352 </select>
353 </div>
354 <div class="col-md-5">
355 <a class="text-decoration-none" href="https://app.brevo.com/senders/" style="font-style: italic;" target="_blank" rel="noopener" ><i class="fa fa-angle-right"></i>&nbsp;<?php esc_attr_e( 'Create a new sender', 'mailin' ); ?></a>
356 </div>
357 </div>
358 <div class="row">
359 <p class="col-md-4 text-left"><?php esc_attr_e( 'Enter email to send a test', 'mailin' ); ?></p>
360 <div class="col-md-3">
361 <input id="activate_email" type="email" class="col-md-12">
362 <button type="button" id="send_email_btn" class="col-md-12 btn btn-success"><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>
363 </div>
364 <div class="col-md-5">
365 <small style="font-style: italic;"><?php esc_attr_e( 'Select here the email address you want to send a test email to.', 'mailin' ); ?></small>
366 </div>
367 </div>
368 </div>
369 </div>
370 </div>
371 <!-- Marketing Automation -->
372 <div class="card sib-small-content">
373 <div class="card-header">
374 <strong><?php esc_attr_e( 'Automation', 'mailin' ); ?></strong>
375 </div>
376 <div class="card-body">
377 <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>
378 <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>
379 <div class="sib-ma-alert sib-ma-disabled alert alert-danger" role="alert" style="display: none;"><?php esc_attr_e( 'Brevo Automation could not be activated. Please click ', 'mailin' ); ?><a href="https://app.brevo.com/automation/onboarding" target="_blank" rel="noopener"><?php esc_attr_e( 'here', 'mailin' ); ?></a><?php esc_attr_e( ' to complete activation', 'mailin' ); ?></div>
380 <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' ); ?>">
381 <div class="row">
382 <p class="col-md-4 text-left"><?php esc_attr_e( 'Activate Marketing Automation through Brevo', 'mailin' ); ?></p>
383 <div class="col-md-3">
384 <label class="col-md-5"><input type="radio" name="activate_ma" id="activate_ma_radio_yes" value="yes"
385 <?php
386 checked( true, $is_ma_active );
387 ?>
388 >&nbsp;<?php esc_attr_e( 'Yes', 'mailin' ); ?></label>
389 <label class="col-md-5"><input type="radio" name="activate_ma" id="activate_ma_radio_no" value="no" <?php
390 checked( false, $is_ma_active ); ?>>&nbsp;<?php esc_attr_e( 'No', 'mailin' ); ?></label>
391 </div>
392 <div class="col-md-5">
393 <small style="font-style: italic;"><?php esc_attr_e( 'Choose "Yes" if you want to use Brevo Automation to track your website activity', 'mailin' ); ?></small>
394 </div>
395 </div>
396 <div class="row" style="">
397 <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 Brevo Automation', 'mailin' ), '<a class="text-decoration-none" href="https://help.brevo.com/hc/en-us/articles/208775609/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank" rel="noopener">', '</a>' ); ?></p>
398 <div class="col-md-3">
399 <button type="button" id="validate_ma_btn" class="col-md-12 btn btn-success"><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>
400 </div>
401 <div class="col-md-5">
402 </div>
403 </div>
404 </div>
405 </div>
406 <?php if ($show_push): ?>
407 <!-- Push notifications -->
408 <div class="card sib-small-content">
409 <div class="card-header">
410 <strong><?php esc_attr_e( 'Web push', 'mailin' ); ?></strong>
411 </div>
412 <div class="card-body">
413 <?php if ( $push_activated && $push_app ) : ?>
414 <div class="row">
415 <div class="col-sm-12 text-left">
416 </div>
417 </div>
418 <div class="row">
419 <p class="col-md-4 text-left">
420 <?php
421 // translators: %s: number of subscribers
422 printf( esc_html( _n( 'Web push is currently active, you have %s subscriber.', 'Push is currently active, you have %s subscribers.', $push_app->getSubscribers(), 'mailin' ) ), number_format_i18n( $push_app->getSubscribers() ) ); ?>
423 </p>
424 <div class="col-md-3">
425 <a href="<?php echo add_query_arg( 'page', SIB_Page_Push::PAGE_ID, admin_url( 'admin.php' ) ) ?>"
426 class="col-md-12 btn btn-success"><?php esc_attr_e( 'Web push dashboard', 'mailin' ); ?></a>
427 </div>
428 <div class="col-md-5">
429 <small style="font-style: italic;">
430 <?php echo $contactSyncMessage; ?>
431 </small>
432 <span style="display: none" id="deactivate_push_content"><?php _e("Warning: Deactivating push will stop new subscriptions and prevent notifications from being sent. To stop creating contacts without disabling push, click 'Cancel' and go to Advanced Settings. Are you sure you want to deactivate push?", 'mailin') ?></span>
433 </div>
434 </div>
435 <?php else : ?>
436 <div class="row">
437 <p class="col-md-4 text-left"><?php esc_attr_e( 'Activate web push', 'mailin' ); ?></p>
438 <div class="col-md-3">
439 <button type="button" id="activate_push_btn" class="col-md-12 btn btn-success"><span
440 class="sib-spin"><i class="fa fa-circle-o-notch fa-spin fa-lg"></i>&nbsp;&nbsp;</span><?php esc_attr_e( 'Activate', 'mailin' ); ?>
441 </button>
442 <small id="sib-push-activation-message" style="display: none">
443 <br/>
444 <?php esc_attr_e( 'Please wait, activation might take up to a minute.', 'mailin' ); ?>
445 </small>
446 </div>
447 <div class="col-md-5">
448 <!-- NOTE: deactivate woocommerce-->
449 <!-- <small style="font-style: italic;">--><?php //esc_attr_e( 'Click "Activate" to start notifying your readers whenever a new post is published, let your users subscribe to their favorite topics, or set up automated e-commerce notifications for your WooCommerce business.', 'mailin' ); ?><!--</small>-->
450 <small style="font-style: italic;"><?php esc_attr_e( 'Click "Activate" to start notifying your readers whenever a new post is published, let your users subscribe to their favorite topics.', 'mailin' ); ?></small>
451 </div>
452 </div>
453 <?php endif ?>
454 </div>
455 </div>
456 <?php endif; ?>
457 <div class="card sib-small-content">
458 <div class="card-header">
459 <strong><?php esc_attr_e( 'SMS', 'mailin' ); ?></strong>
460 </div>
461 <div class="card-body">
462 <div class="row">
463 <div class="col-sm-12 text-left">
464 </div>
465 </div>
466 <div class="row">
467 <p class="col-md-4 text-left">
468 <?php
469 // translators: %s: number of subscribers
470 esc_html( _e( 'SMS statistics', 'mailin' ) ) ?>
471 </p>
472 <div class="col-md-3">
473 <a href="https://my.brevo.com/camp/message/stats/sms?utm_medium=plugin&utm_source=wordpress_plugin&utm_campaign=sms_stats"
474 class="col-md-12 btn btn-success"><?php esc_attr_e( 'SMS dashboard', 'mailin' ); ?></a>
475 </div>
476 <div class="col-md-5">
477 <small style="font-style: italic;">
478 <?php _e('Check your SMS campaign statistics, you can see more here:', 'mailin') ?>
479 <a href="https://help.brevo.com/hc/en-us/articles/4439515713810-Analyze-and-export-your-SMS-campaign-report"><?php _e('Learn about SMS statistics', 'mailin') ?></a>
480 </small>
481 </div>
482 </div>
483 </div>
484 </div>
485 </div>
486 <?php
487 }
488
489 /**
490 * Generate a language box on the plugin admin page.
491 */
492 public static function generate_side_bar() {
493 do_action( 'sib_language_sidebar' );
494 ?>
495
496 <div class="card text-left box-border-box sib-small-content">
497 <div class="card-header"><strong><?php esc_attr_e( 'About Brevo', 'mailin' ); ?></strong></div>
498 <div class="card-body">
499 <p><?php esc_attr_e( 'Brevo is an online software that helps you build and grow relationships through marketing and transactional emails, marketing automation, and text messages.', 'mailin' ); ?></p>
500 <ul class="sib-widget-menu list-group">
501 <li>
502 <a class="text-decoration-none" href="https://www.brevo.com/about/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank" rel="noopener"><i class="fa fa-angle-right"></i> &nbsp;<?php esc_attr_e( 'Who we are', 'mailin' ); ?></a>
503 </li>
504 <li>
505 <a class="text-decoration-none" href="https://www.brevo.com/pricing/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank" rel="noopener"><i class="fa fa-angle-right"></i> &nbsp;<?php esc_attr_e( 'Pricing', 'mailin' ); ?></a>
506 </li>
507 <li>
508 <a class="text-decoration-none" href="https://www.brevo.com/features/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank" rel="noopener"><i class="fa fa-angle-right"></i> &nbsp;<?php esc_attr_e( 'Features', 'mailin' ); ?></a>
509 </li>
510 </ul>
511 </div>
512
513 </div>
514 <div class="card text-left box-border-box sib-small-content">
515 <div class="card-header"><strong><?php esc_attr_e( 'Need Help?', 'mailin' ); ?></strong></div>
516 <div class="card-body">
517 <p><?php esc_attr_e( 'Do you have a question or need more information?', 'mailin' ); ?></p>
518 <ul class="sib-widget-menu list-group">
519 <li><a class="text-decoration-none" href="https://help.brevo.com/hc/en-us/sections/202171729/?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank" rel="noopener"><i class="fa fa-angle-right"></i> &nbsp;<?php esc_attr_e( 'Tutorials', 'mailin' ); ?></a></li>
520 <li><a class="text-decoration-none" href="https://help.brevo.com/hc/en-us?utm_source=wordpress_plugin&utm_medium=plugin&utm_campaign=module_link" target="_blank" rel="noopener"><i class="fa fa-angle-right"></i> &nbsp;<?php esc_attr_e( 'FAQ', 'mailin' ); ?></a></li>
521 </ul>
522 <hr>
523 </div>
524 </div>
525 <div class="card text-left box-border-box sib-small-content">
526 <div class="card-header"><strong><?php esc_attr_e( 'Recommend this plugin', 'mailin' ); ?></strong></div>
527 <div class="card-body">
528 <p><?php esc_attr_e( 'Let everyone know you like this plugin through a review!' ,'mailin' ); ?></p>
529 <ul class="sib-widget-menu list-group">
530 <li><a class="text-decoration-none" href="http://wordpress.org/support/view/plugin-reviews/mailin" target="_blank" rel="noopener"><i class="fa fa-angle-right"></i> &nbsp;<?php esc_attr_e( 'Recommend the Brevo plugin', 'mailin' ); ?></a></li>
531 </ul>
532 </div>
533 </div>
534 <?php
535 }
536
537 /**
538 * Get narration script
539 *
540 * @param string $title - pop up title.
541 * @param string $text - pop up content text.
542 */
543 static function get_narration_script( $title, $text ) {
544 ?>
545 <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>
546 <?php
547 }
548
549 /** Print disable mode popup */
550 static function print_disable_popup() {
551 ?>
552 <div class="modal fade sib-disable-modal">
553 <div class="modal-dialog">
554 <div class="modal-content">
555 <div class="modal-header">
556 <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>
557 <h4 class="modal-title"><?php esc_attr_e( 'Brevo','mailin' ); ?></h4>
558 </div>
559 <div class="modal-body" style="padding: 30px;">
560 <p>
561 <?php esc_attr_e( 'You are currently not logged in. Create an account or log in to benefit from all of Brevo\'s features an your WordPress site.', 'mailin' ); ?>
562 </p>
563 <ul>
564 <li> <span class="glyphicon glyphicon-ok" style="font-size: 12px;"></span>&nbsp;&nbsp;<?php esc_attr_e( 'Collect and manage your contacts', 'mailin' ); ?></li>
565 <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>
566 <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>
567 <li> <span class="glyphicon glyphicon-ok" style="font-size: 12px;"></span>&nbsp;&nbsp;<?php esc_attr_e( 'Edit and send email marketing', 'mailin' ); ?></li>
568 </ul>
569 <div class="row" style="margin-top: 40px;">
570 <div class="col-md-6">
571 <a href="https://www.brevo.com/users/login/" target="_blank" rel="noopener"><i><?php esc_attr_e( 'Have an account?', 'mailin' ); ?></i></a>
572 </div>
573 <div class="col-md-6">
574 <a href="https://www.brevo.com/users/signup/" target="_blank" rel="noopener" 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>
575 </div>
576 </div>
577 </div>
578
579 </div><!-- /.modal-content -->
580 </div><!-- /.modal-dialog -->
581 </div><!-- /.modal -->
582 <button id="sib-disable-popup" class="btn btn-success" data-toggle="modal" data-target=".sib-disable-modal" style="display: none;">sss</button>
583 <script>
584 jQuery(document).ready(function() {
585 jQuery('.sib-disable-modal').modal();
586
587 jQuery('.sib-disable-modal').on('hidden.bs.modal', function() {
588 window.location.href = '<?php echo esc_url( add_query_arg( 'page', 'sib_page_home', admin_url( 'admin.php' ) ) ); ?>';
589 });
590 });
591
592 </script>
593
594 <?php
595 }
596
597 /** Print user sync popup */
598 static function print_sync_popup() {
599 ?>
600 <div class="modal fade sib-sync-modal" id="syncUsers">
601 <div class="modal-dialog">
602 <div class="modal-content">
603 <div class="modal-header">
604 <h5 class="modal-title"><?php esc_attr_e( 'Users Synchronisation','mailin' ); ?></h5>
605 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
606 </div>
607 <div class="modal-body sync-modal-body" style="padding: 10px;">
608 <div id="sync-failure" class="sib_alert alert alert-danger" style="margin-bottom: 0px;display: none;"></div>
609 <form id="sib-sync-form">
610 <!-- roles -->
611 <div class="row sync-row" style="margin-top: 0;">
612 <b><p><?php esc_attr_e( 'Roles to sync', 'mailin' ); ?></p></b>
613 <?php foreach ( wp_roles()->roles as $role_name => $role_info ) : ?>
614 <div class="col-md-6">
615 <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>
616 </div>
617 <?php endforeach; ?>
618 </div>
619 <!-- lists -->
620 <?php $lists = SIB_API_Manager::get_lists(); ?>
621 <div class="row sync-row">
622 <b><p><?php esc_attr_e( 'Sync Lists', 'mailin' ); ?></p></b>
623 <div class="row" style="margin-top: 0;">
624 <div class="col-md-6">
625 <p><?php esc_attr_e( 'Choose the Brevo list in which you want to add your existing customers:', 'mailin' ); ?></p>
626 </div>
627 <div class="col-md-6">
628 <select data-placeholder="Please select the list" id="sib_select_list" name="list_id" multiple="true">
629 <?php foreach ( $lists as $list ) : ?>
630 <option value="<?php echo esc_attr( $list['id'] ); ?>"><?php echo esc_attr( $list['name'] ); ?></option>
631 <?php endforeach; ?>
632 </select>
633 </div>
634 </div>
635 </div>
636 <!-- Match Attributes -->
637 <?php
638 // available WordPress attributes.
639 $wpAttrs = array(
640 'first_name' => __( 'First Name','mailin' ),
641 'last_name' => __( 'Last Name','mailin' ),
642 'user_url' => __( 'Website URL','mailin' ),
643 'roles' => __( 'User Role','mailin' ),
644 'user_login' => __( 'Username','mailin' ),
645 'nickname' => __( 'Nickname','mailin' ),
646 'user_registered' => __( 'User Registration Date','mailin' ),
647 'display_name' => __( 'Display Name','mailin' ),
648 'description' => __( 'Description about user','mailin' ),
649 );
650 // available sendinblue attributes.
651 $sibAllAttrs = SIB_API_Manager::get_attributes();
652 $sibAttrs = $sibAllAttrs['attributes']['normal_attributes'];
653 ?>
654 <div class="row sync-row" id="sync-attr-area">
655 <b><p><?php esc_attr_e( 'Match Attributes', 'mailin' ); ?></p></b>
656 <div class="row" style="padding: 5px;margin-top: 0;">
657 <div class="row" style="margin-top: 0;">
658 <div class="col-md-6">
659 <p><?php esc_attr_e( 'WordPress Users Attributes', 'mailin' ); ?></p>
660 </div>
661 <div class="col-md-6">
662 <p><?php esc_attr_e( 'Brevo Contact Attributes', 'mailin' ); ?></p>
663 </div>
664 </div>
665 </div>
666
667 <div class="col-md-11 sync-attr-line">
668 <div class="row sync-attr" style="padding: 5px;border-top: dotted 1px #dedede;border-bottom: dotted 1px #dedede;margin-top: 0;">
669 <div class="col-md-5">
670 <select class="sync-wp-attr" name="" style="width: 100%;">
671 <?php foreach ( $wpAttrs as $id => $label ) : ?>
672 <option value="<?php echo esc_attr( $id ); ?>"><?php echo esc_attr( $label ); ?></option>
673 <?php endforeach; ?>
674 </select>
675 </div>
676 <div class="col-md-1" style="padding-left: 10px;padding-top: 3px;"><span class="dashicons dashicons-leftright"></span></div>
677 <div class="col-md-5">
678 <select class="sync-sib-attr" name="" style="width: 100%;">
679 <?php foreach ( $sibAttrs as $attr ) : ?>
680 <option value="<?php echo esc_attr( $attr['name'] ); ?>"><?php echo esc_attr( $attr['name'] ); ?></option>
681 <?php endforeach; ?>
682 </select>
683 </div>
684 <div class="col-md-1" style="padding-top: 3px;">
685 <a href="javascript:void(0)" class="sync-attr-dismiss" style="display: none;"><span class="dashicons dashicons-dismiss"></span></a>
686 </div>
687 <input type="hidden" class="sync-match" name="<?php echo esc_attr( $sibAttrs[0]['name'] ); ?>" value="first_name">
688 </div>
689 </div>
690 <div class="col-md-1 sync-attr-plus-col">
691 <div class="row sync-attr-plus">
692 <a href="javascript:void(0)"><span class="dashicons dashicons-plus-alt "></span></a>
693 </div>
694 </div>
695 </div>
696 <!-- Apply button -->
697 <div class="col-md-12 mt-2">
698 <a href="javascript:void(0)" id="sib_sync_users_btn" class="btn btn-success" style="float: right;"><?php esc_attr_e( 'Apply', 'mailin' ); ?></a>
699 </div>
700 </form>
701 </div>
702 </div><!-- /.modal-content -->
703 </div><!-- /.modal-dialog -->
704 </div><!-- /.modal -->
705 <?php
706 }
707
708 /** Ajax module for validation (Home - welcome) */
709 public static function ajax_validation_process() {
710 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
711 $access_key = isset( $_POST['access_key'] ) ? sanitize_text_field( wp_unslash( $_POST['access_key'] ) ) : '';
712 try {
713 update_option(SIB_Manager::API_KEY_V3_OPTION_NAME, $access_key);
714 $apiClient = new SendinblueApiClient();
715 $response = $apiClient->getAccount();
716 if ( $apiClient->getLastResponseCode() === SendinblueApiClient::RESPONSE_CODE_OK ) {
717 self::processInstallationInfo("login");
718 // create tables for users and forms.
719 SIB_Model_Users::createTable();
720 SIB_Forms::createTable(); // create default form also
721
722 // If the client don't have attributes regarding Double OptIn then we will create these.
723 SIB_API_Manager::create_default_dopt();
724 $message = 'success';
725 } else {
726 delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME);
727 $message = isset($response['code']) ? $response['code'] . ': ' . $response['message'] :'Please input a valid API v3 key';
728 }
729 } catch ( Exception $e ) {
730 $message = $e->getMessage();
731 delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME);
732 } finally {
733 wp_send_json($message);
734 }
735 }
736
737 /** Ajax module to change activate marketing automation option */
738 public static function ajax_validate_ma() {
739 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
740 $general_settings = get_option( SIB_Manager::MAIN_OPTION_NAME, array() );
741 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
742 $ma_key = isset( $general_settings['ma_key'] ) ? sanitize_text_field($general_settings['ma_key']) : null;
743 if ( $ma_key !== null && strlen($ma_key) > 0 ) {
744 $option_val = isset( $_POST['option_val'] ) ? sanitize_text_field( wp_unslash( $_POST['option_val'] ) ) : 'no';
745 $home_settings['activate_ma'] = $option_val;
746 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
747 wp_send_json( $option_val );
748 } else {
749 $home_settings['activate_ma'] = 'default';
750 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
751 wp_send_json( 'disabled' );
752 }
753 }
754
755 /** Ajax module to change activate email option */
756 public static function ajax_activate_email_change() {
757 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
758 $option_val = isset( $_POST['option_val'] ) ? sanitize_text_field( wp_unslash( $_POST['option_val'] ) ) : 'no';
759 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
760 $home_settings['activate_email'] = $option_val;
761 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
762 wp_send_json( $option_val );
763 }
764
765 /** Ajax module to change sender detail */
766 public static function ajax_sender_change() {
767 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
768 $sender_id = isset( $_POST['sender'] ) ? sanitize_text_field( wp_unslash( $_POST['sender'] ) ) : ''; // sender id.
769 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
770 $home_settings['sender'] = $sender_id;
771 $senders = SIB_API_Manager::get_sender_lists();
772 foreach ( $senders as $sender ) {
773 if ( $sender['id'] == $sender_id ) {
774 $home_settings['from_name'] = $sender['from_name'];
775 $home_settings['from_email'] = $sender['from_email'];
776 }
777 }
778 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
779 wp_send_json( 'success' );
780 }
781
782 /** Ajax module for send a test email */
783 public static function ajax_send_email() {
784 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
785
786 $subject = __( '[Brevo SMTP] test email', 'mailin' );
787 // Get sender info.
788 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
789 if ( isset( $home_settings['sender'] ) ) {
790 $fromname = $home_settings['from_name'];
791 $from_email = $home_settings['from_email'];
792 } else {
793 $from_email = __( 'no-reply@' . parse_url(get_site_url(), PHP_URL_HOST), 'mailin' );
794 $fromname = __( 'Brevo', 'mailin' );
795 }
796
797 $from = array( $from_email, $fromname );
798 $email_templates = SIB_API_Manager::get_email_template( 'test' );
799
800 $html = $email_templates['html_content'];
801
802 $html = str_replace( '{title}', $subject, $html );
803
804 $mailin = new SendinblueApiClient();
805
806 $data = [
807 'sender' => [
808 'name' => $fromname,
809 'email' => $from_email,
810 ],
811 'replyTo' => [
812 'email' => $from_email,
813 ],
814 'to' => [
815 [
816 'email' => sanitize_email($_POST['email'])
817 ]
818 ],
819 'subject' => $subject,
820 'htmlContent' => $html
821 ];
822 $mailin->sendEmail( $data );
823
824 wp_send_json( 'success' );
825 }
826
827 /** Ajax module for remove all transient value */
828 public static function ajax_remove_cache() {
829 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
830 wp_send_json( 'success' );
831 }
832
833 /** Ajax module for sync wp users to contact list */
834 public static function ajax_sync_users() {
835 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
836
837 // phpcs:ignore
838 $postData = isset( $_POST['data'] ) ? $_POST['data'] : array();
839
840 if ( ! isset( $postData['sync_role'] ) ) {
841 wp_send_json(
842 array(
843 'code' => 'empty_role',
844 'message' => __( 'Please select a user role.','mailin' ),
845 )
846 );}
847 if ( isset( $postData['errAttr'] ) ) {
848 wp_send_json(
849 array(
850 'code' => 'attr_duplicated',
851 'message' => sprintf( esc_attr__( 'The attribute %s is duplicated. You can select one at a time.','mailin' ), '<b>' . esc_html($postData['errAttr']) . '</b>' ),
852 )
853 );}
854
855 $roles = (array) $postData['sync_role']; // array or string.
856 $listIDs = array_map('intval', (array) $postData['list_id']);
857
858 unset( $postData['sync_role'] );
859 unset( $postData['list_id'] );
860
861 $usersData = 'EMAIL';
862 foreach ( $postData as $attrSibName => $attrWP ) {
863 $usersData .= ';' . sanitize_text_field($attrSibName);
864 }
865
866 // sync users to sendinblue.
867 // create body data like csv.
868 // NAME;SURNAME;EMAIL\nName1;Surname1;example1@example.net\nName2;Surname2;example2@example.net.
869 $contentData = '';
870 $usersCount = 0;
871 foreach ( $roles as $role ) {
872 $users = get_users(
873 array(
874 'role' => sanitize_text_field($role),
875 )
876 );
877 if ( empty( $users ) ) {
878 continue;
879 }
880 $usersCount += count($users);
881 foreach ( $users as $user ) {
882 $userId = $user->ID;
883 $user_info = get_userdata( $userId );
884 $userData = $user_info->user_email;
885 foreach ( $postData as $attrSibName => $attrWP ) {
886 if ( $attrWP == 'roles' )
887 {
888 $userData .= ';' . implode( ', ', $user_info->$attrWP ) ;
889 }
890 else {
891 $userData .= ';' . $user_info->$attrWP;
892 }
893
894 }
895 $contentData .= "\n" . strip_tags($userData);
896 }
897 }
898 if ( '' == $contentData ) {
899 wp_send_json(
900 array(
901 'code' => 'empty_users',
902 'message' => __( 'There is not any user in the roles.','mailin' ),
903 )
904 );}
905
906 $usersData .= $contentData;
907 $result = SIB_API_Manager::sync_users( $usersData, $listIDs );
908 update_option('sib_sync_users', $usersCount);
909 wp_send_json( $result );
910 }
911
912 /** Logout process */
913 function logout() {
914 self::processInstallationInfo("logout");
915 $setting = array();
916 update_option( SIB_Manager::MAIN_OPTION_NAME, $setting );
917 delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME);
918
919 $home_settings = array(
920 'activate_email' => 'no',
921 'activate_ma' => 'default',
922 );
923 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
924
925 // remove sync users option.
926 delete_option( 'sib_sync_users' );
927 // remove all transients.
928 SIB_API_Manager::remove_transients();
929
930 // remove all forms.
931 SIB_Forms::removeAllForms();
932 SIB_Forms_Lang::remove_all_trans();
933
934 // Clear push settings
935 SIB_Push_Settings::clearAllSettings();
936
937 wp_safe_redirect( add_query_arg( 'page', self::PAGE_ID, admin_url( 'admin.php' ) ) );
938 exit();
939 }
940
941 public static function processInstallationInfo($action)
942 {
943 global $wp_version;
944
945 if($action == "login")
946 {
947 $apiClient = new SendinblueApiClient();
948
949 $params["partnerName"] = "WORDPRESS";
950 $params["active"] = true;
951 $params["connection"] = 27;
952 $params["plugin_version"] = SendinblueApiClient::PLUGIN_VERSION;
953 if(!empty($wp_version))
954 {
955 $params["shop_version"] = $wp_version;
956 }
957 $params["shop_url"] = get_home_url();
958 $params["created_at"] = gmdate("Y-m-d\TH:i:s\Z");
959 $params["activated_at"] = gmdate("Y-m-d\TH:i:s\Z");
960 $params["type"] = "sib";
961 $response = $apiClient->createInstallationInfo($params);
962 if ( $apiClient->getLastResponseCode() === SendinblueApiClient::RESPONSE_CODE_CREATED )
963 {
964 if(!empty($response["id"]))
965 {
966 update_option(SIB_Manager::INSTALLATION_ID, $response["id"]);
967 }
968 }
969 }
970 elseif($action == "logout")
971 {
972 $installationId = get_option( SIB_Manager::INSTALLATION_ID );
973 if(!empty($installationId))
974 {
975 $apiClient = new SendinblueApiClient();
976 $params["active"] = false;
977 $params["deactivated_at"] = gmdate("Y-m-d\TH:i:s\Z");
978 $params["connection"] = 27;
979 $params["plugin_version"] = SendinblueApiClient::PLUGIN_VERSION;
980 $apiClient->updateInstallationInfo($installationId, $params);
981 }
982 }
983 }
984 }
985
986 }
987