PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.2.3
Brevo – Email, SMS, Web Push, Chat, and more. v3.2.3
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 1 year ago page-push.php 1 year ago
page-home.php
974 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 $show_push = SIB_Push_Settings::getSettings()->getShowPush();
192 $push_app = null;
193 try { $push_app = SIB_Push_Utils::get_push_application(300); } catch (Exception $e) { }
194
195 $is_ma_active = SIB_Manager::is_ma_active();
196
197 // set default sender info.
198 $senders = SIB_API_Manager::get_sender_lists();
199 if (is_array( $senders) && (!isset( $home_settings['sender'] ) || (count($senders) == 1 && $home_settings['from_email'] != $senders[0]['from_email']))) {
200 $home_settings['sender'] = $senders[0]['id'];
201 $home_settings['from_name'] = $senders[0]['from_name'];
202 $home_settings['from_email'] = $senders[0]['from_email'];
203 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
204 }
205
206 // Users Sync part.
207 $currentUsers = count_users();
208 $isSynced = get_option( 'sib_sync_users', '0' );
209 $isEnableSync = '0';
210 if ( $isSynced != $currentUsers['total_users'] ) {
211 $isEnableSync = '1';
212 /* translators: %s: total users */
213 $desc = sprintf( esc_attr__( 'You have %s existing users. Do you want to add them to Brevo?', 'mailin' ), $currentUsers['total_users'] );
214 self::print_sync_popup();
215 } else {
216 $desc = esc_attr__( 'All your users have been added to a Brevo list.','mailin' );
217 }
218 ?>
219
220 <div id="main-content" class="sib-content">
221 <input type="hidden" id="cur_refer_url" value="<?php echo esc_url( add_query_arg( array( 'page' => 'sib_page_home' ), admin_url( 'admin.php' ) ) ); ?> ">
222 <!-- Account Info -->
223 <div class="card sib-small-content">
224 <div class="card-header">
225 <strong><?php esc_attr_e( 'My Account', 'mailin' ); ?></strong>
226 </div>
227 <div class="card-body">
228 <div class="col-md-12">
229 <span><b><?php esc_attr_e( 'You are currently logged in as : ', 'mailin' ); ?></b></span>
230 <div style="margin-bottom: 10px;">
231 <p class="col-md-12" style="margin-top: 5px;">
232 <?php echo esc_attr( $account_user_name ); ?>&nbsp;-&nbsp;<?php echo esc_attr( $account_email ); ?><br>
233 <?php
234 $count = count( $account_data );
235 for ( $i = 0; $i < $count; $i ++ ) {
236 if ( isset($account_data[$i]['type']) )
237 {
238 echo esc_attr( $account_data[ $i ]['type'] ) . ' - ' . esc_attr( $account_data[ $i ]['credits'] ) . ' ' . esc_attr__( 'credits', 'mailin' ) . '<br>';
239 }
240 }
241 ?>
242 <?php if ($show_push): ?>
243 Web push -
244 <?php
245 $isEnterpriseClient = isset($account_settings['enterprise']) ? $account_settings['enterprise'] : false;
246 $isFreeClient = !empty(array_filter($account_data, function($entry) {
247 return isset($entry['type']) && $entry['type'] === 'free';
248 }));
249 echo $isEnterpriseClient ? esc_attr('unlimited') : '<strong>' . esc_attr('free') . '</strong> '. esc_attr('up to') . ' ' . number_format($isFreeClient ? 10000 : 100000);
250 ?>
251 <?php esc_attr_e( 'subscribers', 'mailin' ); ?><br>
252 <?php endif; ?>
253
254 <a class="text-decoration-none" href="<?php
255 $nonce = wp_create_nonce( 'brevo_logout_url' );
256 echo esc_url(
257 add_query_arg(array(
258 'page' => 'sib_page_home',
259 'sib_action' => 'logout',
260 '_wpnonce' => $nonce
261 ), "")
262 );?>" >
263 <i class="fa fa-angle-right"></i>&nbsp;<?php esc_attr_e( 'Log out', 'mailin' ); ?></a>
264 </p>
265 </div>
266
267 <span><b><?php esc_attr_e( 'Contacts', 'mailin' ); ?></b></span>
268 </div>
269 <div class="row" style="padding-top: 10px;">
270 <div class="col-md-6">
271 <p style="margin-top: 5px;">
272 <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>
273 </p>
274 </div>
275 <div class="col-md-6 row">
276 <p class="col-md-7">
277 <b><?php echo esc_attr__( 'Users Synchronisation', 'mailin' ); ?></b><br>
278 <?php echo esc_attr( $desc ); ?><br>
279 </p>
280 <div class="col-md-5">
281 <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>
282 </div>
283 </div>
284 </div>
285 </div>
286 </div>
287 <!-- Transactional Email -->
288 <div class="card sib-small-content">
289 <div class="card-header">
290 <strong><?php esc_attr_e( 'Transactional emails', 'mailin' ); ?></strong>
291 </div>
292 <div class="card-body">
293 <?php
294 if ( 'disabled' == $smtp_status ) :
295 ?>
296 <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>
297 <?php
298 endif;
299 ?>
300 <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>
301 <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>
302 <div class="row">
303 <p class="col-md-4 text-left"><?php esc_attr_e( 'Activate email through Brevo', 'mailin' ); ?></p>
304 <div class="col-md-3">
305 <label class="col-md-5"><input type="radio" name="activate_email" id="activate_email_radio_yes" value="yes"
306 <?php
307 checked( $home_settings['activate_email'], 'yes' );
308 if ( 'disabled' === $smtp_status ) {
309 echo ' disabled';
310 }
311 ?>
312 >&nbsp;<?php esc_attr_e( 'Yes', 'mailin' ); ?></label>
313 <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>
314 </div>
315 <div class="col-md-5">
316 <small style="font-style: italic;"><?php esc_attr_e( 'Choose "Yes" if you want to use Brevo SMTP to send transactional emails', 'mailin' ); ?></small>
317 </div>
318 </div>
319 <div id="email_send_field"
320 <?php
321 if ( 'yes' !== $home_settings['activate_email'] ) {
322 echo 'style="display:none;"';
323 }
324 ?>
325 >
326 <div class="row" style="margin-bottom: 10px;">
327 <p class="col-md-4 text-left"><?php esc_attr_e( 'Choose your sender', 'mailin' ); ?></p>
328 <div class="col-md-3">
329 <select id="sender_list" class="col-md-12">
330 <?php
331 $senders = SIB_API_Manager::get_sender_lists();
332 foreach ( $senders as $sender ) {
333 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>';
334 }
335 ?>
336 </select>
337 </div>
338 <div class="col-md-5">
339 <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>
340 </div>
341 </div>
342 <div class="row">
343 <p class="col-md-4 text-left"><?php esc_attr_e( 'Enter email to send a test', 'mailin' ); ?></p>
344 <div class="col-md-3">
345 <input id="activate_email" type="email" class="col-md-12">
346 <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>
347 </div>
348 <div class="col-md-5">
349 <small style="font-style: italic;"><?php esc_attr_e( 'Select here the email address you want to send a test email to.', 'mailin' ); ?></small>
350 </div>
351 </div>
352 </div>
353 </div>
354 </div>
355 <!-- Marketing Automation -->
356 <div class="card sib-small-content">
357 <div class="card-header">
358 <strong><?php esc_attr_e( 'Automation', 'mailin' ); ?></strong>
359 </div>
360 <div class="card-body">
361 <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>
362 <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>
363 <div class="sib-ma-alert sib-ma-disabled alert alert-danger" role="alert" style="display: none;"><?php esc_attr_e( 'You have not enabled automation in Brevo. Please do so by choosing the Automation application here: ', 'mailin' ); ?> <a href="https://account-app.brevo.com/account/apps/" target="_blank" rel="noopener">account-app.brevo.com/account/apps/</a> <?php esc_attr_e( 'Thanks', 'mailin' ) ?></div>
364 <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' ); ?>">
365 <div class="row">
366 <p class="col-md-4 text-left"><?php esc_attr_e( 'Activate Marketing Automation through Brevo', 'mailin' ); ?></p>
367 <div class="col-md-3">
368 <label class="col-md-5"><input type="radio" name="activate_ma" id="activate_ma_radio_yes" value="yes"
369 <?php
370 checked( true, $is_ma_active );
371 ?>
372 >&nbsp;<?php esc_attr_e( 'Yes', 'mailin' ); ?></label>
373 <label class="col-md-5"><input type="radio" name="activate_ma" id="activate_ma_radio_no" value="no" <?php
374 checked( false, $is_ma_active ); ?>>&nbsp;<?php esc_attr_e( 'No', 'mailin' ); ?></label>
375 </div>
376 <div class="col-md-5">
377 <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>
378 </div>
379 </div>
380 <div class="row" style="">
381 <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>
382 <div class="col-md-3">
383 <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>
384 </div>
385 <div class="col-md-5">
386 </div>
387 </div>
388 </div>
389 </div>
390 <?php if ($show_push): ?>
391 <!-- Push notifications -->
392 <div class="card sib-small-content">
393 <div class="card-header">
394 <strong><?php esc_attr_e( 'Web push', 'mailin' ); ?></strong>
395 </div>
396 <div class="card-body">
397 <?php if ( $push_activated && $push_app ) : ?>
398 <div class="row">
399 <div class="col-sm-12 text-left">
400 </div>
401 </div>
402 <div class="row">
403 <p class="col-md-4 text-left">
404 <?php
405 // translators: %s: number of subscribers
406 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() ) ); ?>
407 </p>
408 <div class="col-md-3">
409 <a href="<?php echo add_query_arg( 'page', SIB_Page_Push::PAGE_ID, admin_url( 'admin.php' ) ) ?>"
410 class="col-md-12 btn btn-success"><?php esc_attr_e( 'Web push dashboard', 'mailin' ); ?></a>
411 </div>
412 <div class="col-md-5">
413 <small style="font-style: italic;">
414 <?php printf(
415 // translators: %s: deactivate push notifications link
416 __( 'To stop getting new push subscribers and notifying existing ones, you can %s.', 'mailin' ),
417 '<a href="#" style="font-size:12px;" id="deactivate_push_btn">' . __( 'deactivate web push', 'mailin' ) . '</a>'
418 ); ?>
419 </small>
420 </div>
421 </div>
422 <?php else : ?>
423 <div class="row">
424 <p class="col-md-4 text-left"><?php esc_attr_e( 'Activate web push', 'mailin' ); ?></p>
425 <div class="col-md-3">
426 <button type="button" id="activate_push_btn" class="col-md-12 btn btn-success"><span
427 class="sib-spin"><i class="fa fa-circle-o-notch fa-spin fa-lg"></i>&nbsp;&nbsp;</span><?php esc_attr_e( 'Activate', 'mailin' ); ?>
428 </button>
429 <small id="sib-push-activation-message" style="display: none">
430 <br/>
431 <?php esc_attr_e( 'Please wait, activation might take up to a minute.', 'mailin' ); ?>
432 </small>
433 </div>
434 <div class="col-md-5">
435 <!-- NOTE: deactivate woocommerce-->
436 <!-- <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>-->
437 <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>
438 </div>
439 </div>
440 <?php endif ?>
441 </div>
442 </div>
443 <?php endif; ?>
444 <div class="card sib-small-content">
445 <div class="card-header">
446 <strong><?php esc_attr_e( 'SMS', 'mailin' ); ?></strong>
447 </div>
448 <div class="card-body">
449 <div class="row">
450 <div class="col-sm-12 text-left">
451 </div>
452 </div>
453 <div class="row">
454 <p class="col-md-4 text-left">
455 <?php
456 // translators: %s: number of subscribers
457 esc_html( _e( 'SMS statistics', 'mailin' ) ) ?>
458 </p>
459 <div class="col-md-3">
460 <a href="https://my.brevo.com/camp/message/stats/sms?utm_medium=plugin&utm_source=wordpress_plugin&utm_campaign=sms_stats"
461 class="col-md-12 btn btn-success"><?php esc_attr_e( 'SMS dashboard', 'mailin' ); ?></a>
462 </div>
463 <div class="col-md-5">
464 <small style="font-style: italic;">
465 <?php _e('Check your SMS campaign statistics, you can see more here:', 'mailin') ?>
466 <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>
467 </small>
468 </div>
469 </div>
470 </div>
471 </div>
472 </div>
473 <?php
474 }
475
476 /**
477 * Generate a language box on the plugin admin page.
478 */
479 public static function generate_side_bar() {
480 do_action( 'sib_language_sidebar' );
481 ?>
482
483 <div class="card text-left box-border-box sib-small-content">
484 <div class="card-header"><strong><?php esc_attr_e( 'About Brevo', 'mailin' ); ?></strong></div>
485 <div class="card-body">
486 <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>
487 <ul class="sib-widget-menu list-group">
488 <li>
489 <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>
490 </li>
491 <li>
492 <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>
493 </li>
494 <li>
495 <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>
496 </li>
497 </ul>
498 </div>
499
500 </div>
501 <div class="card text-left box-border-box sib-small-content">
502 <div class="card-header"><strong><?php esc_attr_e( 'Need Help?', 'mailin' ); ?></strong></div>
503 <div class="card-body">
504 <p><?php esc_attr_e( 'Do you have a question or need more information?', 'mailin' ); ?></p>
505 <ul class="sib-widget-menu list-group">
506 <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>
507 <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>
508 </ul>
509 <hr>
510 </div>
511 </div>
512 <div class="card text-left box-border-box sib-small-content">
513 <div class="card-header"><strong><?php esc_attr_e( 'Recommend this plugin', 'mailin' ); ?></strong></div>
514 <div class="card-body">
515 <p><?php esc_attr_e( 'Let everyone know you like this plugin through a review!' ,'mailin' ); ?></p>
516 <ul class="sib-widget-menu list-group">
517 <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>
518 </ul>
519 </div>
520 </div>
521 <?php
522 }
523
524 /**
525 * Get narration script
526 *
527 * @param string $title - pop up title.
528 * @param string $text - pop up content text.
529 */
530 static function get_narration_script( $title, $text ) {
531 ?>
532 <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>
533 <?php
534 }
535
536 /** Print disable mode popup */
537 static function print_disable_popup() {
538 ?>
539 <div class="modal fade sib-disable-modal">
540 <div class="modal-dialog">
541 <div class="modal-content">
542 <div class="modal-header">
543 <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>
544 <h4 class="modal-title"><?php esc_attr_e( 'Brevo','mailin' ); ?></h4>
545 </div>
546 <div class="modal-body" style="padding: 30px;">
547 <p>
548 <?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' ); ?>
549 </p>
550 <ul>
551 <li> <span class="glyphicon glyphicon-ok" style="font-size: 12px;"></span>&nbsp;&nbsp;<?php esc_attr_e( 'Collect and manage your contacts', 'mailin' ); ?></li>
552 <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>
553 <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>
554 <li> <span class="glyphicon glyphicon-ok" style="font-size: 12px;"></span>&nbsp;&nbsp;<?php esc_attr_e( 'Edit and send email marketing', 'mailin' ); ?></li>
555 </ul>
556 <div class="row" style="margin-top: 40px;">
557 <div class="col-md-6">
558 <a href="https://www.brevo.com/users/login/" target="_blank" rel="noopener"><i><?php esc_attr_e( 'Have an account?', 'mailin' ); ?></i></a>
559 </div>
560 <div class="col-md-6">
561 <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>
562 </div>
563 </div>
564 </div>
565
566 </div><!-- /.modal-content -->
567 </div><!-- /.modal-dialog -->
568 </div><!-- /.modal -->
569 <button id="sib-disable-popup" class="btn btn-success" data-toggle="modal" data-target=".sib-disable-modal" style="display: none;">sss</button>
570 <script>
571 jQuery(document).ready(function() {
572 jQuery('.sib-disable-modal').modal();
573
574 jQuery('.sib-disable-modal').on('hidden.bs.modal', function() {
575 window.location.href = '<?php echo esc_url( add_query_arg( 'page', 'sib_page_home', admin_url( 'admin.php' ) ) ); ?>';
576 });
577 });
578
579 </script>
580
581 <?php
582 }
583
584 /** Print user sync popup */
585 static function print_sync_popup() {
586 ?>
587 <div class="modal fade sib-sync-modal" id="syncUsers">
588 <div class="modal-dialog">
589 <div class="modal-content">
590 <div class="modal-header">
591 <h5 class="modal-title"><?php esc_attr_e( 'Users Synchronisation','mailin' ); ?></h5>
592 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
593 </div>
594 <div class="modal-body sync-modal-body" style="padding: 10px;">
595 <div id="sync-failure" class="sib_alert alert alert-danger" style="margin-bottom: 0px;display: none;"></div>
596 <form id="sib-sync-form">
597 <!-- roles -->
598 <div class="row sync-row" style="margin-top: 0;">
599 <b><p><?php esc_attr_e( 'Roles to sync', 'mailin' ); ?></p></b>
600 <?php foreach ( wp_roles()->roles as $role_name => $role_info ) : ?>
601 <div class="col-md-6">
602 <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>
603 </div>
604 <?php endforeach; ?>
605 </div>
606 <!-- lists -->
607 <?php $lists = SIB_API_Manager::get_lists(); ?>
608 <div class="row sync-row">
609 <b><p><?php esc_attr_e( 'Sync Lists', 'mailin' ); ?></p></b>
610 <div class="row" style="margin-top: 0;">
611 <div class="col-md-6">
612 <p><?php esc_attr_e( 'Choose the Brevo list in which you want to add your existing customers:', 'mailin' ); ?></p>
613 </div>
614 <div class="col-md-6">
615 <select data-placeholder="Please select the list" id="sib_select_list" name="list_id" multiple="true">
616 <?php foreach ( $lists as $list ) : ?>
617 <option value="<?php echo esc_attr( $list['id'] ); ?>"><?php echo esc_attr( $list['name'] ); ?></option>
618 <?php endforeach; ?>
619 </select>
620 </div>
621 </div>
622 </div>
623 <!-- Match Attributes -->
624 <?php
625 // available WordPress attributes.
626 $wpAttrs = array(
627 'first_name' => __( 'First Name','mailin' ),
628 'last_name' => __( 'Last Name','mailin' ),
629 'user_url' => __( 'Website URL','mailin' ),
630 'roles' => __( 'User Role','mailin' ),
631 'user_login' => __( 'Username','mailin' ),
632 'nickname' => __( 'Nickname','mailin' ),
633 'user_registered' => __( 'User Registration Date','mailin' ),
634 'display_name' => __( 'Display Name','mailin' ),
635 'description' => __( 'Description about user','mailin' ),
636 );
637 // available sendinblue attributes.
638 $sibAllAttrs = SIB_API_Manager::get_attributes();
639 $sibAttrs = $sibAllAttrs['attributes']['normal_attributes'];
640 ?>
641 <div class="row sync-row" id="sync-attr-area">
642 <b><p><?php esc_attr_e( 'Match Attributes', 'mailin' ); ?></p></b>
643 <div class="row" style="padding: 5px;margin-top: 0;">
644 <div class="row" style="margin-top: 0;">
645 <div class="col-md-6">
646 <p><?php esc_attr_e( 'WordPress Users Attributes', 'mailin' ); ?></p>
647 </div>
648 <div class="col-md-6">
649 <p><?php esc_attr_e( 'Brevo Contact Attributes', 'mailin' ); ?></p>
650 </div>
651 </div>
652 </div>
653
654 <div class="col-md-11 sync-attr-line">
655 <div class="row sync-attr" style="padding: 5px;border-top: dotted 1px #dedede;border-bottom: dotted 1px #dedede;margin-top: 0;">
656 <div class="col-md-5">
657 <select class="sync-wp-attr" name="" style="width: 100%;">
658 <?php foreach ( $wpAttrs as $id => $label ) : ?>
659 <option value="<?php echo esc_attr( $id ); ?>"><?php echo esc_attr( $label ); ?></option>
660 <?php endforeach; ?>
661 </select>
662 </div>
663 <div class="col-md-1" style="padding-left: 10px;padding-top: 3px;"><span class="dashicons dashicons-leftright"></span></div>
664 <div class="col-md-5">
665 <select class="sync-sib-attr" name="" style="width: 100%;">
666 <?php foreach ( $sibAttrs as $attr ) : ?>
667 <option value="<?php echo esc_attr( $attr['name'] ); ?>"><?php echo esc_attr( $attr['name'] ); ?></option>
668 <?php endforeach; ?>
669 </select>
670 </div>
671 <div class="col-md-1" style="padding-top: 3px;">
672 <a href="javascript:void(0)" class="sync-attr-dismiss" style="display: none;"><span class="dashicons dashicons-dismiss"></span></a>
673 </div>
674 <input type="hidden" class="sync-match" name="<?php echo esc_attr( $sibAttrs[0]['name'] ); ?>" value="first_name">
675 </div>
676 </div>
677 <div class="col-md-1 sync-attr-plus-col">
678 <div class="row sync-attr-plus">
679 <a href="javascript:void(0)"><span class="dashicons dashicons-plus-alt "></span></a>
680 </div>
681 </div>
682 </div>
683 <!-- Apply button -->
684 <div class="col-md-12 mt-2">
685 <a href="javascript:void(0)" id="sib_sync_users_btn" class="btn btn-success" style="float: right;"><?php esc_attr_e( 'Apply', 'mailin' ); ?></a>
686 </div>
687 </form>
688 </div>
689 </div><!-- /.modal-content -->
690 </div><!-- /.modal-dialog -->
691 </div><!-- /.modal -->
692 <?php
693 }
694
695 /** Ajax module for validation (Home - welcome) */
696 public static function ajax_validation_process() {
697 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
698 $access_key = isset( $_POST['access_key'] ) ? sanitize_text_field( wp_unslash( $_POST['access_key'] ) ) : '';
699 try {
700 update_option(SIB_Manager::API_KEY_V3_OPTION_NAME, $access_key);
701 $apiClient = new SendinblueApiClient();
702 $response = $apiClient->getAccount();
703 if ( $apiClient->getLastResponseCode() === SendinblueApiClient::RESPONSE_CODE_OK ) {
704 self::processInstallationInfo("login");
705 // create tables for users and forms.
706 SIB_Model_Users::createTable();
707 SIB_Forms::createTable(); // create default form also
708
709 // If the client don't have attributes regarding Double OptIn then we will create these.
710 SIB_API_Manager::create_default_dopt();
711 $message = 'success';
712 } else {
713 delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME);
714 $message = isset($response['code']) ? $response['code'] . ': ' . $response['message'] :'Please input a valid API v3 key';
715 }
716 } catch ( Exception $e ) {
717 $message = $e->getMessage();
718 delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME);
719 } finally {
720 wp_send_json($message);
721 }
722 }
723
724 /** Ajax module to change activate marketing automation option */
725 public static function ajax_validate_ma() {
726 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
727 $general_settings = get_option( SIB_Manager::MAIN_OPTION_NAME, array() );
728 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
729 $ma_key = isset( $general_settings['ma_key'] ) ? sanitize_text_field($general_settings['ma_key']) : null;
730 if ( $ma_key !== null && strlen($ma_key) > 0 ) {
731 $option_val = isset( $_POST['option_val'] ) ? sanitize_text_field( wp_unslash( $_POST['option_val'] ) ) : 'no';
732 $home_settings['activate_ma'] = $option_val;
733 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
734 wp_send_json( $option_val );
735 } else {
736 $home_settings['activate_ma'] = 'default';
737 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
738 wp_send_json( 'disabled' );
739 }
740 }
741
742 /** Ajax module to change activate email option */
743 public static function ajax_activate_email_change() {
744 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
745 $option_val = isset( $_POST['option_val'] ) ? sanitize_text_field( wp_unslash( $_POST['option_val'] ) ) : 'no';
746 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
747 $home_settings['activate_email'] = $option_val;
748 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
749 wp_send_json( $option_val );
750 }
751
752 /** Ajax module to change sender detail */
753 public static function ajax_sender_change() {
754 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
755 $sender_id = isset( $_POST['sender'] ) ? sanitize_text_field( wp_unslash( $_POST['sender'] ) ) : ''; // sender id.
756 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
757 $home_settings['sender'] = $sender_id;
758 $senders = SIB_API_Manager::get_sender_lists();
759 foreach ( $senders as $sender ) {
760 if ( $sender['id'] == $sender_id ) {
761 $home_settings['from_name'] = $sender['from_name'];
762 $home_settings['from_email'] = $sender['from_email'];
763 }
764 }
765 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
766 wp_send_json( 'success' );
767 }
768
769 /** Ajax module for send a test email */
770 public static function ajax_send_email() {
771 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
772
773 $subject = __( '[Brevo SMTP] test email', 'mailin' );
774 // Get sender info.
775 $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME );
776 if ( isset( $home_settings['sender'] ) ) {
777 $fromname = $home_settings['from_name'];
778 $from_email = $home_settings['from_email'];
779 } else {
780 $from_email = __( 'no-reply@' . parse_url(get_site_url(), PHP_URL_HOST), 'mailin' );
781 $fromname = __( 'Brevo', 'mailin' );
782 }
783
784 $from = array( $from_email, $fromname );
785 $email_templates = SIB_API_Manager::get_email_template( 'test' );
786
787 $html = $email_templates['html_content'];
788
789 $html = str_replace( '{title}', $subject, $html );
790
791 $mailin = new SendinblueApiClient();
792
793 $data = [
794 'sender' => [
795 'name' => $fromname,
796 'email' => $from_email,
797 ],
798 'replyTo' => [
799 'email' => $from_email,
800 ],
801 'to' => [
802 [
803 'email' => sanitize_email($_POST['email'])
804 ]
805 ],
806 'subject' => $subject,
807 'htmlContent' => $html
808 ];
809 $mailin->sendEmail( $data );
810
811 wp_send_json( 'success' );
812 }
813
814 /** Ajax module for remove all transient value */
815 public static function ajax_remove_cache() {
816 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
817 wp_send_json( 'success' );
818 }
819
820 /** Ajax module for sync wp users to contact list */
821 public static function ajax_sync_users() {
822 check_ajax_referer( 'ajax_sib_admin_nonce', 'security' );
823
824 // phpcs:ignore
825 $postData = isset( $_POST['data'] ) ? $_POST['data'] : array();
826
827 if ( ! isset( $postData['sync_role'] ) ) {
828 wp_send_json(
829 array(
830 'code' => 'empty_role',
831 'message' => __( 'Please select a user role.','mailin' ),
832 )
833 );}
834 if ( isset( $postData['errAttr'] ) ) {
835 wp_send_json(
836 array(
837 'code' => 'attr_duplicated',
838 'message' => sprintf( esc_attr__( 'The attribute %s is duplicated. You can select one at a time.','mailin' ), '<b>' . esc_html($postData['errAttr']) . '</b>' ),
839 )
840 );}
841
842 $roles = (array) $postData['sync_role']; // array or string.
843 $listIDs = array_map('intval', (array) $postData['list_id']);
844
845 unset( $postData['sync_role'] );
846 unset( $postData['list_id'] );
847
848 $usersData = 'EMAIL';
849 foreach ( $postData as $attrSibName => $attrWP ) {
850 $usersData .= ';' . sanitize_text_field($attrSibName);
851 }
852
853 // sync users to sendinblue.
854 // create body data like csv.
855 // NAME;SURNAME;EMAIL\nName1;Surname1;example1@example.net\nName2;Surname2;example2@example.net.
856 $contentData = '';
857 $usersCount = 0;
858 foreach ( $roles as $role ) {
859 $users = get_users(
860 array(
861 'role' => sanitize_text_field($role),
862 )
863 );
864 if ( empty( $users ) ) {
865 continue;
866 }
867 $usersCount += count($users);
868 foreach ( $users as $user ) {
869 $userId = $user->ID;
870 $user_info = get_userdata( $userId );
871 $userData = $user_info->user_email;
872 foreach ( $postData as $attrSibName => $attrWP ) {
873 if ( $attrWP == 'roles' )
874 {
875 $userData .= ';' . implode( ', ', $user_info->$attrWP ) ;
876 }
877 else {
878 $userData .= ';' . $user_info->$attrWP;
879 }
880
881 }
882 $contentData .= "\n" . strip_tags($userData);
883 }
884 }
885 if ( '' == $contentData ) {
886 wp_send_json(
887 array(
888 'code' => 'empty_users',
889 'message' => __( 'There is not any user in the roles.','mailin' ),
890 )
891 );}
892
893 $usersData .= $contentData;
894 $result = SIB_API_Manager::sync_users( $usersData, $listIDs );
895 update_option('sib_sync_users', $usersCount);
896 wp_send_json( $result );
897 }
898
899 /** Logout process */
900 function logout() {
901 self::processInstallationInfo("logout");
902 $setting = array();
903 update_option( SIB_Manager::MAIN_OPTION_NAME, $setting );
904 delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME);
905
906 $home_settings = array(
907 'activate_email' => 'no',
908 'activate_ma' => 'default',
909 );
910 update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings );
911
912 // remove sync users option.
913 delete_option( 'sib_sync_users' );
914 // remove all transients.
915 SIB_API_Manager::remove_transients();
916
917 // remove all forms.
918 SIB_Forms::removeAllForms();
919 SIB_Forms_Lang::remove_all_trans();
920
921 // Clear push settings
922 SIB_Push_Settings::clearAllSettings();
923
924 wp_safe_redirect( add_query_arg( 'page', self::PAGE_ID, admin_url( 'admin.php' ) ) );
925 exit();
926 }
927
928 public static function processInstallationInfo($action)
929 {
930 global $wp_version;
931
932 if($action == "login")
933 {
934 $apiClient = new SendinblueApiClient();
935
936 $params["partnerName"] = "WORDPRESS";
937 $params["active"] = true;
938 $params["connection"] = 27;
939 $params["plugin_version"] = SendinblueApiClient::PLUGIN_VERSION;
940 if(!empty($wp_version))
941 {
942 $params["shop_version"] = $wp_version;
943 }
944 $params["shop_url"] = get_home_url();
945 $params["created_at"] = gmdate("Y-m-d\TH:i:s\Z");
946 $params["activated_at"] = gmdate("Y-m-d\TH:i:s\Z");
947 $params["type"] = "sib";
948 $response = $apiClient->createInstallationInfo($params);
949 if ( $apiClient->getLastResponseCode() === SendinblueApiClient::RESPONSE_CODE_CREATED )
950 {
951 if(!empty($response["id"]))
952 {
953 update_option(SIB_Manager::INSTALLATION_ID, $response["id"]);
954 }
955 }
956 }
957 elseif($action == "logout")
958 {
959 $installationId = get_option( SIB_Manager::INSTALLATION_ID );
960 if(!empty($installationId))
961 {
962 $apiClient = new SendinblueApiClient();
963 $params["active"] = false;
964 $params["deactivated_at"] = gmdate("Y-m-d\TH:i:s\Z");
965 $params["connection"] = 27;
966 $params["plugin_version"] = SendinblueApiClient::PLUGIN_VERSION;
967 $apiClient->updateInstallationInfo($installationId, $params);
968 }
969 }
970 }
971 }
972
973 }
974