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