PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / 1.2.0
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels v1.2.0
2.9.1 2.9.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 2.0.0 2.1.0 2.2.0 2.3.2 2.3.3 2.3.5 2.3.6 2.3.8 2.3.9 2.4.3 All 37 releases
automatic-youtube-gallery / freemius / templates / connect.php

connect.php in Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels 1.2.0, at freemius/templates/connect.php

971 lines 39.3 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_usage_tracking_url = $freemius_site_www . '/wordpress/usage-tracking/' . $fs->get_id() . "/{$slug}/";
44 $freemius_plugin_terms_url = $freemius_site_www . '/terms/' . $fs->get_id() . "/{$slug}/";
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" 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->has_settings_menu() || $fs->is_free_wp_org_theme() )
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 <div id="fs_connect"
136 class="wrap<?php if ( ! fs_is_network_admin() && ( ! $fs->is_enable_anonymous() || $is_pending_activation || $require_license_key ) ) {
137 echo ' fs-anonymous-disabled';
138 } ?><?php echo $require_license_key ? ' require-license-key' : '' ?>">
139 <div class="fs-visual">
140 <b class="fs-site-icon"><i class="dashicons dashicons-wordpress"></i></b>
141 <i class="dashicons dashicons-plus fs-first"></i>
142 <?php
143 $vars = array( 'id' => $fs->get_id() );
144 fs_require_once_template( 'plugin-icon.php', $vars );
145 ?>
146 <i class="dashicons dashicons-plus fs-second"></i>
147 <img class="fs-connect-logo" width="80" height="80" src="//img.freemius.com/connect-logo.png"/>
148 </div>
149 <div class="fs-content">
150 <?php if ( ! empty( $error ) ) : ?>
151 <p class="fs-error"><?php echo esc_html( $error ) ?></p>
152 <?php endif ?>
153 <p><?php
154 $button_label = fs_text_inline( 'Allow & Continue', 'opt-in-connect', $slug );
155 $message = '';
156
157 if ( $is_pending_activation ) {
158 $button_label = fs_text_inline( 'Re-send activation email', 'resend-activation-email', $slug );
159
160 $message = $fs->apply_filters( 'pending_activation_message', sprintf(
161 /* translators: %s: name (e.g. Thanks John!) */
162 fs_text_inline( 'Thanks %s!', 'thanks-x', $slug ) . '<br>' .
163 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 ),
164 $first_name,
165 '<b>' . $fs->get_plugin_name() . '</b>',
166 '<b>' . $current_user->user_email . '</b>',
167 fs_text_inline( 'complete the install', 'complete-the-install', $slug )
168 ) );
169 } else if ( $require_license_key ) {
170 $button_label = $is_network_upgrade_mode ?
171 fs_text_inline( 'Activate License', 'agree-activate-license', $slug ) :
172 fs_text_inline( 'Agree & Activate License', 'agree-activate-license', $slug );
173
174 $message = $fs->apply_filters(
175 'connect-message_on-premium',
176 ($is_network_upgrade_mode ?
177 '' :
178 /* translators: %s: name (e.g. Hey John,) */
179 $hey_x_text . '<br>'
180 ) .
181 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>' ),
182 $first_name,
183 $fs->get_plugin_name()
184 );
185 } else {
186 $filter = 'connect_message';
187 $default_optin_message = $is_gdpr_required ?
188 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) :
189 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);
190
191 if ( $fs->is_plugin_update() ) {
192 // If Freemius was added on a plugin update, set different
193 // opt-in message.
194 $default_optin_message = $is_gdpr_required ?
195 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 ) :
196 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 );
197
198 // If user customized the opt-in message on update, use
199 // that message. Otherwise, fallback to regular opt-in
200 // custom message if exist.
201 if ( $fs->has_filter( 'connect_message_on_update' ) ) {
202 $filter = 'connect_message_on_update';
203 }
204 }
205
206 $message = $fs->apply_filters(
207 $filter,
208 ($is_network_upgrade_mode ?
209 '' :
210 /* translators: %s: name (e.g. Hey John,) */
211 $hey_x_text . '<br>'
212 ) .
213 sprintf(
214 esc_html( $default_optin_message ),
215 '<b>' . esc_html( $fs->get_plugin_name() ) . '</b>',
216 '<b>' . $current_user->user_login . '</b>',
217 '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
218 $freemius_link
219 ),
220 $first_name,
221 $fs->get_plugin_name(),
222 $current_user->user_login,
223 '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
224 $freemius_link,
225 $is_gdpr_required
226 );
227 }
228
229 if ( $is_network_upgrade_mode ) {
230 $network_integration_text = esc_html( fs_text_inline( 'We\'re excited to introduce the Freemius network-level integration.', 'connect_message_network_upgrade', $slug ) );
231
232 if ($is_premium_code){
233 $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 ) );
234
235 $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(
236 /* translators: %s: module type (plugin, theme, or add-on) */
237 fs_text_inline( "%s's paid features", 'x-paid-features', $slug ),
238 $fs->get_module_label( true )
239 ) );
240
241 /* translators: %s: module type (plugin, theme, or add-on) */
242 $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 ) );
243 }else {
244 $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 );
245 }
246 }
247
248 echo $message;
249 ?></p>
250 <?php if ( $require_license_key ) : ?>
251 <div class="fs-license-key-container">
252 <input id="fs_license_key" name="fs_key" type="text" required maxlength="<?php echo $fs->apply_filters('license_key_maxlength', 32) ?>"
253 placeholder="<?php fs_esc_attr_echo_inline( 'License key', 'license-key', $slug ) ?>" tabindex="1"/>
254 <i class="dashicons dashicons-admin-network"></i>
255 <a class="show-license-resend-modal show-license-resend-modal-<?php echo $fs->get_unique_affix() ?>"
256 href="#"><?php fs_esc_html_echo_inline( "Can't find your license key?", 'cant-find-license-key', $slug ); ?></a>
257 </div>
258
259 <?php
260 /**
261 * Allows developers to include custom HTML after the license input container.
262 *
263 * @author Vova Feldman
264 * @since 2.1.2
265 */
266 $fs->do_action( 'connect/after_license_input' );
267 ?>
268
269 <?php
270 $send_updates_text = sprintf(
271 '%s<span class="action-description"> - %s</span>',
272 $fs->get_text_inline( 'Yes', 'yes' ),
273 $fs->get_text_inline( 'send me security & feature updates, educational content and offers.', 'send-updates' )
274 );
275
276 $do_not_send_updates_text = sprintf(
277 '%s<span class="action-description"> - %s</span>',
278 $fs->get_text_inline( 'No', 'no' ),
279 sprintf(
280 $fs->get_text_inline( 'do %sNOT%s send me security & feature updates, educational content and offers.', 'do-not-send-updates' ),
281 '<span class="underlined">',
282 '</span>'
283 )
284 );
285 ?>
286 <div id="fs_marketing_optin">
287 <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>
288 <div class="fs-input-container">
289 <label>
290 <input type="radio" name="allow-marketing" value="true" tabindex="1" />
291 <span class="fs-input-label"><?php echo $send_updates_text ?></span>
292 </label>
293 <label>
294 <input type="radio" name="allow-marketing" value="false" tabindex="1" />
295 <span class="fs-input-label"><?php echo $do_not_send_updates_text ?></span>
296 </label>
297 </div>
298 </div>
299 <?php endif ?>
300 <?php if ( $is_network_level_activation ) : ?>
301 <?php
302 $vars = array(
303 'id' => $fs->get_id(),
304 'sites' => $sites,
305 'require_license_key' => $require_license_key
306 );
307
308 echo fs_get_template( 'partials/network-activation.php', $vars );
309 ?>
310 <?php endif ?>
311 </div>
312 <div class="fs-actions">
313 <?php if ( $fs->is_enable_anonymous() && ! $is_pending_activation && ( ! $require_license_key || $is_network_upgrade_mode ) ) : ?>
314 <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' ) ?>"
315 class="button button-secondary" tabindex="2"><?php fs_esc_html_echo_x_inline( 'Skip', 'verb', 'skip', $slug ) ?></a>
316 <?php endif ?>
317 <?php if ( $is_network_level_activation && $fs->apply_filters( 'show_delegation_option', true ) ) : ?>
318 <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>
319 <?php endif ?>
320 <?php if ( $activate_with_current_user ) : ?>
321 <form action="" method="POST">
322 <input type="hidden" name="fs_action"
323 value="<?php echo $fs->get_unique_affix() ?>_activate_existing">
324 <?php wp_nonce_field( 'activate_existing_' . $fs->get_public_key() ) ?>
325 <button class="button button-primary" tabindex="1"
326 type="submit"><?php echo esc_html( $button_label ) ?></button>
327 </form>
328 <?php else : ?>
329 <form method="post" action="<?php echo WP_FS__ADDRESS ?>/action/service/user/install/">
330 <?php unset( $optin_params['sites']); ?>
331 <?php foreach ( $optin_params as $name => $value ) : ?>
332 <input type="hidden" name="<?php echo $name ?>" value="<?php echo esc_attr( $value ) ?>">
333 <?php endforeach ?>
334 <button class="button button-primary" tabindex="1"
335 type="submit"<?php if ( $require_license_key ) {
336 echo ' disabled="disabled"';
337 } ?>><?php echo esc_html( $button_label ) ?></button>
338 </form>
339 <?php endif ?>
340 </div><?php
341
342 // Set core permission list items.
343 $permissions = array(
344 'profile' => array(
345 'icon-class' => 'dashicons dashicons-admin-users',
346 'label' => $fs->get_text_inline( 'Your Profile Overview', 'permissions-profile' ),
347 'desc' => $fs->get_text_inline( 'Name and email address', 'permissions-profile_desc' ),
348 'priority' => 5,
349 ),
350 'site' => array(
351 'icon-class' => 'dashicons dashicons-admin-settings',
352 'label' => $fs->get_text_inline( 'Your Site Overview', 'permissions-site' ),
353 'desc' => $fs->get_text_inline( 'Site URL, WP version, PHP info, plugins & themes', 'permissions-site_desc' ),
354 'priority' => 10,
355 ),
356 'notices' => array(
357 'icon-class' => 'dashicons dashicons-testimonial',
358 'label' => $fs->get_text_inline( 'Admin Notices', 'permissions-admin-notices' ),
359 'desc' => $fs->get_text_inline( 'Updates, announcements, marketing, no spam', 'permissions-newsletter_desc' ),
360 'priority' => 13,
361 ),
362 'events' => array(
363 'icon-class' => 'dashicons dashicons-admin-plugins',
364 'label' => sprintf( $fs->get_text_inline( 'Current %s Events', 'permissions-events' ), ucfirst( $fs->get_module_type() ) ),
365 'desc' => $fs->get_text_inline( 'Activation, deactivation and uninstall', 'permissions-events_desc' ),
366 'priority' => 20,
367 ),
368 );
369
370 // Add newsletter permissions if enabled.
371 if ( $is_gdpr_required || $fs->is_permission_requested( 'newsletter' ) ) {
372 $permissions['newsletter'] = array(
373 'icon-class' => 'dashicons dashicons-email-alt',
374 'label' => $fs->get_text_inline( 'Newsletter', 'permissions-newsletter' ),
375 'desc' => $fs->get_text_inline( 'Updates, announcements, marketing, no spam', 'permissions-newsletter_desc' ),
376 'priority' => 15,
377 );
378 }
379
380 // Allow filtering of the permissions list.
381 $permissions = $fs->apply_filters( 'permission_list', $permissions );
382
383 // Sort by priority.
384 uasort( $permissions, 'fs_sort_by_priority' );
385
386 if ( ! empty( $permissions ) ) : ?>
387 <div class="fs-permissions">
388 <?php if ( $require_license_key ) : ?>
389 <p class="fs-license-sync-disclaimer"><?php
390 echo sprintf(
391 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 ),
392 $fs->get_module_label( true ),
393 $freemius_link
394 ) ?></p>
395 <?php endif ?>
396 <a class="fs-trigger" href="#" tabindex="1"><?php fs_esc_html_echo_inline( 'What permissions are being granted?', 'what-permissions', $slug ) ?></a>
397 <ul><?php
398 foreach ( $permissions as $id => $permission ) : ?>
399 <li id="fs-permission-<?php echo esc_attr( $id ); ?>"
400 class="fs-permission fs-<?php echo esc_attr( $id ); ?>">
401 <i class="<?php echo esc_attr( $permission['icon-class'] ); ?>"></i>
402
403 <div>
404 <span><?php echo esc_html( $permission['label'] ); ?></span>
405
406 <p><?php echo esc_html( $permission['desc'] ); ?></p>
407 </div>
408 </li>
409 <?php endforeach; ?>
410 </ul>
411 </div>
412 <?php endif ?>
413 <?php if ( $is_premium_code && $is_freemium ) : ?>
414 <div class="fs-freemium-licensing">
415 <p>
416 <?php if ( $require_license_key ) : ?>
417 <?php fs_esc_html_echo_inline( 'Don\'t have a license key?', 'dont-have-license-key', $slug ) ?>
418 <a data-require-license="false" tabindex="1"><?php fs_esc_html_echo_inline( 'Activate Free Version', 'activate-free-version', $slug ) ?></a>
419 <?php else : ?>
420 <?php fs_echo_inline( 'Have a license key?', 'have-license-key', $slug ) ?>
421 <a data-require-license="true" tabindex="1"><?php fs_esc_html_echo_inline( 'Activate License', 'activate-license', $slug ) ?></a>
422 <?php endif ?>
423 </p>
424 </div>
425 <?php endif ?>
426 <div class="fs-terms">
427 <a href="https://freemius.com/privacy/" target="_blank"
428 tabindex="1"><?php fs_esc_html_echo_inline( 'Privacy Policy', 'privacy-policy', $slug ) ?></a>
429 &nbsp;&nbsp;-&nbsp;&nbsp;
430 <a href="<?php echo $require_license_key ? $freemius_plugin_terms_url : $freemius_usage_tracking_url ?>" target="_blank" tabindex="1"><?php $require_license_key ? fs_echo_inline( 'License Agreement', 'license-agreement', $slug ) : fs_echo_inline( 'Terms of Service', 'tos', $slug ) ?></a>
431 </div>
432 </div>
433 <?php
434 if ( $is_optin_dialog ) { ?>
435 </div>
436 <?php
437 }
438 ?>
439 <script type="text/javascript">
440 (function ($) {
441 var $html = $('html');
442
443 <?php
444 if ( $is_optin_dialog ) {
445 if ( $show_close_button ) { ?>
446 var $themeConnectWrapper = $('#fs_theme_connect_wrapper');
447
448 $themeConnectWrapper.find('button.close').on('click', function () {
449 <?php if ( ! empty( $previous_theme_activation_url ) ) { ?>
450 location.href = '<?php echo html_entity_decode( $previous_theme_activation_url ); ?>';
451 <?php } else { ?>
452 $themeConnectWrapper.remove();
453 $html.css({overflow: $html.attr('fs-optin-overflow')});
454 <?php } ?>
455 });
456 <?php
457 }
458 ?>
459
460 $html.attr('fs-optin-overflow', $html.css('overflow'));
461 $html.css({overflow: 'hidden'});
462
463 <?php
464 }
465 ?>
466
467 var $primaryCta = $('.fs-actions .button.button-primary'),
468 primaryCtaLabel = $primaryCta.html(),
469 $form = $('.fs-actions form'),
470 isNetworkActive = <?php echo $is_network_level_activation ? 'true' : 'false' ?>,
471 requireLicenseKey = <?php echo $require_license_key ? 'true' : 'false' ?>,
472 hasContextUser = <?php echo $activate_with_current_user ? 'true' : 'false' ?>,
473 isNetworkUpgradeMode = <?php echo $is_network_upgrade_mode ? 'true' : 'false' ?>,
474 $licenseSecret,
475 $licenseKeyInput = $('#fs_license_key'),
476 pauseCtaLabelUpdate = false,
477 isNetworkDelegating = false,
478 /**
479 * @author Leo Fajardo (@leorw)
480 * @since 2.1.0
481 */
482 resetLoadingMode = function() {
483 // Reset loading mode.
484 $primaryCta.html(primaryCtaLabel);
485 $primaryCta.prop('disabled', false);
486 $(document.body).css({'cursor': 'auto'});
487 $('.fs-loading').removeClass('fs-loading');
488
489 console.log('resetLoadingMode - Primary button was enabled');
490 },
491 setLoadingMode = function () {
492 $(document.body).css({'cursor': 'wait'});
493 };
494
495 $('.fs-actions .button').on('click', function () {
496 setLoadingMode();
497
498 var $this = $(this);
499
500 setTimeout(function () {
501 if ( ! requireLicenseKey || ! $marketingOptin.hasClass( 'error' ) ) {
502 $this.attr('disabled', 'disabled');
503 }
504 }, 200);
505 });
506
507 if ( isNetworkActive ) {
508 var
509 $multisiteOptionsContainer = $( '.fs-multisite-options-container' ),
510 $allSitesOptions = $( '.fs-all-sites-options' ),
511 $applyOnAllSites = $( '.fs-apply-on-all-sites-checkbox' ),
512 $sitesListContainer = $( '.fs-sites-list-container' ),
513 totalSites = <?php echo count( $sites ) ?>,
514 maxSitesListHeight = null,
515 $skipActivationButton = $( '#skip_activation' ),
516 $delegateToSiteAdminsButton = $( '#delegate_to_site_admins' ),
517 hasAnyInstall = <?php echo ! is_null( $fs->find_first_install() ) ? 'true' : 'false' ?>;
518
519 $applyOnAllSites.click(function() {
520 var isChecked = $( this ).is( ':checked' );
521
522 if ( isChecked ) {
523 $multisiteOptionsContainer.find( '.action' ).removeClass( 'selected' );
524 updatePrimaryCtaText( 'allow' );
525 }
526
527 $multisiteOptionsContainer.find( '.action-allow' ).addClass( 'selected' );
528
529 $skipActivationButton.toggle();
530
531 $delegateToSiteAdminsButton.toggle();
532
533 $multisiteOptionsContainer.toggleClass( 'fs-apply-on-all-sites', isChecked );
534
535 $sitesListContainer.toggle( ! isChecked );
536 if ( ! isChecked && null === maxSitesListHeight ) {
537 /**
538 * Set the visible number of rows to 5 (5 * height of the first row).
539 *
540 * @author Leo Fajardo (@leorw)
541 */
542 maxSitesListHeight = ( 5 * $sitesListContainer.find( 'tr:first' ).height() );
543 $sitesListContainer.css( 'max-height', maxSitesListHeight );
544 }
545 });
546
547 $allSitesOptions.find( '.action' ).click(function( evt ) {
548 var actionType = $( evt.target ).data( 'action-type' );
549
550 $multisiteOptionsContainer.find( '.action' ).removeClass( 'selected' );
551 $multisiteOptionsContainer.find( '.action-' + actionType ).toggleClass( 'selected' );
552
553 updatePrimaryCtaText( actionType );
554 });
555
556 $sitesListContainer.delegate( '.action', 'click', function( evt ) {
557 var $this = $( evt.target );
558 if ( $this.hasClass( 'selected' ) ) {
559 return false;
560 }
561
562 $this.parents( 'tr:first' ).find( '.action' ).removeClass( 'selected' );
563 $this.toggleClass( 'selected' );
564
565 var
566 singleSiteActionType = $this.data( 'action-type' ),
567 totalSelected = $sitesListContainer.find( '.action-' + singleSiteActionType + '.selected' ).length;
568
569 $allSitesOptions.find( '.action.selected' ).removeClass( 'selected' );
570
571 if ( totalSelected === totalSites ) {
572 $allSitesOptions.find( '.action-' + singleSiteActionType ).addClass( 'selected' );
573
574 updatePrimaryCtaText( singleSiteActionType );
575 } else {
576 updatePrimaryCtaText( 'mixed' );
577 }
578 });
579
580 if ( isNetworkUpgradeMode || hasAnyInstall ) {
581 $skipActivationButton.click(function(){
582 $delegateToSiteAdminsButton.hide();
583
584 $skipActivationButton.html('<?php fs_esc_js_echo_inline( 'Skipping, please wait', 'skipping-wait', $slug ) ?>...');
585
586 pauseCtaLabelUpdate = true;
587
588 // Check all sites to be skipped.
589 $allSitesOptions.find('.action.action-skip').click();
590
591 $form.submit();
592
593 pauseCtaLabelUpdate = false;
594
595 return false;
596 });
597
598 $delegateToSiteAdminsButton.click(function(){
599 $delegateToSiteAdminsButton.html('<?php fs_esc_js_echo_inline( 'Delegating, please wait', 'delegating-wait', $slug ) ?>...');
600
601 pauseCtaLabelUpdate = true;
602
603 /**
604 * Set to true so that the form submission handler can differentiate delegation from license
605 * activation and the proper AJAX action will be used (when delegating, the action should be
606 * `network_activate` and not `activate_license`).
607 *
608 * @author Leo Fajardo (@leorw)
609 * @since 2.3.0
610 */
611 isNetworkDelegating = true;
612
613 // Check all sites to be skipped.
614 $allSitesOptions.find('.action.action-delegate').click();
615
616 $form.submit();
617
618 pauseCtaLabelUpdate = false;
619
620 /**
621 * Set to false so that in case the previous AJAX request has failed, the form submission handler
622 * can differentiate license activation from delegation and the proper AJAX action will be used
623 * (when activating a license, the action should be `activate_license` and not `network_activate`).
624 *
625 * @author Leo Fajardo (@leorw)
626 * @since 2.3.0
627 */
628 isNetworkDelegating = false;
629
630 return false;
631 });
632 }
633 }
634
635 /**
636 * @author Leo Fajardo (@leorw)
637 */
638 function updatePrimaryCtaText( actionType ) {
639 if (pauseCtaLabelUpdate)
640 return;
641
642 var text = '<?php fs_esc_js_echo_inline( 'Continue', 'continue', $slug ) ?>';
643
644 switch ( actionType ) {
645 case 'allow':
646 text = '<?php fs_esc_js_echo_inline( 'Allow & Continue', 'opt-in-connect', $slug ) ?>';
647 break;
648 case 'delegate':
649 text = '<?php fs_esc_js_echo_inline( 'Delegate to Site Admins & Continue', 'delegate-to-site-admins-and-continue', $slug ) ?>';
650 break;
651 case 'skip':
652 text = '<?php fs_esc_js_echo_x_inline( 'Skip', 'verb', 'skip', $slug ) ?>';
653 break;
654 }
655
656 $primaryCta.html( text );
657 }
658
659 var ajaxOptin = ( requireLicenseKey || isNetworkActive );
660
661 $form.on('submit', function () {
662 /**
663 * @author Vova Feldman (@svovaf)
664 * @since 1.1.9
665 */
666 if ( ajaxOptin ) {
667 if (!hasContextUser || isNetworkUpgradeMode) {
668 var action = null,
669 security = null;
670
671 if ( requireLicenseKey && ! isNetworkDelegating ) {
672 action = '<?php echo $fs->get_ajax_action( 'activate_license' ) ?>';
673 security = '<?php echo $fs->get_ajax_security( 'activate_license' ) ?>';
674 } else {
675 action = '<?php echo $fs->get_ajax_action( 'network_activate' ) ?>';
676 security = '<?php echo $fs->get_ajax_security( 'network_activate' ) ?>';
677 }
678
679 $('.fs-error').remove();
680
681 var
682 licenseKey = $licenseKeyInput.val(),
683 data = {
684 action : action,
685 security : security,
686 license_key: licenseKey,
687 module_id : '<?php echo $fs->get_id() ?>'
688 };
689
690 if (
691 requireLicenseKey &&
692 ! isNetworkDelegating &&
693 isMarketingAllowedByLicense.hasOwnProperty(licenseKey)
694 ) {
695 var
696 isMarketingAllowed = null,
697 $isMarketingAllowed = $marketingOptin.find( 'input[type="radio"][name="allow-marketing"]:checked');
698
699
700 if ($isMarketingAllowed.length > 0)
701 isMarketingAllowed = ('true' == $isMarketingAllowed.val());
702
703 if ( null == isMarketingAllowedByLicense[ licenseKey ] &&
704 null == isMarketingAllowed
705 ) {
706 $marketingOptin.addClass( 'error' ).show();
707 resetLoadingMode();
708 return false;
709 } else if ( null == isMarketingAllowed ) {
710 isMarketingAllowed = isMarketingAllowedByLicense[ licenseKey ];
711 }
712
713 data.is_marketing_allowed = isMarketingAllowed;
714 }
715
716 $marketingOptin.removeClass( 'error' );
717
718 if ( isNetworkActive ) {
719 var
720 sites = [],
721 applyOnAllSites = $applyOnAllSites.is( ':checked' );
722
723 $sitesListContainer.find( 'tr' ).each(function() {
724 var
725 $this = $( this ),
726 includeSite = ( ! requireLicenseKey || applyOnAllSites || $this.find( 'input' ).is( ':checked' ) );
727
728 if ( ! includeSite )
729 return;
730
731 var site = {
732 uid : $this.find( '.uid' ).val(),
733 url : $this.find( '.url' ).val(),
734 title : $this.find( '.title' ).val(),
735 language: $this.find( '.language' ).val(),
736 charset : $this.find( '.charset' ).val(),
737 blog_id : $this.find( '.blog-id' ).find( 'span' ).text()
738 };
739
740 if ( ! requireLicenseKey) {
741 site.action = $this.find('.action.selected').data('action-type');
742 } else if ( isNetworkDelegating ) {
743 site.action = 'delegate';
744 }
745
746 sites.push( site );
747 });
748
749 data.sites = sites;
750
751 if ( hasAnyInstall ) {
752 data.has_any_install = hasAnyInstall;
753 }
754 }
755
756 /**
757 * Use the AJAX opt-in when license key is required to potentially
758 * process the after install failure hook.
759 *
760 * @author Vova Feldman (@svovaf)
761 * @since 1.2.1.5
762 */
763 $.ajax({
764 url : ajaxurl,
765 method : 'POST',
766 data : data,
767 success: function (result) {
768 var resultObj = $.parseJSON(result);
769 if (resultObj.success) {
770 // Redirect to the "Account" page and sync the license.
771 window.location.href = resultObj.next_page;
772 } else {
773 resetLoadingMode();
774
775 // Show error.
776 $('.fs-content').prepend('<p class="fs-error">' + (resultObj.error.message ? resultObj.error.message : resultObj.error) + '</p>');
777 }
778 },
779 error: function () {
780 resetLoadingMode();
781 }
782 });
783
784 return false;
785 }
786 else {
787 if (null == $licenseSecret) {
788 $licenseSecret = $('<input type="hidden" name="license_secret_key" value="" />');
789 $form.append($licenseSecret);
790 }
791
792 // Update secret key if premium only plugin.
793 $licenseSecret.val($licenseKeyInput.val());
794 }
795 }
796
797 return true;
798 });
799
800 $primaryCta.on('click', function () {
801 console.log('Primary button was clicked');
802
803 $(this).addClass('fs-loading');
804 $(this).html('<?php echo esc_js( $is_pending_activation ?
805 fs_text_x_inline( 'Sending email', 'as in the process of sending an email', 'sending-email', $slug ) :
806 fs_text_x_inline( 'Activating', 'as activating plugin', 'activating', $slug )
807 ) ?>...');
808 });
809
810 $('.fs-permissions .fs-trigger').on('click', function () {
811 $('.fs-permissions').toggleClass('fs-open');
812
813 return false;
814 });
815
816 if (requireLicenseKey) {
817 /**
818 * Submit license key on enter.
819 *
820 * @author Vova Feldman (@svovaf)
821 * @since 1.1.9
822 */
823 $licenseKeyInput.keypress(function (e) {
824 if (e.which == 13) {
825 if ('' !== $(this).val()) {
826 $primaryCta.click();
827 return false;
828 }
829 }
830 });
831
832 /**
833 * Disable activation button when empty license key.
834 *
835 * @author Vova Feldman (@svovaf)
836 * @since 1.1.9
837 */
838 $licenseKeyInput.on('keyup paste delete cut', function () {
839 setTimeout(function () {
840 var key = $licenseKeyInput.val();
841
842 if (key == previousLicenseKey){
843 return;
844 }
845
846 if ('' === key) {
847 $primaryCta.attr('disabled', 'disabled');
848 $marketingOptin.hide();
849 } else {
850 $primaryCta.prop('disabled', false);
851
852 if (32 <= key.length){
853 fetchIsMarketingAllowedFlagAndToggleOptin();
854 } else {
855 $marketingOptin.hide();
856 }
857 }
858
859 previousLicenseKey = key;
860 }, 100);
861 }).focus();
862 }
863
864 /**
865 * Set license mode trigger URL.
866 *
867 * @author Vova Feldman (@svovaf)
868 * @since 1.1.9
869 */
870 var
871 $connectLicenseModeTrigger = $('#fs_connect .fs-freemium-licensing a'),
872 href = window.location.href;
873
874 if (href.indexOf('?') > 0) {
875 href += '&';
876 } else {
877 href += '?';
878 }
879
880 if ($connectLicenseModeTrigger.length > 0) {
881 $connectLicenseModeTrigger.attr(
882 'href',
883 href + 'require_license=' + $connectLicenseModeTrigger.attr('data-require-license')
884 );
885 }
886
887 //--------------------------------------------------------------------------------
888 //region GDPR
889 //--------------------------------------------------------------------------------
890 var isMarketingAllowedByLicense = {},
891 $marketingOptin = $('#fs_marketing_optin'),
892 previousLicenseKey = null;
893
894 if (requireLicenseKey) {
895
896 var
897 afterMarketingFlagLoaded = function () {
898 var licenseKey = $licenseKeyInput.val();
899
900 if (null == isMarketingAllowedByLicense[licenseKey]) {
901 $marketingOptin.show();
902
903 if ($marketingOptin.find('input[type=radio]:checked').length > 0){
904 // Focus on button if GDPR opt-in already selected is already selected.
905 $primaryCta.focus();
906 } else {
907 // Focus on the GDPR opt-in radio button.
908 $($marketingOptin.find('input[type=radio]')[0]).focus();
909 }
910 } else {
911 $marketingOptin.hide();
912 $primaryCta.focus();
913 }
914 },
915 /**
916 * @author Leo Fajardo (@leorw)
917 * @since 2.1.0
918 */
919 fetchIsMarketingAllowedFlagAndToggleOptin = function () {
920 var licenseKey = $licenseKeyInput.val();
921
922 if (licenseKey.length < 32) {
923 $marketingOptin.hide();
924 return;
925 }
926
927 if (isMarketingAllowedByLicense.hasOwnProperty(licenseKey)) {
928 afterMarketingFlagLoaded();
929 return;
930 }
931
932 $marketingOptin.hide();
933
934 setLoadingMode();
935
936 $primaryCta.addClass('fs-loading');
937 $primaryCta.attr('disabled', 'disabled');
938 $primaryCta.html('<?php fs_esc_js_echo_inline( 'Please wait', 'please-wait', $slug ) ?>...');
939
940 $.ajax({
941 url : ajaxurl,
942 method : 'POST',
943 data : {
944 action : '<?php echo $fs->get_ajax_action( 'fetch_is_marketing_required_flag_value' ) ?>',
945 security : '<?php echo $fs->get_ajax_security( 'fetch_is_marketing_required_flag_value' ) ?>',
946 license_key: licenseKey,
947 module_id : '<?php echo $fs->get_id() ?>'
948 },
949 success: function (result) {
950 resetLoadingMode();
951
952 if (result.success) {
953 result = result.data;
954
955 // Cache result.
956 isMarketingAllowedByLicense[licenseKey] = result.is_marketing_allowed;
957 }
958
959 afterMarketingFlagLoaded();
960 }
961 });
962 };
963
964 $marketingOptin.find( 'input' ).click(function() {
965 $marketingOptin.removeClass( 'error' );
966 });
967 }
968
969 //endregion
970 })(jQuery);
971 </script>