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