account
3 years ago
connect
3 years ago
debug
5 years ago
forms
2 years ago
js
3 years ago
partials
3 years ago
plugin-info
3 years ago
account.php
3 years ago
add-ons.php
5 years ago
add-trial-to-pricing.php
5 years ago
admin-notice.php
3 years ago
ajax-loader.php
4 years ago
api-connectivity-message-js.php
3 years ago
auto-installation.php
3 years ago
checkout.php
3 years ago
clone-resolution-js.php
2 years ago
connect.php
3 years ago
contact.php
3 years ago
debug.php
3 years ago
email.php
5 years ago
gdpr-optin-js.php
3 years ago
index.php
5 years ago
plugin-icon.php
3 years ago
powered-by.php
3 years ago
pricing.php
3 years ago
secure-https-header.php
5 years ago
sticky-admin-notice-js.php
3 years ago
tabs-capture-js.php
3 years ago
tabs.php
5 years ago
connect.php
1044 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package Freemius |
| 4 | * @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 | * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 |
| 6 | * @since 1.0.7 |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * @var array $VARS |
| 15 | * @var Freemius $fs |
| 16 | */ |
| 17 | $fs = freemius( $VARS['id'] ); |
| 18 | $slug = $fs->get_slug(); |
| 19 | |
| 20 | $is_pending_activation = $fs->is_pending_activation(); |
| 21 | $is_premium_only = $fs->is_only_premium(); |
| 22 | $has_paid_plans = $fs->has_paid_plan(); |
| 23 | $is_premium_code = $fs->is_premium(); |
| 24 | $is_freemium = $fs->is_freemium(); |
| 25 | |
| 26 | $fs->_enqueue_connect_essentials(); |
| 27 | |
| 28 | /** |
| 29 | * Enqueueing the styles in `_enqueue_connect_essentials()` is too late, as we need them in the HEADER. Therefore, inject the styles inline to avoid FOUC. |
| 30 | * |
| 31 | * @author Vova Feldman (@svovaf) |
| 32 | */ |
| 33 | echo "<style>\n"; |
| 34 | include WP_FS__DIR_CSS . '/admin/connect.css'; |
| 35 | echo "</style>\n"; |
| 36 | |
| 37 | $current_user = Freemius::_get_current_wp_user(); |
| 38 | |
| 39 | $first_name = $current_user->user_firstname; |
| 40 | if ( empty( $first_name ) ) { |
| 41 | $first_name = $current_user->nickname; |
| 42 | } |
| 43 | |
| 44 | $site_url = Freemius::get_unfiltered_site_url(); |
| 45 | $protocol_pos = strpos( $site_url, '://' ); |
| 46 | if ( false !== $protocol_pos ) { |
| 47 | $site_url = substr( $site_url, $protocol_pos + 3 ); |
| 48 | } |
| 49 | |
| 50 | $freemius_usage_tracking_url = $fs->get_usage_tracking_terms_url(); |
| 51 | $freemius_plugin_terms_url = $fs->get_eula_url(); |
| 52 | |
| 53 | $error = fs_request_get( 'error' ); |
| 54 | |
| 55 | $has_release_on_freemius = $fs->has_release_on_freemius(); |
| 56 | |
| 57 | $require_license_key = $is_premium_only || |
| 58 | ( |
| 59 | $is_freemium && |
| 60 | ( $is_premium_code || ! $has_release_on_freemius ) && |
| 61 | fs_request_get_bool( 'require_license', ( $is_premium_code || $has_release_on_freemius ) ) |
| 62 | ); |
| 63 | |
| 64 | $freemius_activation_terms_url = ($fs->is_premium() && $require_license_key) ? |
| 65 | $fs->get_license_activation_terms_url() : |
| 66 | $freemius_usage_tracking_url; |
| 67 | |
| 68 | $freemius_activation_terms_html = '<a href="' . esc_url( $freemius_activation_terms_url ) . '" target="_blank" rel="noopener" tabindex="1">freemius.com</a>'; |
| 69 | |
| 70 | if ( $is_pending_activation ) { |
| 71 | $require_license_key = false; |
| 72 | } |
| 73 | |
| 74 | if ( $require_license_key ) { |
| 75 | $fs->_add_license_activation_dialog_box(); |
| 76 | } |
| 77 | |
| 78 | $is_optin_dialog = ( |
| 79 | $fs->is_theme() && |
| 80 | $fs->is_themes_page() && |
| 81 | $fs->show_opt_in_on_themes_page() |
| 82 | ); |
| 83 | |
| 84 | if ( $is_optin_dialog ) { |
| 85 | $show_close_button = false; |
| 86 | $previous_theme_activation_url = ''; |
| 87 | |
| 88 | if ( ! $is_premium_code ) { |
| 89 | $show_close_button = true; |
| 90 | } else if ( $is_premium_only ) { |
| 91 | $previous_theme_activation_url = $fs->get_previous_theme_activation_url(); |
| 92 | $show_close_button = ( ! empty( $previous_theme_activation_url ) ); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | $is_network_level_activation = ( |
| 97 | fs_is_network_admin() && |
| 98 | $fs->is_network_active() && |
| 99 | ! $fs->is_network_delegated_connection() |
| 100 | ); |
| 101 | |
| 102 | $fs_user = Freemius::_get_user_by_email( $current_user->user_email ); |
| 103 | |
| 104 | $activate_with_current_user = ( |
| 105 | is_object( $fs_user ) && |
| 106 | ! $is_pending_activation && |
| 107 | // If requires a license for activation, use the user associated with the license for the opt-in. |
| 108 | ! $require_license_key && |
| 109 | ! $is_network_level_activation |
| 110 | ); |
| 111 | |
| 112 | $optin_params = $fs->get_opt_in_params( array(), $is_network_level_activation ); |
| 113 | $sites = isset( $optin_params['sites'] ) ? $optin_params['sites'] : array(); |
| 114 | |
| 115 | $is_network_upgrade_mode = ( fs_is_network_admin() && $fs->is_network_upgrade_mode() ); |
| 116 | |
| 117 | /* translators: %s: name (e.g. Hey John,) */ |
| 118 | $hey_x_text = esc_html( sprintf( fs_text_x_inline( 'Hey %s,', 'greeting', 'hey-x', $slug ), $first_name ) ); |
| 119 | |
| 120 | $activation_state = array( |
| 121 | 'is_license_activation' => $require_license_key, |
| 122 | 'is_pending_activation' => $is_pending_activation, |
| 123 | 'is_gdpr_required' => true, |
| 124 | 'is_network_level_activation' => $is_network_level_activation, |
| 125 | 'is_dialog' => $is_optin_dialog, |
| 126 | ); |
| 127 | ?> |
| 128 | <?php |
| 129 | if ( $is_optin_dialog ) { ?> |
| 130 | <div id="fs_theme_connect_wrapper"> |
| 131 | <?php |
| 132 | if ( $show_close_button ) { ?> |
| 133 | <button class="close dashicons dashicons-no"><span class="screen-reader-text">Close connect dialog</span> |
| 134 | </button> |
| 135 | <?php |
| 136 | } |
| 137 | ?> |
| 138 | <?php |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Allows developers to include custom HTML before the opt-in content. |
| 143 | * |
| 144 | * @author Vova Feldman |
| 145 | * @since 2.3.2 |
| 146 | */ |
| 147 | $fs->do_action( 'connect/before', $activation_state ); |
| 148 | ?> |
| 149 | <div id="fs_connect" |
| 150 | class="wrap<?php if ( ! fs_is_network_admin() && ( ! $fs->is_enable_anonymous() || $is_pending_activation || $require_license_key ) ) { |
| 151 | echo ' fs-anonymous-disabled'; |
| 152 | } ?><?php echo $require_license_key ? ' require-license-key' : '' ?>"> |
| 153 | <div class="fs-header"> |
| 154 | <!-- <b class="fs-site-icon"><i class="dashicons dashicons-wordpress-alt"></i></b>--> |
| 155 | <?php |
| 156 | $size = 50; |
| 157 | $vars = array( |
| 158 | 'id' => $fs->get_id(), |
| 159 | 'size' => $size, |
| 160 | ); |
| 161 | |
| 162 | fs_require_once_template( 'plugin-icon.php', $vars ); |
| 163 | ?> |
| 164 | <!-- <img class="fs-connect-logo" width="--><?php //echo $size ?><!--" height="--><?php //echo $size ?><!--" src="//img.freemius.com/logo/connect.svg"/>--> |
| 165 | </div> |
| 166 | <div class="fs-box-container"> |
| 167 | <div class="fs-content"> |
| 168 | <?php $fs->do_action( 'connect/before_message', $activation_state ) ?> |
| 169 | |
| 170 | <?php if ( ! empty( $error ) ) : ?> |
| 171 | <div class="fs-error"><?php echo $fs->apply_filters( 'connect_error_esc_html', esc_html( $error ) ) ?></div> |
| 172 | <?php endif ?> |
| 173 | <?php |
| 174 | if ( ! $is_pending_activation && ! $require_license_key ) { |
| 175 | if ( ! $fs->is_plugin_update() ) { |
| 176 | echo $fs->apply_filters( 'connect-header', sprintf( |
| 177 | '<h2 style="text-align: center">%s</h2>', |
| 178 | esc_html( fs_text_inline( 'Never miss an important update', 'connect-header' ) ) |
| 179 | ) ); |
| 180 | } else { |
| 181 | echo $fs->apply_filters( 'connect-header_on-update', sprintf( |
| 182 | '<h2>%s</h2>', |
| 183 | sprintf( |
| 184 | esc_html( |
| 185 | /* translators: %1$s: plugin name (e.g., "Awesome Plugin"); %2$s: version (e.g., "1.2.3") */ |
| 186 | fs_text_inline('Thank you for updating to %1$s v%2$s!', 'connect-header_on-update' ) |
| 187 | ), |
| 188 | esc_html( $fs->get_plugin_name() ), |
| 189 | $fs->get_plugin_version() |
| 190 | ) |
| 191 | ) ); |
| 192 | } |
| 193 | } |
| 194 | ?> |
| 195 | <p><?php |
| 196 | $button_label = fs_text_inline( 'Allow & Continue', 'opt-in-connect', $slug ); |
| 197 | $message = ''; |
| 198 | |
| 199 | if ( $is_pending_activation ) { |
| 200 | $button_label = fs_text_inline( 'Re-send activation email', 'resend-activation-email', $slug ); |
| 201 | |
| 202 | $message = $fs->apply_filters( 'pending_activation_message', sprintf( |
| 203 | /* translators: %s: name (e.g. Thanks John!) */ |
| 204 | fs_text_inline( 'Thanks %s!', 'thanks-x', $slug ) . '<br>' . |
| 205 | fs_text_inline( 'You should receive a confirmation email for %s to your mailbox at %s. Please make sure you click the button in that email to %s.', 'pending-activation-message', $slug ), |
| 206 | $first_name, |
| 207 | '<b>' . $fs->get_plugin_name() . '</b>', |
| 208 | '<b>' . $current_user->user_email . '</b>', |
| 209 | fs_text_inline( 'complete the opt-in', 'complete-the-opt-in', $slug ) |
| 210 | ) ); |
| 211 | } else if ( $require_license_key ) { |
| 212 | $button_label = fs_text_inline( 'Activate License', 'activate-license', $slug ); |
| 213 | |
| 214 | $message = $fs->apply_filters( |
| 215 | 'connect-message_on-premium', |
| 216 | sprintf( fs_text_inline( 'Welcome to %s! To get started, please enter your license key:', 'thanks-for-purchasing', $slug ), '<b>' . $fs->get_plugin_name() . '</b>' ), |
| 217 | $first_name, |
| 218 | $fs->get_plugin_name() |
| 219 | ); |
| 220 | } else { |
| 221 | $filter = 'connect_message'; |
| 222 | |
| 223 | if ( ! $fs->is_plugin_update() ) { |
| 224 | $default_optin_message = esc_html( |
| 225 | sprintf( |
| 226 | /* translators: %s: module type (plugin, theme, or add-on) */ |
| 227 | fs_text_inline( 'Opt in to get email notifications for security & feature updates, educational content, and occasional offers, and to share some basic WordPress environment info. This will help us make the %s more compatible with your site and better at doing what you need it to.', 'connect-message', $slug ), |
| 228 | $fs->get_module_label( true ) |
| 229 | ) |
| 230 | ); |
| 231 | } else { |
| 232 | // If Freemius was added on a plugin update, set different |
| 233 | // opt-in message. |
| 234 | |
| 235 | /* translators: %s: module type (plugin, theme, or add-on) */ |
| 236 | $default_optin_message = esc_html( sprintf( fs_text_inline( 'We have introduced this opt-in so you never miss an important update and help us make the %s more compatible with your site and better at doing what you need it to.', 'connect-message_on-update_why' ), $fs->get_module_label( true ) ) ); |
| 237 | |
| 238 | $default_optin_message .= '<br><br>' . esc_html( fs_text_inline( 'Opt in to get email notifications for security & feature updates, educational content, and occasional offers, and to share some basic WordPress environment info.', 'connect-message_on-update', $slug ) ); |
| 239 | |
| 240 | if ( $fs->is_enable_anonymous() ) { |
| 241 | $default_optin_message .= ' ' . esc_html( fs_text_inline( 'If you skip this, that\'s okay! %1$s will still work just fine.', 'connect-message_on-update_skip', $slug ) ); |
| 242 | } |
| 243 | |
| 244 | // If user customized the opt-in message on update, use |
| 245 | // that message. Otherwise, fallback to regular opt-in |
| 246 | // custom message if exists. |
| 247 | if ( $fs->has_filter( 'connect_message_on_update' ) ) { |
| 248 | $filter = 'connect_message_on_update'; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | $message = $fs->apply_filters( |
| 253 | $filter, |
| 254 | sprintf( |
| 255 | $default_optin_message, |
| 256 | '<b>' . esc_html( $fs->get_plugin_name() ) . '</b>', |
| 257 | '<b>' . $current_user->user_login . '</b>', |
| 258 | '<a href="' . $site_url . '" target="_blank" rel="noopener noreferrer">' . $site_url . '</a>', |
| 259 | $freemius_activation_terms_html |
| 260 | ), |
| 261 | $first_name, |
| 262 | $fs->get_plugin_name(), |
| 263 | $current_user->user_login, |
| 264 | '<a href="' . $site_url . '" target="_blank" rel="noopener noreferrer">' . $site_url . '</a>', |
| 265 | $freemius_activation_terms_html, |
| 266 | true |
| 267 | ); |
| 268 | } |
| 269 | |
| 270 | if ( $is_network_upgrade_mode ) { |
| 271 | $network_integration_text = esc_html( fs_text_inline( 'We\'re excited to introduce the Freemius network-level integration.', 'connect_message_network_upgrade', $slug ) ); |
| 272 | |
| 273 | if ($is_premium_code){ |
| 274 | $message = $network_integration_text . ' ' . sprintf( fs_text_inline( 'During the update process we detected %d site(s) that are still pending license activation.', 'connect_message_network_upgrade-premium', $slug ), count( $sites ) ); |
| 275 | |
| 276 | $message .= '<br><br>' . sprintf( fs_text_inline( 'If you\'d like to use the %s on those sites, please enter your license key below and click the activation button.', 'connect_message_network_upgrade-premium-activate-license', $slug ), $is_premium_only ? $fs->get_module_label( true ) : sprintf( |
| 277 | /* translators: %s: module type (plugin, theme, or add-on) */ |
| 278 | fs_text_inline( "%s's paid features", 'x-paid-features', $slug ), |
| 279 | $fs->get_module_label( true ) |
| 280 | ) ); |
| 281 | |
| 282 | /* translators: %s: module type (plugin, theme, or add-on) */ |
| 283 | $message .= ' ' . sprintf( fs_text_inline( 'Alternatively, you can skip it for now and activate the license later, in your %s\'s network-level Account page.', 'connect_message_network_upgrade-premium-skip-license', $slug ), $fs->get_module_label( true ) ); |
| 284 | }else { |
| 285 | $message = $network_integration_text . ' ' . sprintf( fs_text_inline( 'During the update process we detected %s site(s) in the network that are still pending your attention.', 'connect_message_network_upgrade-free', $slug ), count( $sites ) ) . '<br><br>' . ( fs_starts_with( $message, $hey_x_text . '<br>' ) ? substr( $message, strlen( $hey_x_text . '<br>' ) ) : $message ); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | echo $message; |
| 290 | ?></p> |
| 291 | <?php if ( $require_license_key ) : ?> |
| 292 | <div class="fs-license-key-container"> |
| 293 | <input id="fs_license_key" name="fs_key" type="text" required maxlength="<?php echo $fs->apply_filters('license_key_maxlength', 32) ?>" |
| 294 | placeholder="<?php fs_esc_attr_echo_inline( 'License key', 'license-key', $slug ) ?>" tabindex="1"/> |
| 295 | <i class="dashicons dashicons-admin-network"></i> |
| 296 | <a class="show-license-resend-modal show-license-resend-modal-<?php echo $fs->get_unique_affix() ?>" |
| 297 | href="#"><?php fs_esc_html_echo_inline( "Can't find your license key?", 'cant-find-license-key', $slug ); ?></a> |
| 298 | </div> |
| 299 | |
| 300 | <?php |
| 301 | /** |
| 302 | * Allows developers to include custom HTML after the license input container. |
| 303 | * |
| 304 | * @author Vova Feldman |
| 305 | * @since 2.1.2 |
| 306 | */ |
| 307 | $fs->do_action( 'connect/after_license_input', $activation_state ); |
| 308 | ?> |
| 309 | |
| 310 | <?php |
| 311 | $send_updates_text = sprintf( |
| 312 | '%s<span class="action-description"> - %s</span>', |
| 313 | $fs->get_text_inline( 'Yes', 'yes' ), |
| 314 | $fs->get_text_inline( 'send me security & feature updates, educational content and offers.', 'send-updates' ) |
| 315 | ); |
| 316 | |
| 317 | $do_not_send_updates_text = sprintf( |
| 318 | '%s<span class="action-description"> - %s</span>', |
| 319 | $fs->get_text_inline( 'No', 'no' ), |
| 320 | sprintf( |
| 321 | $fs->get_text_inline( 'do %sNOT%s send me security & feature updates, educational content and offers.', 'do-not-send-updates' ), |
| 322 | '<span class="underlined">', |
| 323 | '</span>' |
| 324 | ) |
| 325 | ); |
| 326 | ?> |
| 327 | <div id="fs_marketing_optin"> |
| 328 | <span class="fs-message"><?php fs_echo_inline( "Please let us know if you'd like us to contact you for security & feature updates, educational content, and occasional offers:", 'contact-for-updates' ) ?></span> |
| 329 | <div class="fs-input-container"> |
| 330 | <label> |
| 331 | <input type="radio" name="allow-marketing" value="true" tabindex="1" /> |
| 332 | <span class="fs-input-label"><?php echo $send_updates_text ?></span> |
| 333 | </label> |
| 334 | <label> |
| 335 | <input type="radio" name="allow-marketing" value="false" tabindex="1" /> |
| 336 | <span class="fs-input-label"><?php echo $do_not_send_updates_text ?></span> |
| 337 | </label> |
| 338 | </div> |
| 339 | </div> |
| 340 | <?php endif ?> |
| 341 | <?php if ( $is_network_level_activation ) : ?> |
| 342 | <?php |
| 343 | $vars = array( |
| 344 | 'id' => $fs->get_id(), |
| 345 | 'sites' => $sites, |
| 346 | 'require_license_key' => $require_license_key |
| 347 | ); |
| 348 | |
| 349 | echo fs_get_template( 'partials/network-activation.php', $vars ); |
| 350 | ?> |
| 351 | <?php endif ?> |
| 352 | |
| 353 | <?php $fs->do_action( 'connect/after_message', $activation_state ) ?> |
| 354 | </div> |
| 355 | <div class="fs-actions"> |
| 356 | <?php $fs->do_action( 'connect/before_actions', $activation_state ) ?> |
| 357 | |
| 358 | <?php if ( $fs->is_enable_anonymous() && ! $is_pending_activation && ( ! $require_license_key || $is_network_upgrade_mode ) ) : ?> |
| 359 | <a id="skip_activation" href="<?php echo fs_nonce_url( $fs->_get_admin_page_url( '', array( 'fs_action' => $fs->get_unique_affix() . '_skip_activation' ), $is_network_level_activation ), $fs->get_unique_affix() . '_skip_activation' ) ?>" |
| 360 | class="button button-secondary" tabindex="2"><?php fs_esc_html_echo_x_inline( 'Skip', 'verb', 'skip', $slug ) ?></a> |
| 361 | <?php endif ?> |
| 362 | <?php if ( $is_network_level_activation && $fs->apply_filters( 'show_delegation_option', true ) ) : ?> |
| 363 | <a id="delegate_to_site_admins" class="fs-tooltip-trigger <?php echo is_rtl() ? ' rtl' : '' ?>" href="<?php echo fs_nonce_url( $fs->_get_admin_page_url( '', array( 'fs_action' => $fs->get_unique_affix() . '_delegate_activation' ) ), $fs->get_unique_affix() . '_delegate_activation' ) ?>"><?php fs_esc_html_echo_inline( 'Delegate to Site Admins', 'delegate-to-site-admins', $slug ) ?><span class="fs-tooltip"><?php fs_esc_html_echo_inline( 'If you click it, this decision will be delegated to the sites administrators.', 'delegate-sites-tooltip', $slug ) ?></span></a> |
| 364 | <?php endif ?> |
| 365 | <?php if ( $activate_with_current_user ) : ?> |
| 366 | <form action="" method="POST"> |
| 367 | <input type="hidden" name="fs_action" |
| 368 | value="<?php echo esc_attr( $fs->get_unique_affix() . '_activate_existing' ) ?>"> |
| 369 | <?php wp_nonce_field( $fs->get_unique_affix() . '_activate_existing' ) ?> |
| 370 | <input type="hidden" name="is_extensions_tracking_allowed" value="1"> |
| 371 | <input type="hidden" name="is_diagnostic_tracking_allowed" value="1"> |
| 372 | <button class="button button-primary" tabindex="1" |
| 373 | type="submit"><?php echo esc_html( $button_label ) ?></button> |
| 374 | </form> |
| 375 | <?php else : ?> |
| 376 | <form method="post" action="<?php echo WP_FS__ADDRESS ?>/action/service/user/install/"> |
| 377 | <?php unset( $optin_params['sites']); ?> |
| 378 | <?php foreach ( $optin_params as $name => $value ) : ?> |
| 379 | <input type="hidden" name="<?php echo esc_attr( $name ) ?>" value="<?php echo esc_attr( $value ) ?>"> |
| 380 | <?php endforeach ?> |
| 381 | <input type="hidden" name="is_extensions_tracking_allowed" value="1"> |
| 382 | <input type="hidden" name="is_diagnostic_tracking_allowed" value="1"> |
| 383 | <button class="button button-primary" tabindex="1" |
| 384 | type="submit"<?php if ( $require_license_key ) { |
| 385 | echo ' disabled="disabled"'; |
| 386 | } ?>><?php echo esc_html( $button_label ) ?></button> |
| 387 | </form> |
| 388 | <?php endif ?> |
| 389 | <?php if ( $require_license_key ) : ?> |
| 390 | <a id="license_issues_link" |
| 391 | href="<?php echo esc_url( $fs->apply_filters( 'known_license_issues_url', 'https://freemius.com/help/documentation/wordpress-sdk/license-activation-issues/' ) ) ?>" |
| 392 | target="_blank"><?php fs_esc_html_echo_inline( 'License issues?', 'license-issues', $slug ) ?></a> |
| 393 | <?php endif ?> |
| 394 | |
| 395 | <?php $fs->do_action( 'connect/after_actions', $activation_state ) ?> |
| 396 | </div><?php |
| 397 | $permission_manager = FS_Permission_Manager::instance( $fs ); |
| 398 | |
| 399 | // Set core permission list items. |
| 400 | $permissions = array(); |
| 401 | |
| 402 | // Add newsletter permissions if enabled. |
| 403 | if ( $fs->is_permission_requested( 'newsletter' ) ) { |
| 404 | $permissions[] = $permission_manager->get_newsletter_permission(); |
| 405 | } |
| 406 | |
| 407 | $permissions = $permission_manager->get_permissions( |
| 408 | $require_license_key, |
| 409 | $permissions |
| 410 | ); |
| 411 | |
| 412 | if ( ! empty( $permissions ) ) : ?> |
| 413 | <div class="fs-permissions"> |
| 414 | <?php if ( $require_license_key ) : ?> |
| 415 | <a class="fs-trigger wp-core-ui" href="#" tabindex="1" style="color: inherit;"><?php echo sprintf( |
| 416 | fs_esc_html_inline( 'For delivery of security & feature updates, and license management, %s needs to', 'license-sync-disclaimer', $slug ) . '<b class="fs-arrow"></b>', |
| 417 | sprintf( '<nobr class="button-link" style="color: inherit;">%s</nobr>', esc_html( $fs->get_plugin_title() ) ) |
| 418 | ) ?></a> |
| 419 | <?php else : ?> |
| 420 | <a class="fs-trigger wp-core-ui" href="#" tabindex="1" style="color: inherit;"><?php printf( |
| 421 | fs_esc_html_inline( 'This will allow %s to', 'this-will-allow-x', $slug ) . '<b class="fs-arrow"></b>', |
| 422 | sprintf( '<nobr class="button-link" style="color: inherit;">%s</nobr>', esc_html( $fs->get_plugin_title() ) ) |
| 423 | ) ?></a> |
| 424 | <?php endif ?> |
| 425 | <ul><?php |
| 426 | foreach ( $permissions as $permission ) { |
| 427 | $permission_manager->render_permission( $permission ); |
| 428 | } |
| 429 | ?></ul> |
| 430 | </div> |
| 431 | <?php endif ?> |
| 432 | <?php if ( $is_premium_code && $is_freemium ) : ?> |
| 433 | <div class="fs-freemium-licensing"> |
| 434 | <p> |
| 435 | <?php if ( $require_license_key ) : ?> |
| 436 | <?php fs_esc_html_echo_inline( 'Don\'t have a license key?', 'dont-have-license-key', $slug ) ?> |
| 437 | <a data-require-license="false" tabindex="1"><?php fs_esc_html_echo_inline( 'Activate Free Version', 'activate-free-version', $slug ) ?></a> |
| 438 | <?php else : ?> |
| 439 | <?php fs_echo_inline( 'Have a license key?', 'have-license-key', $slug ) ?> |
| 440 | <a data-require-license="true" tabindex="1"><?php fs_esc_html_echo_inline( 'Activate License', 'activate-license', $slug ) ?></a> |
| 441 | <?php endif ?> |
| 442 | </p> |
| 443 | </div> |
| 444 | <?php endif ?> |
| 445 | </div> |
| 446 | <div class="fs-terms"> |
| 447 | <a class="fs-tooltip-trigger<?php echo is_rtl() ? ' rtl' : '' ?>" href="<?php echo esc_url( $freemius_activation_terms_url ) ?>" target="_blank" rel="noopener" tabindex="1">Powered by Freemius<?php if ( $require_license_key ) : ?> <span class="fs-tooltip" style="width: 170px"><?php echo esc_html( $fs->get_text_inline( 'Freemius is our licensing and software updates engine', 'permissions-extensions_desc' ) ) ?></span><?php endif ?></a> |
| 448 | - |
| 449 | <a href="https://freemius.com/privacy/" target="_blank" rel="noopener" |
| 450 | tabindex="1"><?php fs_esc_html_echo_inline( 'Privacy Policy', 'privacy-policy', $slug ) ?></a> |
| 451 | - |
| 452 | <?php if ($require_license_key) : ?> |
| 453 | <a href="<?php echo esc_url( $freemius_plugin_terms_url ) ?>" target="_blank" rel="noopener" tabindex="1"><?php fs_echo_inline( 'License Agreement', 'license-agreement', $slug ) ?></a> |
| 454 | <?php else : ?> |
| 455 | <a href="<?php echo esc_url( $freemius_usage_tracking_url ) ?>" target="_blank" rel="noopener" tabindex="1"><?php fs_echo_inline( 'Terms of Service', 'tos', $slug ) ?></a> |
| 456 | <?php endif; ?> |
| 457 | </div> |
| 458 | </div> |
| 459 | <?php |
| 460 | /** |
| 461 | * Allows developers to include custom HTML after the opt-in content. |
| 462 | * |
| 463 | * @author Vova Feldman |
| 464 | * @since 2.3.2 |
| 465 | */ |
| 466 | $fs->do_action( 'connect/after', $activation_state ); |
| 467 | |
| 468 | if ( $is_optin_dialog ) { ?> |
| 469 | </div> |
| 470 | <?php |
| 471 | } |
| 472 | ?> |
| 473 | <script type="text/javascript"> |
| 474 | (function ($) { |
| 475 | var $html = $('html'); |
| 476 | |
| 477 | <?php |
| 478 | if ( $is_optin_dialog ) { |
| 479 | if ( $show_close_button ) { ?> |
| 480 | var $themeConnectWrapper = $('#fs_theme_connect_wrapper'); |
| 481 | |
| 482 | $themeConnectWrapper.find('button.close').on('click', function () { |
| 483 | <?php if ( ! empty( $previous_theme_activation_url ) ) { ?> |
| 484 | location.href = '<?php echo html_entity_decode( $previous_theme_activation_url ); ?>'; |
| 485 | <?php } else { ?> |
| 486 | $themeConnectWrapper.remove(); |
| 487 | $html.css({overflow: $html.attr('fs-optin-overflow')}); |
| 488 | <?php } ?> |
| 489 | }); |
| 490 | <?php |
| 491 | } |
| 492 | ?> |
| 493 | |
| 494 | $html.attr('fs-optin-overflow', $html.css('overflow')); |
| 495 | $html.css({overflow: 'hidden'}); |
| 496 | |
| 497 | <?php |
| 498 | } |
| 499 | ?> |
| 500 | |
| 501 | var $primaryCta = $('.fs-actions .button.button-primary'), |
| 502 | primaryCtaLabel = $primaryCta.html(), |
| 503 | $form = $('.fs-actions form'), |
| 504 | isNetworkActive = <?php echo $is_network_level_activation ? 'true' : 'false' ?>, |
| 505 | requireLicenseKey = <?php echo $require_license_key ? 'true' : 'false' ?>, |
| 506 | hasContextUser = <?php echo $activate_with_current_user ? 'true' : 'false' ?>, |
| 507 | isNetworkUpgradeMode = <?php echo $is_network_upgrade_mode ? 'true' : 'false' ?>, |
| 508 | $licenseSecret, |
| 509 | $licenseKeyInput = $('#fs_license_key'), |
| 510 | pauseCtaLabelUpdate = false, |
| 511 | isNetworkDelegating = false, |
| 512 | /** |
| 513 | * @author Leo Fajardo (@leorw) |
| 514 | * @since 2.1.0 |
| 515 | */ |
| 516 | resetLoadingMode = function() { |
| 517 | // Reset loading mode. |
| 518 | $primaryCta.html(primaryCtaLabel); |
| 519 | $primaryCta.prop('disabled', false); |
| 520 | $( '.fs-loading' ).removeClass( 'fs-loading' ); |
| 521 | |
| 522 | console.log('resetLoadingMode - Primary button was enabled'); |
| 523 | }, |
| 524 | setLoadingMode = function () { |
| 525 | $( document.body ).addClass( 'fs-loading' ); |
| 526 | }; |
| 527 | |
| 528 | $('.fs-actions .button').on('click', function () { |
| 529 | setLoadingMode(); |
| 530 | |
| 531 | var $this = $(this); |
| 532 | |
| 533 | setTimeout(function () { |
| 534 | if ( ! requireLicenseKey || ! $marketingOptin.hasClass( 'error' ) ) { |
| 535 | $this.attr('disabled', 'disabled'); |
| 536 | } |
| 537 | }, 200); |
| 538 | }); |
| 539 | |
| 540 | if ( isNetworkActive ) { |
| 541 | var |
| 542 | $multisiteOptionsContainer = $( '.fs-multisite-options-container' ), |
| 543 | $allSitesOptions = $( '.fs-all-sites-options' ), |
| 544 | $applyOnAllSites = $( '.fs-apply-on-all-sites-checkbox' ), |
| 545 | $sitesListContainer = $( '.fs-sites-list-container' ), |
| 546 | totalSites = <?php echo count( $sites ) ?>, |
| 547 | maxSitesListHeight = null, |
| 548 | $skipActivationButton = $( '#skip_activation' ), |
| 549 | $delegateToSiteAdminsButton = $( '#delegate_to_site_admins' ), |
| 550 | hasAnyInstall = <?php echo ! is_null( $fs->find_first_install() ) ? 'true' : 'false' ?>; |
| 551 | |
| 552 | $applyOnAllSites.click(function() { |
| 553 | var isChecked = $( this ).is( ':checked' ); |
| 554 | |
| 555 | if ( isChecked ) { |
| 556 | $multisiteOptionsContainer.find( '.action' ).removeClass( 'selected' ); |
| 557 | updatePrimaryCtaText( 'allow' ); |
| 558 | } |
| 559 | |
| 560 | $multisiteOptionsContainer.find( '.action-allow' ).addClass( 'selected' ); |
| 561 | |
| 562 | $skipActivationButton.toggle(); |
| 563 | |
| 564 | $delegateToSiteAdminsButton.toggle(); |
| 565 | |
| 566 | $multisiteOptionsContainer.toggleClass( 'fs-apply-on-all-sites', isChecked ); |
| 567 | |
| 568 | $sitesListContainer.toggle( ! isChecked ); |
| 569 | if ( ! isChecked && null === maxSitesListHeight ) { |
| 570 | /** |
| 571 | * Set the visible number of rows to 5 (5 * height of the first row). |
| 572 | * |
| 573 | * @author Leo Fajardo (@leorw) |
| 574 | */ |
| 575 | maxSitesListHeight = ( 5 * $sitesListContainer.find( 'tr:first' ).height() ); |
| 576 | $sitesListContainer.css( 'max-height', maxSitesListHeight ); |
| 577 | } |
| 578 | }); |
| 579 | |
| 580 | $allSitesOptions.find( '.action' ).click(function( evt ) { |
| 581 | var actionType = $( evt.target ).data( 'action-type' ); |
| 582 | |
| 583 | $multisiteOptionsContainer.find( '.action' ).removeClass( 'selected' ); |
| 584 | $multisiteOptionsContainer.find( '.action-' + actionType ).toggleClass( 'selected' ); |
| 585 | |
| 586 | updatePrimaryCtaText( actionType ); |
| 587 | }); |
| 588 | |
| 589 | $sitesListContainer.delegate( 'td:not(:first-child)', 'click', function() { |
| 590 | // If a site row is clicked, trigger a click on the checkbox. |
| 591 | $( this ).parent().find( 'td:first-child input' ).click(); |
| 592 | } ); |
| 593 | |
| 594 | $sitesListContainer.delegate( '.action', 'click', function( evt ) { |
| 595 | var $this = $( evt.target ); |
| 596 | if ( $this.hasClass( 'selected' ) ) { |
| 597 | return false; |
| 598 | } |
| 599 | |
| 600 | $this.parents( 'tr:first' ).find( '.action' ).removeClass( 'selected' ); |
| 601 | $this.toggleClass( 'selected' ); |
| 602 | |
| 603 | var |
| 604 | singleSiteActionType = $this.data( 'action-type' ), |
| 605 | totalSelected = $sitesListContainer.find( '.action-' + singleSiteActionType + '.selected' ).length; |
| 606 | |
| 607 | $allSitesOptions.find( '.action.selected' ).removeClass( 'selected' ); |
| 608 | |
| 609 | if ( totalSelected === totalSites ) { |
| 610 | $allSitesOptions.find( '.action-' + singleSiteActionType ).addClass( 'selected' ); |
| 611 | |
| 612 | updatePrimaryCtaText( singleSiteActionType ); |
| 613 | } else { |
| 614 | updatePrimaryCtaText( 'mixed' ); |
| 615 | } |
| 616 | }); |
| 617 | |
| 618 | if ( isNetworkUpgradeMode || hasAnyInstall ) { |
| 619 | $skipActivationButton.click(function(){ |
| 620 | $delegateToSiteAdminsButton.hide(); |
| 621 | |
| 622 | $skipActivationButton.html('<?php fs_esc_js_echo_inline( 'Skipping, please wait', 'skipping-wait', $slug ) ?>...'); |
| 623 | |
| 624 | pauseCtaLabelUpdate = true; |
| 625 | |
| 626 | // Check all sites to be skipped. |
| 627 | $allSitesOptions.find('.action.action-skip').click(); |
| 628 | |
| 629 | $form.submit(); |
| 630 | |
| 631 | pauseCtaLabelUpdate = false; |
| 632 | |
| 633 | return false; |
| 634 | }); |
| 635 | |
| 636 | $delegateToSiteAdminsButton.click(function(){ |
| 637 | $delegateToSiteAdminsButton.html('<?php fs_esc_js_echo_inline( 'Delegating, please wait', 'delegating-wait', $slug ) ?>...'); |
| 638 | |
| 639 | pauseCtaLabelUpdate = true; |
| 640 | |
| 641 | /** |
| 642 | * Set to true so that the form submission handler can differentiate delegation from license |
| 643 | * activation and the proper AJAX action will be used (when delegating, the action should be |
| 644 | * `network_activate` and not `activate_license`). |
| 645 | * |
| 646 | * @author Leo Fajardo (@leorw) |
| 647 | * @since 2.3.0 |
| 648 | */ |
| 649 | isNetworkDelegating = true; |
| 650 | |
| 651 | // Check all sites to be skipped. |
| 652 | $allSitesOptions.find('.action.action-delegate').click(); |
| 653 | |
| 654 | $form.submit(); |
| 655 | |
| 656 | pauseCtaLabelUpdate = false; |
| 657 | |
| 658 | /** |
| 659 | * Set to false so that in case the previous AJAX request has failed, the form submission handler |
| 660 | * can differentiate license activation from delegation and the proper AJAX action will be used |
| 661 | * (when activating a license, the action should be `activate_license` and not `network_activate`). |
| 662 | * |
| 663 | * @author Leo Fajardo (@leorw) |
| 664 | * @since 2.3.0 |
| 665 | */ |
| 666 | isNetworkDelegating = false; |
| 667 | |
| 668 | return false; |
| 669 | }); |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | /** |
| 674 | * @author Leo Fajardo (@leorw) |
| 675 | */ |
| 676 | function updatePrimaryCtaText( actionType ) { |
| 677 | if (pauseCtaLabelUpdate) |
| 678 | return; |
| 679 | |
| 680 | var text = '<?php fs_esc_js_echo_inline( 'Continue', 'continue', $slug ) ?>'; |
| 681 | |
| 682 | switch ( actionType ) { |
| 683 | case 'allow': |
| 684 | text = '<?php fs_esc_js_echo_inline( 'Allow & Continue', 'opt-in-connect', $slug ) ?>'; |
| 685 | break; |
| 686 | case 'delegate': |
| 687 | text = '<?php fs_esc_js_echo_inline( 'Delegate to Site Admins & Continue', 'delegate-to-site-admins-and-continue', $slug ) ?>'; |
| 688 | break; |
| 689 | case 'skip': |
| 690 | text = '<?php fs_esc_js_echo_x_inline( 'Skip', 'verb', 'skip', $slug ) ?>'; |
| 691 | break; |
| 692 | } |
| 693 | |
| 694 | $primaryCta.html( text ); |
| 695 | } |
| 696 | |
| 697 | var ajaxOptin = ( requireLicenseKey || isNetworkActive ); |
| 698 | |
| 699 | $form.on('submit', function () { |
| 700 | var $extensionsPermission = $( '#fs_permission_extensions .fs-switch' ), |
| 701 | isExtensionsTrackingAllowed = ( $extensionsPermission.length > 0 ) ? |
| 702 | $extensionsPermission.hasClass( 'fs-on' ) : |
| 703 | null; |
| 704 | |
| 705 | var $diagnosticPermission = $( '#fs_permission_diagnostic .fs-switch' ), |
| 706 | isDiagnosticTrackingAllowed = ( $diagnosticPermission.length > 0 ) ? |
| 707 | $diagnosticPermission.hasClass( 'fs-on' ) : |
| 708 | null; |
| 709 | |
| 710 | if ( null === isExtensionsTrackingAllowed ) { |
| 711 | $( 'input[name=is_extensions_tracking_allowed]' ).remove(); |
| 712 | } else { |
| 713 | $( 'input[name=is_extensions_tracking_allowed]' ).val( isExtensionsTrackingAllowed ? 1 : 0 ); |
| 714 | } |
| 715 | |
| 716 | // We are not showing switch to enable/disable diagnostic tracking while activating free version. So, don't remove hidden `is_diagnostic_tracking_allowed` element from DOM and change the value only if switch is available. |
| 717 | if ( null !== isDiagnosticTrackingAllowed ) { |
| 718 | $( 'input[name=is_diagnostic_tracking_allowed]' ).val( isDiagnosticTrackingAllowed ? 1 : 0 ); |
| 719 | } |
| 720 | |
| 721 | /** |
| 722 | * @author Vova Feldman (@svovaf) |
| 723 | * @since 1.1.9 |
| 724 | */ |
| 725 | if ( ajaxOptin ) { |
| 726 | if (!hasContextUser || isNetworkUpgradeMode) { |
| 727 | var action = null, |
| 728 | security = null; |
| 729 | |
| 730 | if ( requireLicenseKey && ! isNetworkDelegating ) { |
| 731 | action = '<?php echo $fs->get_ajax_action( 'activate_license' ) ?>'; |
| 732 | security = '<?php echo $fs->get_ajax_security( 'activate_license' ) ?>'; |
| 733 | } else { |
| 734 | action = '<?php echo $fs->get_ajax_action( 'network_activate' ) ?>'; |
| 735 | security = '<?php echo $fs->get_ajax_security( 'network_activate' ) ?>'; |
| 736 | } |
| 737 | |
| 738 | $('.fs-error').remove(); |
| 739 | |
| 740 | var |
| 741 | licenseKey = $licenseKeyInput.val(), |
| 742 | data = { |
| 743 | action : action, |
| 744 | security : security, |
| 745 | license_key: licenseKey, |
| 746 | module_id : '<?php echo $fs->get_id() ?>' |
| 747 | }; |
| 748 | |
| 749 | if ( |
| 750 | requireLicenseKey && |
| 751 | ! isNetworkDelegating && |
| 752 | isMarketingAllowedByLicense.hasOwnProperty(licenseKey) |
| 753 | ) { |
| 754 | var |
| 755 | isMarketingAllowed = null, |
| 756 | $isMarketingAllowed = $marketingOptin.find( 'input[type="radio"][name="allow-marketing"]:checked'); |
| 757 | |
| 758 | |
| 759 | if ($isMarketingAllowed.length > 0) |
| 760 | isMarketingAllowed = ('true' == $isMarketingAllowed.val()); |
| 761 | |
| 762 | if ( null == isMarketingAllowedByLicense[ licenseKey ] && |
| 763 | null == isMarketingAllowed |
| 764 | ) { |
| 765 | $marketingOptin.addClass( 'error' ).show(); |
| 766 | resetLoadingMode(); |
| 767 | return false; |
| 768 | } else if ( null == isMarketingAllowed ) { |
| 769 | isMarketingAllowed = isMarketingAllowedByLicense[ licenseKey ]; |
| 770 | } |
| 771 | |
| 772 | data.is_marketing_allowed = isMarketingAllowed; |
| 773 | |
| 774 | data.is_extensions_tracking_allowed = isExtensionsTrackingAllowed; |
| 775 | |
| 776 | data.is_diagnostic_tracking_allowed = isDiagnosticTrackingAllowed; |
| 777 | } |
| 778 | |
| 779 | $marketingOptin.removeClass( 'error' ); |
| 780 | |
| 781 | if ( isNetworkActive ) { |
| 782 | var |
| 783 | sites = [], |
| 784 | applyOnAllSites = $applyOnAllSites.is( ':checked' ); |
| 785 | |
| 786 | $sitesListContainer.find( 'tr' ).each(function() { |
| 787 | var |
| 788 | $this = $( this ), |
| 789 | includeSite = ( ! requireLicenseKey || applyOnAllSites || $this.find( 'input' ).is( ':checked' ) ); |
| 790 | |
| 791 | if ( ! includeSite ) |
| 792 | return; |
| 793 | |
| 794 | var site = { |
| 795 | uid : $this.find( '.uid' ).val(), |
| 796 | url : $this.find( '.url' ).val(), |
| 797 | title : $this.find( '.title' ).val(), |
| 798 | language: $this.find( '.language' ).val(), |
| 799 | blog_id : $this.find( '.blog-id' ).find( 'span' ).text() |
| 800 | }; |
| 801 | |
| 802 | if ( ! requireLicenseKey) { |
| 803 | site.action = $this.find('.action.selected').data('action-type'); |
| 804 | } else if ( isNetworkDelegating ) { |
| 805 | site.action = 'delegate'; |
| 806 | } |
| 807 | |
| 808 | sites.push( site ); |
| 809 | }); |
| 810 | |
| 811 | data.sites = sites; |
| 812 | |
| 813 | if ( hasAnyInstall ) { |
| 814 | data.has_any_install = hasAnyInstall; |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | /** |
| 819 | * Use the AJAX opt-in when license key is required to potentially |
| 820 | * process the after install failure hook. |
| 821 | * |
| 822 | * @author Vova Feldman (@svovaf) |
| 823 | * @since 1.2.1.5 |
| 824 | */ |
| 825 | $.ajax({ |
| 826 | url : <?php echo Freemius::ajax_url() ?>, |
| 827 | method : 'POST', |
| 828 | data : data, |
| 829 | success: function (result) { |
| 830 | var resultObj = $.parseJSON(result); |
| 831 | if (resultObj.success) { |
| 832 | // Redirect to the "Account" page and sync the license. |
| 833 | window.location.href = resultObj.next_page; |
| 834 | } else { |
| 835 | resetLoadingMode(); |
| 836 | |
| 837 | // Show error. |
| 838 | $('.fs-content').prepend('<div class="fs-error">' + (resultObj.error.message ? resultObj.error.message : resultObj.error) + '</div>'); |
| 839 | } |
| 840 | }, |
| 841 | error: function () { |
| 842 | resetLoadingMode(); |
| 843 | } |
| 844 | }); |
| 845 | |
| 846 | return false; |
| 847 | } |
| 848 | else { |
| 849 | if (null == $licenseSecret) { |
| 850 | $licenseSecret = $('<input type="hidden" name="license_secret_key" value="" />'); |
| 851 | $form.append($licenseSecret); |
| 852 | } |
| 853 | |
| 854 | // Update secret key if premium only plugin. |
| 855 | $licenseSecret.val($licenseKeyInput.val()); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | return true; |
| 860 | }); |
| 861 | |
| 862 | $( '#fs_connect .fs-permissions .fs-switch' ).on( 'click', function () { |
| 863 | $( this ) |
| 864 | .toggleClass( 'fs-on' ) |
| 865 | .toggleClass( 'fs-off' ); |
| 866 | |
| 867 | $( this ).closest( '.fs-permission' ) |
| 868 | .toggleClass( 'fs-disabled' ); |
| 869 | }); |
| 870 | |
| 871 | $primaryCta.on('click', function () { |
| 872 | console.log('Primary button was clicked'); |
| 873 | |
| 874 | $(this).addClass('fs-loading'); |
| 875 | $(this).html('<?php echo esc_js( $is_pending_activation ? |
| 876 | fs_text_x_inline( 'Sending email', 'as in the process of sending an email', 'sending-email', $slug ) : |
| 877 | fs_text_x_inline( 'Activating', 'as activating plugin', 'activating', $slug ) |
| 878 | ) ?>...'); |
| 879 | }); |
| 880 | |
| 881 | $('.fs-permissions .fs-trigger').on('click', function () { |
| 882 | $('.fs-permissions').toggleClass('fs-open'); |
| 883 | |
| 884 | return false; |
| 885 | }); |
| 886 | |
| 887 | if (requireLicenseKey) { |
| 888 | /** |
| 889 | * Submit license key on enter. |
| 890 | * |
| 891 | * @author Vova Feldman (@svovaf) |
| 892 | * @since 1.1.9 |
| 893 | */ |
| 894 | $licenseKeyInput.keypress(function (e) { |
| 895 | if (e.which == 13) { |
| 896 | if ('' !== $(this).val()) { |
| 897 | $primaryCta.click(); |
| 898 | return false; |
| 899 | } |
| 900 | } |
| 901 | }); |
| 902 | |
| 903 | /** |
| 904 | * Disable activation button when empty license key. |
| 905 | * |
| 906 | * @author Vova Feldman (@svovaf) |
| 907 | * @since 1.1.9 |
| 908 | */ |
| 909 | $licenseKeyInput.on('keyup paste delete cut', function () { |
| 910 | setTimeout(function () { |
| 911 | var key = $licenseKeyInput.val(); |
| 912 | |
| 913 | if (key == previousLicenseKey){ |
| 914 | return; |
| 915 | } |
| 916 | |
| 917 | if ('' === key) { |
| 918 | $primaryCta.attr('disabled', 'disabled'); |
| 919 | $marketingOptin.hide(); |
| 920 | } else { |
| 921 | $primaryCta.prop('disabled', false); |
| 922 | |
| 923 | if (32 <= key.length){ |
| 924 | fetchIsMarketingAllowedFlagAndToggleOptin(); |
| 925 | } else { |
| 926 | $marketingOptin.hide(); |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | previousLicenseKey = key; |
| 931 | }, 100); |
| 932 | }).focus(); |
| 933 | } |
| 934 | |
| 935 | /** |
| 936 | * Set license mode trigger URL. |
| 937 | * |
| 938 | * @author Vova Feldman (@svovaf) |
| 939 | * @since 1.1.9 |
| 940 | */ |
| 941 | var |
| 942 | $connectLicenseModeTrigger = $('#fs_connect .fs-freemium-licensing a'), |
| 943 | href = window.location.href; |
| 944 | |
| 945 | if (href.indexOf('?') > 0) { |
| 946 | href += '&'; |
| 947 | } else { |
| 948 | href += '?'; |
| 949 | } |
| 950 | |
| 951 | if ($connectLicenseModeTrigger.length > 0) { |
| 952 | $connectLicenseModeTrigger.attr( |
| 953 | 'href', |
| 954 | href + 'require_license=' + $connectLicenseModeTrigger.attr('data-require-license') |
| 955 | ); |
| 956 | } |
| 957 | |
| 958 | //-------------------------------------------------------------------------------- |
| 959 | //region GDPR |
| 960 | //-------------------------------------------------------------------------------- |
| 961 | var isMarketingAllowedByLicense = {}, |
| 962 | $marketingOptin = $('#fs_marketing_optin'), |
| 963 | previousLicenseKey = null; |
| 964 | |
| 965 | if (requireLicenseKey) { |
| 966 | |
| 967 | var |
| 968 | afterMarketingFlagLoaded = function () { |
| 969 | var licenseKey = $licenseKeyInput.val(); |
| 970 | |
| 971 | if (null == isMarketingAllowedByLicense[licenseKey]) { |
| 972 | $marketingOptin.show(); |
| 973 | |
| 974 | if ($marketingOptin.find('input[type=radio]:checked').length > 0){ |
| 975 | // Focus on button if GDPR opt-in already selected is already selected. |
| 976 | $primaryCta.focus(); |
| 977 | } else { |
| 978 | // Focus on the GDPR opt-in radio button. |
| 979 | $($marketingOptin.find('input[type=radio]')[0]).focus(); |
| 980 | } |
| 981 | } else { |
| 982 | $marketingOptin.hide(); |
| 983 | $primaryCta.focus(); |
| 984 | } |
| 985 | }, |
| 986 | /** |
| 987 | * @author Leo Fajardo (@leorw) |
| 988 | * @since 2.1.0 |
| 989 | */ |
| 990 | fetchIsMarketingAllowedFlagAndToggleOptin = function () { |
| 991 | var licenseKey = $licenseKeyInput.val(); |
| 992 | |
| 993 | if (licenseKey.length < 32) { |
| 994 | $marketingOptin.hide(); |
| 995 | return; |
| 996 | } |
| 997 | |
| 998 | if (isMarketingAllowedByLicense.hasOwnProperty(licenseKey)) { |
| 999 | afterMarketingFlagLoaded(); |
| 1000 | return; |
| 1001 | } |
| 1002 | |
| 1003 | $marketingOptin.hide(); |
| 1004 | |
| 1005 | setLoadingMode(); |
| 1006 | |
| 1007 | $primaryCta.addClass('fs-loading'); |
| 1008 | $primaryCta.attr('disabled', 'disabled'); |
| 1009 | $primaryCta.html('<?php fs_esc_js_echo_inline( 'Please wait', 'please-wait', $slug ) ?>...'); |
| 1010 | |
| 1011 | $.ajax({ |
| 1012 | url : <?php echo Freemius::ajax_url() ?>, |
| 1013 | method : 'POST', |
| 1014 | data : { |
| 1015 | action : '<?php echo $fs->get_ajax_action( 'fetch_is_marketing_required_flag_value' ) ?>', |
| 1016 | security : '<?php echo $fs->get_ajax_security( 'fetch_is_marketing_required_flag_value' ) ?>', |
| 1017 | license_key: licenseKey, |
| 1018 | module_id : '<?php echo $fs->get_id() ?>' |
| 1019 | }, |
| 1020 | success: function (result) { |
| 1021 | resetLoadingMode(); |
| 1022 | |
| 1023 | if (result.success) { |
| 1024 | result = result.data; |
| 1025 | |
| 1026 | // Cache result. |
| 1027 | isMarketingAllowedByLicense[licenseKey] = result.is_marketing_allowed; |
| 1028 | } |
| 1029 | |
| 1030 | afterMarketingFlagLoaded(); |
| 1031 | } |
| 1032 | }); |
| 1033 | }; |
| 1034 | |
| 1035 | $marketingOptin.find( 'input' ).click(function() { |
| 1036 | $marketingOptin.removeClass( 'error' ); |
| 1037 | }); |
| 1038 | } |
| 1039 | |
| 1040 | //endregion |
| 1041 | })(jQuery); |
| 1042 | </script> |
| 1043 | <?php |
| 1044 | fs_require_once_template( 'api-connectivity-message-js.php' ); |