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