PluginProbe
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder / 1.5
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder v1.5
3.6.0 3.5.0 trunk 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.6.1 1.0.7 1.0.8 1.0.9 1.1 1.1.1 1.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5 1.5.1 All 110 releases
buttonizer-multifunctional-button / freemius / templates / connect.php

connect.php in Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder 1.5, at freemius/templates/connect.php

737 lines 28.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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_site_url = $freemius_site_www . '/' . ( $fs->is_premium() ?
44 'wordpress/' :
45 // Insights platform information.
46 'wordpress/usage-tracking/' . $fs->get_id() . "/{$slug}/" );
47
48 if ( $fs->is_premium() ) {
49 $freemius_site_url .= '?' . http_build_query( array(
50 'id' => $fs->get_id(),
51 'slug' => $slug,
52 ) );
53 }
54
55 $freemius_link = '<a href="' . $freemius_site_url . '" target="_blank" tabindex="1">freemius.com</a>';
56
57 $error = fs_request_get( 'error' );
58
59 $require_license_key = $is_premium_only ||
60 ( $is_freemium && $is_premium_code && fs_request_get_bool( 'require_license', true ) );
61
62 if ( $is_pending_activation ) {
63 $require_license_key = false;
64 }
65
66 if ( $require_license_key ) {
67 $fs->_add_license_activation_dialog_box();
68 }
69
70 $is_optin_dialog = (
71 $fs->is_theme() &&
72 $fs->is_themes_page() &&
73 ( ! $fs->has_settings_menu() || $fs->is_free_wp_org_theme() )
74 );
75
76 if ( $is_optin_dialog ) {
77 $show_close_button = false;
78 $previous_theme_activation_url = '';
79
80 if ( ! $is_premium_code ) {
81 $show_close_button = true;
82 } else if ( $is_premium_only ) {
83 $previous_theme_activation_url = $fs->get_previous_theme_activation_url();
84 $show_close_button = ( ! empty( $previous_theme_activation_url ) );
85 }
86 }
87
88 $is_network_level_activation = (
89 fs_is_network_admin() &&
90 $fs->is_network_active() &&
91 ! $fs->is_network_delegated_connection()
92 );
93
94 $fs_user = Freemius::_get_user_by_email( $current_user->user_email );
95
96 $activate_with_current_user = (
97 is_object( $fs_user ) &&
98 ! $is_pending_activation &&
99 // If requires a license for activation, use the user associated with the license for the opt-in.
100 ! $require_license_key &&
101 ! $is_network_level_activation
102 );
103
104 $optin_params = $fs->get_opt_in_params( array(), $is_network_level_activation );
105 $sites = isset( $optin_params['sites'] ) ? $optin_params['sites'] : array();
106
107 $is_network_upgrade_mode = ( fs_is_network_admin() && $fs->is_network_upgrade_mode() );
108
109 /* translators: %s: name (e.g. Hey John,) */
110 $hey_x_text = esc_html( sprintf( fs_text_x_inline( 'Hey %s,', 'greeting', 'hey-x', $slug ), $first_name ) );
111 ?>
112 <?php
113 if ( $is_optin_dialog ) { ?>
114 <div id="fs_theme_connect_wrapper">
115 <?php
116 if ( $show_close_button ) { ?>
117 <button class="close dashicons dashicons-no"><span class="screen-reader-text">Close connect dialog</span>
118 </button>
119 <?php
120 }
121 ?>
122 <?php
123 }
124 ?>
125 <div id="fs_connect"
126 class="wrap<?php if ( ! fs_is_network_admin() && ( ! $fs->is_enable_anonymous() || $is_pending_activation || $require_license_key ) ) {
127 echo ' fs-anonymous-disabled';
128 } ?><?php echo $require_license_key ? ' require-license-key' : '' ?>">
129 <div class="fs-visual">
130 <b class="fs-site-icon"><i class="dashicons dashicons-wordpress"></i></b>
131 <i class="dashicons dashicons-plus fs-first"></i>
132 <?php
133 $vars = array( 'id' => $fs->get_id() );
134 fs_require_once_template( 'plugin-icon.php', $vars );
135 ?>
136 <i class="dashicons dashicons-plus fs-second"></i>
137 <img class="fs-connect-logo" width="80" height="80" src="//img.freemius.com/connect-logo.png"/>
138 </div>
139 <div class="fs-content">
140 <?php if ( ! empty( $error ) ) : ?>
141 <p class="fs-error"><?php echo esc_html( $error ) ?></p>
142 <?php endif ?>
143 <p><?php
144 $button_label = fs_text_inline( 'Allow & Continue', 'opt-in-connect', $slug );
145 $message = '';
146
147 if ( $is_pending_activation ) {
148 $button_label = fs_text_inline( 'Re-send activation email', 'resend-activation-email', $slug );
149
150 $message = $fs->apply_filters( 'pending_activation_message', sprintf(
151 /* translators: %s: name (e.g. Thanks John!) */
152 fs_text_inline( 'Thanks %s!', 'thanks-x', $slug ) . '<br>' .
153 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 ),
154 $first_name,
155 '<b>' . $fs->get_plugin_name() . '</b>',
156 '<b>' . $current_user->user_email . '</b>',
157 fs_text_inline( 'complete the install', 'complete-the-install', $slug )
158 ) );
159 } else if ( $require_license_key ) {
160 $button_label = $is_network_upgrade_mode ?
161 fs_text_inline( 'Activate License', 'agree-activate-license', $slug ) :
162 fs_text_inline( 'Agree & Activate License', 'agree-activate-license', $slug );
163
164 $message = $fs->apply_filters(
165 'connect-message_on-premium',
166 ($is_network_upgrade_mode ?
167 '' :
168 /* translators: %s: name (e.g. Hey John,) */
169 $hey_x_text . '<br>'
170 ) .
171 sprintf( fs_text_inline( 'Thanks for purchasing %s! To get started, please enter your license key:', 'thanks-for-purchasing', $slug ), '<b>' . $fs->get_plugin_name() . '</b>' ),
172 $first_name,
173 $fs->get_plugin_name()
174 );
175 } else {
176 $filter = 'connect_message';
177 $default_optin_message = 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);;
178
179 if ( $fs->is_plugin_update() ) {
180 // If Freemius was added on a plugin update, set different
181 // opt-in message.
182 $default_optin_message = fs_text_inline( 'Please help us improve %1$s! If you opt in, some data about your usage of %1$s will be sent to %4$s. If you skip this, that\'s okay! %1$s will still work just fine.', 'connect-message_on-update', $slug );
183
184 // If user customized the opt-in message on update, use
185 // that message. Otherwise, fallback to regular opt-in
186 // custom message if exist.
187 if ( $fs->has_filter( 'connect_message_on_update' ) ) {
188 $filter = 'connect_message_on_update';
189 }
190 }
191
192 $message = $fs->apply_filters(
193 $filter,
194 ($is_network_upgrade_mode ?
195 '' :
196 /* translators: %s: name (e.g. Hey John,) */
197 $hey_x_text . '<br>'
198 ) .
199 sprintf(
200 esc_html( $default_optin_message ),
201 '<b>' . esc_html( $fs->get_plugin_name() ) . '</b>',
202 '<b>' . $current_user->user_login . '</b>',
203 '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
204 $freemius_link
205 ),
206 $first_name,
207 $fs->get_plugin_name(),
208 $current_user->user_login,
209 '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
210 $freemius_link
211 );
212 }
213
214 if ( $is_network_upgrade_mode ) {
215 $network_integration_text = esc_html( fs_text_inline( 'We\'re excited to introduce the Freemius network-level integration.', 'connect_message_network_upgrade', $slug ) );
216
217 if ($is_premium_code){
218 $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 ) );
219
220 $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(
221 /* translators: %s: module type (plugin, theme, or add-on) */
222 fs_text_inline( "%s's paid features", 'x-paid-features', $slug ),
223 $fs->get_module_label( true )
224 ) );
225
226 /* translators: %s: module type (plugin, theme, or add-on) */
227 $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 ) );
228 }else {
229 $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 );
230 }
231 }
232
233 echo $message;
234 ?></p>
235 <?php if ( $require_license_key ) : ?>
236 <div class="fs-license-key-container">
237 <input id="fs_license_key" name="fs_key" type="text" required maxlength="32"
238 placeholder="<?php fs_esc_attr_echo_inline( 'License key', 'license-key', $slug ) ?>" tabindex="1"/>
239 <i class="dashicons dashicons-admin-network"></i>
240 <a class="show-license-resend-modal show-license-resend-modal-<?php echo $fs->get_unique_affix() ?>"
241 href="#"><?php fs_esc_html_echo_inline( "Can't find your license key?", 'cant-find-license-key', $slug ); ?></a>
242 </div>
243 <?php endif ?>
244 <?php if ( $is_network_level_activation ) : ?>
245 <?php
246 $vars = array(
247 'id' => $fs->get_id(),
248 'sites' => $sites,
249 'require_license_key' => $require_license_key
250 );
251
252 echo fs_get_template( 'partials/network-activation.php', $vars );
253 ?>
254 <?php endif ?>
255 </div>
256 <div class="fs-actions">
257 <?php if ( $fs->is_enable_anonymous() && ! $is_pending_activation && ( ! $require_license_key || $is_network_upgrade_mode ) ) : ?>
258 <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' ) ?>"
259 class="button button-secondary" tabindex="2"><?php fs_esc_html_echo_x_inline( 'Skip', 'verb', 'skip', $slug ) ?></a>
260 <?php endif ?>
261 <?php if ( $is_network_level_activation ) : ?>
262 <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>
263 <?php endif ?>
264 <?php if ( $activate_with_current_user ) : ?>
265 <form action="" method="POST">
266 <input type="hidden" name="fs_action"
267 value="<?php echo $fs->get_unique_affix() ?>_activate_existing">
268 <?php wp_nonce_field( 'activate_existing_' . $fs->get_public_key() ) ?>
269 <button class="button button-primary" tabindex="1"
270 type="submit"><?php echo esc_html( $button_label ) ?></button>
271 </form>
272 <?php else : ?>
273 <form method="post" action="<?php echo WP_FS__ADDRESS ?>/action/service/user/install/">
274 <?php unset( $optin_params['sites']); ?>
275 <?php foreach ( $optin_params as $name => $value ) : ?>
276 <input type="hidden" name="<?php echo $name ?>" value="<?php echo esc_attr( $value ) ?>">
277 <?php endforeach ?>
278 <button class="button button-primary" tabindex="1"
279 type="submit"<?php if ( $require_license_key ) {
280 echo ' disabled="disabled"';
281 } ?>><?php echo esc_html( $button_label ) ?></button>
282 </form>
283 <?php endif ?>
284 </div><?php
285
286 // Set core permission list items.
287 $permissions = array(
288 'profile' => array(
289 'icon-class' => 'dashicons dashicons-admin-users',
290 'label' => $fs->get_text_inline( 'Your Profile Overview', 'permissions-profile' ),
291 'desc' => $fs->get_text_inline( 'Name and email address', 'permissions-profile_desc' ),
292 'priority' => 5,
293 ),
294 'site' => array(
295 'icon-class' => 'dashicons dashicons-admin-settings',
296 'label' => $fs->get_text_inline( 'Your Site Overview', 'permissions-site' ),
297 'desc' => $fs->get_text_inline( 'Site URL, WP version, PHP info, plugins & themes', 'permissions-site_desc' ),
298 'priority' => 10,
299 ),
300 'notices' => array(
301 'icon-class' => 'dashicons dashicons-testimonial',
302 'label' => $fs->get_text_inline( 'Admin Notices', 'permissions-admin-notices' ),
303 'desc' => $fs->get_text_inline( 'Updates, announcements, marketing, no spam', 'permissions-newsletter_desc' ),
304 'priority' => 13,
305 ),
306 'events' => array(
307 'icon-class' => 'dashicons dashicons-admin-plugins',
308 'label' => sprintf( $fs->get_text_inline( 'Current %s Events', 'permissions-events' ), ucfirst( $fs->get_module_type() ) ),
309 'desc' => $fs->get_text_inline( 'Activation, deactivation and uninstall', 'permissions-events_desc' ),
310 'priority' => 20,
311 ),
312 // 'plugins_themes' => array(
313 // 'icon-class' => 'dashicons dashicons-admin-settings',
314 // 'label' => fs_text_inline( 'Plugins & Themes', 'permissions-plugins_themes' ),
315 // 'desc' => fs_text_inline( 'Titles, versions and state.', 'permissions-plugins_themes_desc' ),
316 // 'priority' => 30,
317 // ),
318 );
319
320 // Add newsletter permissions if enabled.
321 if ( $fs->is_permission_requested( 'newsletter' ) ) {
322 $permissions['newsletter'] = array(
323 'icon-class' => 'dashicons dashicons-email-alt',
324 'label' => $fs->get_text_inline( 'Newsletter', 'permissions-newsletter' ),
325 'desc' => $fs->get_text_inline( 'Updates, announcements, marketing, no spam', 'permissions-newsletter_desc' ),
326 'priority' => 15,
327 );
328 }
329
330 // Allow filtering of the permissions list.
331 $permissions = $fs->apply_filters( 'permission_list', $permissions );
332
333 // Sort by priority.
334 uasort( $permissions, 'fs_sort_by_priority' );
335
336 if ( ! empty( $permissions ) ) : ?>
337 <div class="fs-permissions">
338 <?php if ( $require_license_key ) : ?>
339 <p class="fs-license-sync-disclaimer"><?php
340 echo sprintf(
341 fs_esc_html_inline( 'The %1$s will be periodically sending data to %2$s to check for security and feature updates, and verify the validity of your license.', 'license-sync-disclaimer', $slug ),
342 $fs->get_module_label( true ),
343 $freemius_link
344 ) ?></p>
345 <?php endif ?>
346 <a class="fs-trigger" href="#" tabindex="1"><?php fs_esc_html_echo_inline( 'What permissions are being granted?', 'what-permissions', $slug ) ?></a>
347 <ul><?php
348 foreach ( $permissions as $id => $permission ) : ?>
349 <li id="fs-permission-<?php echo esc_attr( $id ); ?>"
350 class="fs-permission fs-<?php echo esc_attr( $id ); ?>">
351 <i class="<?php echo esc_attr( $permission['icon-class'] ); ?>"></i>
352
353 <div>
354 <span><?php echo esc_html( $permission['label'] ); ?></span>
355
356 <p><?php echo esc_html( $permission['desc'] ); ?></p>
357 </div>
358 </li>
359 <?php endforeach; ?>
360 </ul>
361 </div>
362 <?php endif ?>
363 <?php if ( $is_premium_code && $is_freemium ) : ?>
364 <div class="fs-freemium-licensing">
365 <p>
366 <?php if ( $require_license_key ) : ?>
367 <?php fs_esc_html_echo_inline( 'Don\'t have a license key?', 'dont-have-license-key', $slug ) ?>
368 <a data-require-license="false" tabindex="1"><?php fs_esc_html_echo_inline( 'Activate Free Version', 'activate-free-version', $slug ) ?></a>
369 <?php else : ?>
370 <?php fs_echo_inline( 'Have a license key?', 'have-license-key', $slug ) ?>
371 <a data-require-license="true" tabindex="1"><?php fs_esc_html_echo_inline( 'Activate License', 'activate-license', $slug ) ?></a>
372 <?php endif ?>
373 </p>
374 </div>
375 <?php endif ?>
376 <div class="fs-terms">
377 <a href="https://freemius.com/privacy/" target="_blank"
378 tabindex="1"><?php fs_esc_html_echo_inline( 'Privacy Policy', 'privacy-policy', $slug ) ?></a>
379 &nbsp;&nbsp;-&nbsp;&nbsp;
380 <a href="<?php echo $freemius_site_www ?>/terms/" target="_blank" tabindex="1"><?php fs_echo_inline( 'Terms of Service', 'tos', $slug ) ?></a>
381 </div>
382 </div>
383 <?php
384 if ( $is_optin_dialog ) { ?>
385 </div>
386 <?php
387 }
388 ?>
389 <script type="text/javascript">
390 (function ($) {
391 var $html = $('html');
392
393 <?php
394 if ( $is_optin_dialog ) {
395 if ( $show_close_button ) { ?>
396 var $themeConnectWrapper = $('#fs_theme_connect_wrapper');
397
398 $themeConnectWrapper.find('button.close').on('click', function () {
399 <?php if ( ! empty( $previous_theme_activation_url ) ) { ?>
400 location.href = '<?php echo html_entity_decode( $previous_theme_activation_url ); ?>';
401 <?php } else { ?>
402 $themeConnectWrapper.remove();
403 $html.css({overflow: $html.attr('fs-optin-overflow')});
404 <?php } ?>
405 });
406 <?php
407 }
408 ?>
409
410 $html.attr('fs-optin-overflow', $html.css('overflow'));
411 $html.css({overflow: 'hidden'});
412
413 <?php
414 }
415 ?>
416
417 var $primaryCta = $('.fs-actions .button.button-primary'),
418 $form = $('.fs-actions form'),
419 isNetworkActive = <?php echo $is_network_level_activation ? 'true' : 'false' ?>,
420 requireLicenseKey = <?php echo $require_license_key ? 'true' : 'false' ?>,
421 hasContextUser = <?php echo $activate_with_current_user ? 'true' : 'false' ?>,
422 isNetworkUpgradeMode = <?php echo $is_network_upgrade_mode ? 'true' : 'false' ?>,
423 $licenseSecret,
424 $licenseKeyInput = $('#fs_license_key'),
425 pauseCtaLabelUpdate = false;
426
427 $('.fs-actions .button').on('click', function () {
428 // Set loading mode.
429 $(document.body).css({'cursor': 'wait'});
430
431 var $this = $(this);
432 $this.css({'cursor': 'wait'});
433
434 setTimeout(function () {
435 $this.attr('disabled', 'disabled');
436 }, 200);
437 });
438
439 if ( isNetworkActive ) {
440 var
441 $multisiteOptionsContainer = $( '#multisite_options_container' ),
442 $allSitesOptions = $( '#all_sites_options' ),
443 $applyOnAllSites = $( '#apply_on_all_sites' ),
444 $sitesListContainer = $( '#sites_list_container' ),
445 totalSites = <?php echo count( $sites ) ?>,
446 maxSitesListHeight = null,
447 $skipActivationButton = $( '#skip_activation' ),
448 $delegateToSiteAdminsButton = $( '#delegate_to_site_admins' );
449
450 $applyOnAllSites.click(function() {
451 var isChecked = $( this ).is( ':checked' );
452
453 if ( ! isChecked ) {
454 $multisiteOptionsContainer.find( '.action-allow' ).addClass( 'selected' );
455 } else {
456 $multisiteOptionsContainer.find( '.action' ).removeClass( 'selected' );
457 updatePrimaryCtaText( 'allow' );
458 }
459
460 $skipActivationButton.toggle();
461
462 $delegateToSiteAdminsButton.toggle();
463
464 $multisiteOptionsContainer.toggleClass( 'apply-on-all-sites', isChecked );
465
466 $sitesListContainer.toggle( ! isChecked );
467 if ( ! isChecked && null === maxSitesListHeight ) {
468 /**
469 * Set the visible number of rows to 5 (5 * height of the first row).
470 *
471 * @author Leo Fajardo (@leorw)
472 */
473 maxSitesListHeight = ( 5 * $sitesListContainer.find( 'tr:first' ).height() );
474 $sitesListContainer.css( 'max-height', maxSitesListHeight );
475 }
476 });
477
478 $allSitesOptions.find( '.action' ).click(function( evt ) {
479 var actionType = $( evt.target ).data( 'action-type' );
480
481 $multisiteOptionsContainer.find( '.action' ).removeClass( 'selected' );
482 $multisiteOptionsContainer.find( '.action-' + actionType ).toggleClass( 'selected' );
483
484 updatePrimaryCtaText( actionType );
485 });
486
487 $sitesListContainer.delegate( '.action', 'click', function( evt ) {
488 var $this = $( evt.target );
489 if ( $this.hasClass( 'selected' ) ) {
490 return false;
491 }
492
493 $this.parents( 'tr:first' ).find( '.action' ).removeClass( 'selected' );
494 $this.toggleClass( 'selected' );
495
496 var
497 singleSiteActionType = $this.data( 'action-type' ),
498 totalSelected = $sitesListContainer.find( '.action-' + singleSiteActionType + '.selected' ).length;
499
500 $allSitesOptions.find( '.action.selected' ).removeClass( 'selected' );
501
502 if ( totalSelected === totalSites ) {
503 $allSitesOptions.find( '.action-' + singleSiteActionType ).addClass( 'selected' );
504
505 updatePrimaryCtaText( singleSiteActionType );
506 } else {
507 updatePrimaryCtaText( 'mixed' );
508 }
509 });
510
511 if (isNetworkUpgradeMode) {
512 $skipActivationButton.click(function(){
513 $delegateToSiteAdminsButton.hide();
514
515 $skipActivationButton.html('<?php fs_esc_js_echo_inline( 'Skipping, please wait', 'skipping-wait', $slug ) ?>...');
516
517 pauseCtaLabelUpdate = true;
518
519 // Check all sites to be skipped.
520 $allSitesOptions.find('.action.action-skip').click();
521
522 $form.submit();
523
524 pauseCtaLabelUpdate = false;
525
526 return false;
527 });
528
529 $delegateToSiteAdminsButton.click(function(){
530 $delegateToSiteAdminsButton.html('<?php fs_esc_js_echo_inline( 'Delegating, please wait', 'delegating-wait', $slug ) ?>...');
531
532 pauseCtaLabelUpdate = true;
533
534 // Check all sites to be skipped.
535 $allSitesOptions.find('.action.action-delegate').click();
536
537 $form.submit();
538
539 pauseCtaLabelUpdate = false;
540
541 return false;
542 });
543 }
544 }
545
546 /**
547 * @author Leo Fajardo (@leorw)
548 */
549 function updatePrimaryCtaText( actionType ) {
550 if (pauseCtaLabelUpdate)
551 return;
552
553 var text = '<?php fs_esc_js_echo_inline( 'Continue', 'continue', $slug ) ?>';
554
555 switch ( actionType ) {
556 case 'allow':
557 text = '<?php fs_esc_js_echo_inline( 'Allow & Continue', 'opt-in-connect', $slug ) ?>';
558 break;
559 case 'delegate':
560 text = '<?php fs_esc_js_echo_inline( 'Delegate to Site Admins & Continue', 'delegate-to-site-admins-and-continue', $slug ) ?>';
561 break;
562 case 'skip':
563 text = '<?php fs_esc_js_echo_x_inline( 'Skip', 'verb', 'skip', $slug ) ?>';
564 break;
565 }
566
567 $primaryCta.html( text );
568 }
569
570 var ajaxOptin = ( requireLicenseKey || isNetworkActive );
571
572 $form.on('submit', function () {
573 /**
574 * @author Vova Feldman (@svovaf)
575 * @since 1.1.9
576 */
577 if ( ajaxOptin ) {
578 if (!hasContextUser || isNetworkUpgradeMode) {
579 <?php $action = $require_license_key ? 'activate_license' : 'network_activate' ?>
580
581 $('.fs-error').remove();
582
583 var data = {
584 action : '<?php echo $fs->get_ajax_action( $action ) ?>',
585 security : '<?php echo $fs->get_ajax_security( $action ) ?>',
586 license_key: $licenseKeyInput.val(),
587 module_id : '<?php echo $fs->get_id() ?>'
588 };
589
590 if ( isNetworkActive ) {
591 var
592 sites = [],
593 applyOnAllSites = $applyOnAllSites.is( ':checked' );
594
595 $sitesListContainer.find( 'tr' ).each(function() {
596 var
597 $this = $( this ),
598 includeSite = ( ! requireLicenseKey || applyOnAllSites || $this.find( 'input' ).is( ':checked' ) );
599
600 if ( ! includeSite )
601 return;
602
603 var site = {
604 uid : $this.find( '.uid' ).val(),
605 url : $this.find( '.url' ).val(),
606 title : $this.find( '.title' ).val(),
607 language: $this.find( '.language' ).val(),
608 charset : $this.find( '.charset' ).val(),
609 blog_id : $this.find( '.blog-id' ).find( 'span' ).text()
610 };
611
612 if ( ! requireLicenseKey) {
613 site.action = $this.find('.action.selected').data('action-type');
614 }
615
616 sites.push( site );
617 });
618
619 data.sites = sites;
620 }
621
622 /**
623 * Use the AJAX opt-in when license key is required to potentially
624 * process the after install failure hook.
625 *
626 * @author Vova Feldman (@svovaf)
627 * @since 1.2.1.5
628 */
629 $.ajax({
630 url : ajaxurl,
631 method : 'POST',
632 data : data,
633 success: function (result) {
634 var resultObj = $.parseJSON(result);
635 if (resultObj.success) {
636 // Redirect to the "Account" page and sync the license.
637 window.location.href = resultObj.next_page;
638 } else {
639 // Show error.
640 $('.fs-content').prepend('<p class="fs-error">' + (resultObj.error.message ? resultObj.error.message : resultObj.error) + '</p>');
641
642 // Reset loading mode.
643 $primaryCta.removeClass('fs-loading').css({'cursor': 'auto'});
644 $primaryCta.html('<?php echo esc_js( $button_label ) ?>');
645 $primaryCta.prop('disabled', false);
646 $(document.body).css({'cursor': 'auto'});
647 }
648 }
649 });
650
651 return false;
652 }
653 else {
654 if (null == $licenseSecret) {
655 $licenseSecret = $('<input type="hidden" name="license_secret_key" value="" />');
656 $form.append($licenseSecret);
657 }
658
659 // Update secret key if premium only plugin.
660 $licenseSecret.val($licenseKeyInput.val());
661 }
662 }
663
664 return true;
665 });
666
667 $primaryCta.on('click', function () {
668 $(this).addClass('fs-loading');
669 $(this).html('<?php echo esc_js( $is_pending_activation ?
670 fs_text_x_inline( 'Sending email', 'as in the process of sending an email', 'sending-email', $slug ) :
671 fs_text_x_inline( 'Activating', 'as activating plugin', 'activating', $slug )
672 ) ?>...');
673 });
674
675 $('.fs-permissions .fs-trigger').on('click', function () {
676 $('.fs-permissions').toggleClass('fs-open');
677
678 return false;
679 });
680
681 if (requireLicenseKey) {
682 /**
683 * Submit license key on enter.
684 *
685 * @author Vova Feldman (@svovaf)
686 * @since 1.1.9
687 */
688 $licenseKeyInput.keypress(function (e) {
689 if (e.which == 13) {
690 if ('' !== $(this).val()) {
691 $primaryCta.click();
692 return false;
693 }
694 }
695 });
696
697 /**
698 * Disable activation button when empty license key.
699 *
700 * @author Vova Feldman (@svovaf)
701 * @since 1.1.9
702 */
703 $licenseKeyInput.on('keyup paste delete cut', function () {
704 setTimeout(function () {
705 if ('' === $licenseKeyInput.val()) {
706 $primaryCta.attr('disabled', 'disabled');
707 } else {
708 $primaryCta.prop('disabled', false);
709 }
710 }, 100);
711 }).focus();
712 }
713
714 /**
715 * Set license mode trigger URL.
716 *
717 * @author Vova Feldman (@svovaf)
718 * @since 1.1.9
719 */
720 var
721 $connectLicenseModeTrigger = $('#fs_connect .fs-freemium-licensing a'),
722 href = window.location.href;
723
724 if (href.indexOf('?') > 0) {
725 href += '&';
726 } else {
727 href += '?';
728 }
729
730 if ($connectLicenseModeTrigger.length > 0) {
731 $connectLicenseModeTrigger.attr(
732 'href',
733 href + 'require_license=' + $connectLicenseModeTrigger.attr('data-require-license')
734 );
735 }
736 })(jQuery);
737 </script>