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