PluginProbe ʕ •ᴥ•ʔ
Royal Addons for Elementor – Addons and Templates Kit for Elementor / 1.7.1064
Royal Addons for Elementor – Addons and Templates Kit for Elementor v1.7.1064
1.7.1064 1.7.1063 1.7.1062 1.7.1061 1.7.1060 1.7.1059 1.7.1058 trunk 1.0.0 1.1.0 1.2 1.3 1.3.1 1.3.2 1.3.21 1.3.22 1.3.23 1.3.24 1.3.25 1.3.26 1.3.27 1.3.28 1.3.29 1.3.30 1.3.31 1.3.32 1.3.33 1.3.34 1.3.35 1.3.36 1.3.37 1.3.38 1.3.39 1.3.40 1.3.41 1.3.42 1.3.43 1.3.44 1.3.45 1.3.46 1.3.47 1.3.48 1.3.49 1.3.50 1.3.51 1.3.52 1.3.53 1.3.54 1.3.55 1.3.56 1.3.57 1.3.58 1.3.59 1.3.60 1.3.61 1.3.62 1.3.63 1.3.64 1.3.65 1.3.66 1.3.67 1.3.68 1.3.69 1.3.70 1.3.71 1.3.72 1.3.73 1.3.74 1.3.75 1.3.76 1.3.77 1.3.78 1.3.79 1.3.80 1.3.81 1.3.82 1.3.83 1.3.84 1.3.85 1.3.86 1.3.87 1.3.88 1.3.89 1.3.90 1.3.91 1.3.92 1.3.93 1.3.94 1.3.95 1.3.96 1.3.97 1.3.971 1.3.972 1.3.973 1.3.974 1.3.975 1.3.976 1.3.977 1.3.978 1.3.979 1.3.980 1.3.981 1.3.982 1.3.983 1.3.984 1.3.985 1.3.986 1.3.987 1.7.1 1.7.1001 1.7.1002 1.7.1003 1.7.1004 1.7.1005 1.7.1006 1.7.1007 1.7.1008 1.7.1009 1.7.1010 1.7.1011 1.7.1012 1.7.1013 1.7.1014 1.7.1015 1.7.1016 1.7.1017 1.7.1018 1.7.1019 1.7.1020 1.7.1021 1.7.1022 1.7.1023 1.7.1024 1.7.1025 1.7.1026 1.7.1027 1.7.1028 1.7.1029 1.7.1030 1.7.1031 1.7.1032 1.7.1033 1.7.1034 1.7.1035 1.7.1036 1.7.1037 1.7.1038 1.7.1039 1.7.1040 1.7.1041 1.7.1042 1.7.1043 1.7.1044 1.7.1045 1.7.1046 1.7.1047 1.7.1048 1.7.1049 1.7.1050 1.7.1051 1.7.1052 1.7.1053 1.7.1054 1.7.1055 1.7.1056 1.7.1057
royal-elementor-addons / freemius / templates / forms / license-activation.php
royal-elementor-addons / freemius / templates / forms Last commit date
deactivation 5 days ago affiliation.php 5 days ago data-debug-mode.php 5 days ago email-address-update.php 5 days ago index.php 5 days ago license-activation.php 5 days ago optout.php 5 days ago premium-versions-upgrade-handler.php 5 days ago premium-versions-upgrade-metadata.php 5 days ago resend-key.php 5 days ago subscription-cancellation.php 5 days ago trial-start.php 5 days ago user-change.php 5 days ago
license-activation.php
900 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.1.9
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * @var array $VARS
15 *
16 * @var Freemius $fs
17 */
18 $fs = freemius( $VARS['id'] );
19 $slug = $fs->get_slug();
20 $unique_affix = $fs->get_unique_affix();
21
22 $cant_find_license_key_text = fs_text_inline( "Can't find your license key?", 'cant-find-license-key', $slug );
23 $message_above_input_field = fs_text_inline( 'Please enter the license key that you received in the email right after the purchase:', 'activate-license-message', $slug );
24 $message_below_input_field = '';
25
26 $header_title = $fs->is_free_plan() ?
27 fs_text_inline( 'Activate License', 'activate-license', $slug ) :
28 fs_text_inline( 'Update License', 'update-license', $slug );
29
30 if ( $fs->is_registered() ) {
31 $activate_button_text = $header_title;
32 } else {
33 $message_below_input_field = sprintf(
34 fs_text_inline( 'The %1$s will be periodically sending essential license data to %2$s to check for security and feature updates, and verify the validity of your license.', 'license-sync-disclaimer', $slug ),
35 $fs->get_module_label( true ),
36 "<b>{$fs->get_plugin_title()}</b>"
37 );
38
39 $activate_button_text = fs_text_inline( 'Agree & Activate License', 'agree-activate-license', $slug );
40 }
41
42 $license_key_text = fs_text_inline( 'License key', 'license-key' , $slug );
43
44 $is_network_activation = (
45 $fs->is_network_active() &&
46 fs_is_network_admin() &&
47 ! $fs->is_delegated_connection()
48 );
49 $network_activation_html = '';
50
51 $sites_details = array();
52 if ( $is_network_activation ) {
53 $all_sites = Freemius::get_sites();
54
55 $all_site_details = array();
56 $subsite_url_by_install_id = array();
57 $install_url_by_install_id = array();
58
59 foreach ( $all_sites as $site ) {
60 $site_details = $fs->get_site_info( $site );
61
62 if ( FS_Clone_Manager::instance()->is_temporary_duplicate_by_blog_id( $site_details['blog_id'] ) ) {
63 continue;
64 }
65
66 $blog_id = Freemius::get_site_blog_id( $site );
67 $install = $fs->get_install_by_blog_id($blog_id);
68
69 if ( is_object( $install ) ) {
70 if ( isset( $subsite_url_by_install_id[ $install->id ] ) ) {
71 $clone_subsite_url = $subsite_url_by_install_id[ $install->id ];
72 $clone_install_url = $install_url_by_install_id[ $install->id ];
73
74 if (
75 /**
76 * If we already have an install with the same URL as the subsite it's stored in, skip the current subsite. Otherwise, replace the existing install's data with the current subsite's install's data if the URLs match.
77 *
78 * @author Leo Fajardo (@leorw)
79 * @since 2.5.0
80 */
81 fs_strip_url_protocol( untrailingslashit( $clone_install_url ) ) === fs_strip_url_protocol( untrailingslashit( $clone_subsite_url ) ) ||
82 fs_strip_url_protocol( untrailingslashit( $install->url ) ) !== fs_strip_url_protocol( untrailingslashit( $site_details['url'] ) )
83 ) {
84 continue;
85 }
86 }
87
88 if ( FS_Plugin_License::is_valid_id( $install->license_id ) ) {
89 $site_details['license_id'] = $install->license_id;
90 }
91
92 $subsite_url_by_install_id[ $install->id ] = $site_details['url'];
93 $install_url_by_install_id[ $install->id ] = $install->url;
94 }
95
96 $all_site_details[] = $site_details;
97 }
98
99 if ( $is_network_activation ) {
100 $vars = array(
101 'id' => $fs->get_id(),
102 'sites' => $all_site_details,
103 'require_license_key' => true
104 );
105
106 $network_activation_html = fs_get_template( 'partials/network-activation.php', $vars );
107 }
108 }
109
110 $premium_licenses = $fs->get_available_premium_licenses();
111 $available_licenses = array();
112 foreach ( $premium_licenses as $premium_license ) {
113 $activations_left = $premium_license->left();
114 if ( ! ( $activations_left > 0 ) ) {
115 continue;
116 }
117
118 $available_licenses[ $activations_left . '_' . $premium_license->id ] = $premium_license;
119 }
120
121 $total_available_licenses = count( $available_licenses );
122 if ( $total_available_licenses > 0 ) {
123 $license_input_html = <<< HTML
124 <div class="fs-license-options-container">
125 <table>
126 <tbody>
127 <tr class="fs-available-license-key-container">
128 <td><input type="radio" name="license_type" value="available"></td>
129 <td>
130 HTML;
131
132 if ( $total_available_licenses > 1 ) {
133 // Sort the licenses by number of activations left in descending order.
134 krsort( $available_licenses );
135
136 $license_input_html .= '<select class="fs-licenses">';
137
138 /**
139 * @var FS_Plugin_License $license
140 */
141 foreach ( $available_licenses as $license ) {
142 $plan = $fs->_get_plan_by_id( $license->plan_id );
143
144 $label = sprintf(
145 "%s-Site %s License - %s",
146 ( 1 == $license->quota ?
147 'Single' :
148 ( $license->is_unlimited() ? 'Unlimited' : $license->quota )
149 ),
150 ( is_object( $plan ) ? $plan->title : '' ),
151 $license->get_html_escaped_masked_secret_key()
152 );
153
154 $license_input_html .= "<option data-id='{$license->id}' value='{$license->id}' data-left='{$license->left()}'>{$label}</option>";
155 }
156
157 $license_input_html .= '</select>';
158 } else {
159 $available_licenses = array_values( $available_licenses );
160
161 /**
162 * @var FS_Plugin_License $available_license
163 */
164 $available_license = $available_licenses[0];
165 $value = sprintf(
166 "%s-Site %s License - %s",
167 ( 1 == $available_license->quota ?
168 'Single' :
169 ( $available_license->is_unlimited() ? 'Unlimited' : $available_license->quota )
170 ),
171 $fs->_get_plan_by_id( $available_license->plan_id )->title,
172 $available_license->get_html_escaped_masked_secret_key()
173 );
174
175 $license_input_html .= <<< HTML
176 <input
177 class="fs-available-license-key"
178 type="text"
179 value="{$value}"
180 data-id="{$available_license->id}"
181 data-left="{$available_license->left()}"
182 readonly />
183 HTML;
184 }
185
186 $license_input_html .= <<< HTML
187 </td>
188 </tr>
189 <tr>
190 <td><input type="radio" name="license_type" value="other"></td>
191 <td class="fs-other-license-key-container">
192 <label for="other_license_key_{$unique_affix}">Other: </label>
193 <div>
194 <input id="other_license_key_{$unique_affix}" class="fs-license-key" type="text" placeholder="Enter license key" tabindex="1">
195 </div>
196 </td>
197 </tr>
198 </tbody>
199 </table>
200 </div>
201 HTML;
202 } else {
203 $license_input_html = "<input class='fs-license-key' type='text' placeholder='{$license_key_text}' tabindex='1' />";
204 }
205
206 $ownership_change_option_text = fs_text_inline( "Associate with the license owner's account.", 'associate-account-with-license-owner', $slug );
207 $ownership_change_option_html = "<div class='ownership-change-option-container' style='display: none'><label><input type='checkbox' /> <strong>{$ownership_change_option_text}</strong></label></div>";
208
209 /**
210 * IMPORTANT:
211 * DO NOT ADD MAXLENGTH OR LIMIT THE LICENSE KEY LENGTH SINCE
212 * WE DO WANT TO ALLOW INPUT OF LONGER KEYS (E.G. WooCommerce Keys)
213 * FOR MIGRATED MODULES.
214 */
215 $modal_content_html = <<< HTML
216 <div class="notice notice-error inline license-activation-message"><p></p></div>
217 <p>{$message_above_input_field}</p>
218 {$license_input_html}
219 <a class="show-license-resend-modal show-license-resend-modal-{$fs->get_unique_affix()}" href="!#" tabindex="2">{$cant_find_license_key_text}</a>
220 {$network_activation_html}
221 <p>{$message_below_input_field}</p>
222 {$ownership_change_option_html}
223 HTML;
224
225 /**
226 * Handle the ownership change option if not an add-on or if no license yet is activated for the
227 * parent product in case of an add-on.
228 *
229 * @author Leo Fajardo (@leorw)
230 * @since 2.3.2
231 */
232 $is_user_change_supported = ( ! $fs->is_addon() || ! $fs->get_parent_instance()->has_active_valid_license() );
233
234 fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' );
235 ?>
236 <script type="text/javascript">
237 (function( $ ) {
238 $( document ).ready(function() {
239 var modalContentHtml = <?php echo json_encode($modal_content_html); ?>,
240 modalHtml =
241 '<div class="fs-modal fs-modal-license-activation fs-modal-license-activation-<?php echo $unique_affix ?>">'
242 + ' <div class="fs-modal-dialog">'
243 + ' <div class="fs-modal-header">'
244 + ' <h4><?php echo esc_js($header_title) ?></h4>'
245 + ' <a href="!#" class="fs-close"><i class="dashicons dashicons-no" title="<?php echo esc_js( fs_text_x_inline( 'Dismiss', 'as close a window', 'dismiss', $slug ) ) ?>"></i></a>'
246 + ' </div>'
247 + ' <div class="fs-modal-body">'
248 + ' <div class="fs-modal-panel active">' + modalContentHtml + '</div>'
249 + ' </div>'
250 + ' <div class="fs-modal-footer">'
251 + ' <button class="button button-secondary button-close" tabindex="4"><?php fs_esc_js_echo_inline( 'Cancel', 'cancel', $slug ) ?></button>'
252 + ' <button class="button button-primary button-activate-license" tabindex="3"><?php echo esc_js( $activate_button_text ) ?></button>'
253 + ' </div>'
254 + ' </div>'
255 + '</div>',
256 $modal = $(modalHtml),
257 $activateLicenseButton = $modal.find('.button-activate-license'),
258 $licenseKeyInput = $modal.find( 'input.fs-license-key' ),
259 $licenseActivationMessage = $modal.find( '.license-activation-message' ),
260 isNetworkActivation = <?php echo $is_network_activation ? 'true' : 'false' ?>,
261 isUserChangeSupported = <?php echo $is_user_change_supported ? 'true' : 'false' ?>,
262 isSingleSiteActivation = false,
263 $ownershipChangeOptionContainer = $modal.find( '.ownership-change-option-container' ),
264 $body = $( 'body' );
265
266 $modal.appendTo( $body );
267
268 var
269 $licensesDropdown = $modal.find( '.fs-licenses' ),
270 $licenseTypes = $modal.find( 'input[type="radio"][name="license_type"]' ),
271 $applyOnAllSites = $modal.find( '.fs-apply-on-all-sites-checkbox' ),
272 $sitesListContainer = $modal.find( '.fs-sites-list-container' ),
273 $availableLicenseKey = $modal.find( '.fs-available-license-key' ),
274 $otherLicenseKey = $modal.find( '#other_license_key_<?php echo $unique_affix ?>' ),
275 $multisiteOptionsContainer = $modal.find( '.fs-multisite-options-container' ),
276 $activationsLeft = null,
277 hasLicensesDropdown = ( $licensesDropdown.length > 0 ),
278 hasLicenseTypes = ( $licenseTypes.length > 0 ),
279 maxSitesListHeight = null,
280 totalSites = <?php echo count( $sites_details ) ?>,
281 singleBlogID = null;
282
283 var
284 previousLicenseKey = null,
285 otherLicenseOwnerID = null,
286 /**
287 * @author Leo Fajardo (@leorw)
288 * @since 2.3.2
289 */
290 resetLoadingMode = function () {
291 // Reset loading mode.
292 $activateLicenseButton.text( <?php echo json_encode( $activate_button_text ) ?> );
293 $activateLicenseButton.prop( 'disabled', false );
294 $( document.body ).css( { 'cursor': 'auto' } );
295 $( '.fs-loading' ).removeClass( 'fs-loading' );
296
297 console.log( 'resetLoadingMode - Primary button was enabled' );
298 },
299 /**
300 * @author Leo Fajardo (@leorw)
301 * @since 2.3.2
302 */
303 setLoadingMode = function () {
304 $( document.body ).css( { 'cursor': 'wait' } );
305 },
306 /**
307 * @author Leo Fajardo (@leorw)
308 * @since 2.3.2
309 */
310 afterLicenseUserDataLoaded = function () {
311 if (
312 false !== otherLicenseOwnerID &&
313 null !== otherLicenseOwnerID &&
314 otherLicenseOwnerID != <?php echo $fs->is_registered() ? $fs->get_user()->id : 'null' ?>
315 ) {
316 $ownershipChangeOptionContainer.show();
317 } else {
318 $ownershipChangeOptionContainer.hide();
319 $activateLicenseButton.focus();
320 }
321 },
322 /**
323 * @author Leo Fajardo (@leorw)
324 * @since 2.3.2
325 */
326 fetchLicenseUserData = function () {
327 var hideAndUncheckUserChangeCheckbox = ( ! isUserChangeSupported ),
328 otherLicenseKeyIsSelected = isOtherLicenseKeySelected();
329
330 if ( ! hideAndUncheckUserChangeCheckbox ) {
331 // User change is supported only on the site level.
332 hideAndUncheckUserChangeCheckbox = ( isNetworkActivation || isSingleSiteActivation );
333 }
334
335 if ( ! hideAndUncheckUserChangeCheckbox ) {
336 hideAndUncheckUserChangeCheckbox = ( hasLicenseTypes && ! otherLicenseKeyIsSelected );
337 }
338
339 var licenseKey = $licenseKeyInput.val().trim();
340
341 if ( ! hideAndUncheckUserChangeCheckbox && otherLicenseKeyIsSelected ) {
342 hideAndUncheckUserChangeCheckbox = ( licenseKey.length < 32 );
343 }
344
345 if ( licenseKey !== previousLicenseKey ) {
346 // If the license key has not been changed, keep the owner ID in order to prevent another API call.
347 otherLicenseOwnerID = null;
348 }
349
350 if ( hideAndUncheckUserChangeCheckbox ) {
351 $ownershipChangeOptionContainer.hide().find( 'input' ).attr( 'checked', false );
352
353 return;
354 }
355
356 if ( null !== otherLicenseOwnerID ) {
357 afterLicenseUserDataLoaded();
358 return;
359 }
360
361 setLoadingMode();
362
363 $activateLicenseButton.addClass( 'fs-loading' );
364 $activateLicenseButton.attr( 'disabled', 'disabled' );
365 $activateLicenseButton.html( '<?php fs_esc_js_echo_inline( 'Please wait', 'please-wait', $slug ) ?>...' );
366
367 $.ajax( {
368 url : <?php echo Freemius::ajax_url() ?>,
369 method : 'POST',
370 data : {
371 action : '<?php echo $fs->get_ajax_action( 'fetch_is_marketing_required_flag_value' ) ?>',
372 security : '<?php echo $fs->get_ajax_security( 'fetch_is_marketing_required_flag_value' ) ?>',
373 license_key: licenseKey,
374 module_id : '<?php echo $fs->get_id() ?>'
375 },
376 success: function ( result ) {
377 resetLoadingMode();
378
379 if ( result.success ) {
380 result = result.data;
381
382 // Cache license owner's ID.
383 otherLicenseOwnerID = result.license_owner_id;
384 }
385
386 afterLicenseUserDataLoaded();
387 }
388 } );
389 };
390
391 function registerEventHandlers() {
392 var
393 $otherLicenseKeyContainer = $modal.find( '.fs-other-license-key-container' );
394
395 if ( isNetworkActivation ) {
396 $applyOnAllSites.click(function() {
397 var applyOnAllSites = $( this ).is( ':checked' );
398
399 $multisiteOptionsContainer.toggleClass( 'fs-apply-on-all-sites', applyOnAllSites );
400
401 showSites( ! applyOnAllSites );
402
403 if ( hasValidLicenseKey() && ( applyOnAllSites || hasSelectedSite() ) ) {
404 enableActivateLicenseButton();
405 } else {
406 disableActivateLicenseButton();
407 }
408 });
409
410 $sitesListContainer.delegate( 'td:not(:first-child)', 'click', function() {
411 // If a site row is clicked, trigger a click on the checkbox.
412 $( this ).parent().find( 'td:first-child input' ).click();
413 });
414
415 $sitesListContainer.delegate( 'input[type="checkbox"]', 'click', function() {
416 enableDisableSitesSelection();
417
418 if ( hasValidLicenseKey() && hasSelectedSite() ) {
419 enableActivateLicenseButton();
420 } else {
421 disableActivateLicenseButton();
422 }
423 });
424 }
425
426 if ( hasLicensesDropdown ) {
427 $licensesDropdown.change(function() {
428 // When a license is selected, select the associated radio button.
429 $licenseTypes.filter( '[value="available"]' ).attr( 'checked', true );
430
431 if ( ! isNetworkActivation || $modal.hasClass( 'is-single-site-activation' ) ) {
432 enableActivateLicenseButton();
433 return true;
434 }
435
436 toggleActivationOnAllSites();
437 })
438 }
439
440 if ( hasLicenseTypes ) {
441 $licenseTypes.change(function() {
442 var
443 licenseKey = $modal.find( 'input.fs-license-key' ).val().trim(),
444 otherLicenseKeySelected = isOtherLicenseKeySelected();
445
446 if ( ( licenseKey.length > 0 || ( hasLicenseTypes && ! otherLicenseKeySelected ) ) &&
447 ( $modal.hasClass( 'is-single-site-activation' ) || ! isNetworkActivation || hasSelectedSite() )
448 ) {
449 /**
450 * If the "other" license is not empty or an available license is selected, enable the activate
451 * button.
452 *
453 * @author Leo Fajardo (@leorw)
454 */
455 enableActivateLicenseButton();
456 } else {
457 disableActivateLicenseButton();
458 }
459
460 if ( '' !== licenseKey ) {
461 fetchLicenseUserData();
462 }
463
464 if ( ! isNetworkActivation ) {
465 return;
466 }
467
468 if ( otherLicenseKeySelected ) {
469 $applyOnAllSites.attr( 'disabled', false );
470 enableDisableSitesSelection();
471 resetActivateLicenseCheckboxLabel();
472 } else if ( ! $modal.hasClass( 'is-single-site-activation' ) ) {
473 toggleActivationOnAllSites();
474 }
475 });
476
477 if ( ! hasLicensesDropdown ) {
478 $availableLicenseKey.click(function() {
479 $licenseTypes.filter( '[value="available"]' ).click();
480 });
481 }
482
483 $otherLicenseKeyContainer.click(function() {
484 $licenseTypes.filter( '[value="other"]' ).click();
485 });
486 }
487
488 $body.on( 'click', 'span.activate-license.<?php echo $unique_affix ?> a, .activate-license-trigger.<?php echo $unique_affix ?>', function (evt) {
489 evt.preventDefault();
490
491 showModal( evt );
492 });
493
494 var licenseTimeout = null;
495
496 /**
497 * Disable activation button when license key is empty.
498 *
499 * @author Leo Fajardo (@leorw)
500 * @since 2.3.2
501 */
502 $modal.on( 'keyup paste delete cut', 'input.fs-license-key', function () {
503 clearTimeout(licenseTimeout);
504
505 licenseTimeout = setTimeout( function () {
506 var licenseKey = $licenseKeyInput.val().trim();
507
508 if ( licenseKey == previousLicenseKey ) {
509 afterLicenseUserDataLoaded();
510 return;
511 }
512
513 if ( '' === licenseKey ) {
514 disableActivateLicenseButton();
515 $ownershipChangeOptionContainer.hide();
516 } else {
517 enableActivateLicenseButton();
518
519 if ( 32 <= licenseKey.length ) {
520 fetchLicenseUserData();
521 } else {
522 $ownershipChangeOptionContainer.hide();
523 }
524 }
525
526 previousLicenseKey = licenseKey;
527 }, 200 );
528 } ).focus();
529
530 $modal.on('input propertychange', 'input.fs-license-key', function () {
531
532 var licenseKey = $(this).val().trim();
533
534 /**
535 * If license key is not empty, enable the license activation button.
536 */
537 if ( licenseKey.length > 0 && ( $modal.hasClass( 'is-single-site-activation' ) || ! isNetworkActivation || hasSelectedSite() ) ) {
538 enableActivateLicenseButton();
539 }
540 });
541
542 $modal.on( 'blur', 'input.fs-license-key', function( evt ) {
543 var
544 licenseKey = $(this).val().trim(),
545 $focusedElement = $( evt.relatedTarget ),
546 hasSelectedAvailableLicense = ( hasLicenseTypes && $focusedElement.parents( '.fs-available-license-key-container' ).length > 0 );
547
548 /**
549 * If license key is empty, disable the license activation button.
550 */
551 if ( ( 0 === licenseKey.length && ( ! hasLicenseTypes || ! hasSelectedAvailableLicense ) ) ||
552 ( isNetworkActivation && ! hasSelectedSite() )
553 ) {
554 disableActivateLicenseButton();
555 }
556 });
557
558 $modal.on('click', '.button-activate-license', function (evt) {
559 evt.preventDefault();
560
561 if ($(this).hasClass('disabled')) {
562 return;
563 }
564
565 var licenseKey = '',
566 licenseID = '';
567
568 if ( hasLicenseTypes ) {
569 if ( isOtherLicenseKeySelected() ) {
570 licenseKey = $otherLicenseKey.val();
571 } else {
572 if ( ! hasLicensesDropdown ) {
573 licenseID = $availableLicenseKey.data( 'id' ).toString();
574 } else {
575 licenseID = $licensesDropdown.val();
576 }
577 }
578 } else {
579 licenseKey = $licenseKeyInput.val().trim();
580 }
581
582 disableActivateLicenseButton();
583
584 if ( 0 === licenseID.length && 0 === licenseKey.length ) {
585 return;
586 }
587
588 var data = {
589 action : '<?php echo $fs->get_ajax_action( 'activate_license' ) ?>',
590 security : '<?php echo $fs->get_ajax_security( 'activate_license' ) ?>',
591 module_id : '<?php echo $fs->get_id() ?>'
592 };
593
594 if ( licenseID.length > 0 ) {
595 data.license_id = licenseID;
596 } else {
597 data.license_key = licenseKey;
598 }
599
600 if ( isNetworkActivation ) {
601 var
602 sites = [];
603
604 if ( null === singleBlogID ) {
605 var
606 applyOnAllSites = $applyOnAllSites.is( ':checked' );
607
608 $sitesListContainer.find( 'tr' ).each(function() {
609 var
610 $this = $( this ),
611 includeSite = ( applyOnAllSites || $this.find( 'input' ).is( ':checked' ) );
612
613 if ( ! includeSite )
614 return;
615
616 var site = {
617 uid : $this.find( '.uid' ).val(),
618 url : $this.find( '.url' ).val(),
619 title : $this.find( '.title' ).val(),
620 language: $this.find( '.language' ).val(),
621 blog_id : $this.find( '.blog-id' ).find( 'span' ).text()
622 };
623
624 sites.push( site );
625 });
626 } else {
627 data.blog_id = singleBlogID;
628 }
629
630 data.sites = sites;
631 }
632
633 if ( $ownershipChangeOptionContainer.find( 'input:checked' ).length > 0 ) {
634 data.user_id = otherLicenseOwnerID;
635 }
636
637 $.ajax({
638 url: <?php echo Freemius::ajax_url() ?>,
639 method: 'POST',
640 data: data,
641 beforeSend: function () {
642 $activateLicenseButton.text( '<?php fs_esc_js_echo_inline( 'Activating license', 'activating-license', $slug ) ?>...' );
643 },
644 success: function( result ) {
645 var resultObj = $.parseJSON( result );
646 if ( resultObj.success ) {
647 closeModal();
648
649 // Redirect to the "Account" page and sync the license.
650 window.location.href = resultObj.next_page;
651 } else {
652 showError( resultObj.error.message ? resultObj.error.message : resultObj.error );
653 resetActivateLicenseButton();
654 }
655 }
656 });
657 });
658
659 // If the user has clicked outside the window, close the modal.
660 $modal.on('click', '.fs-close, .button-secondary', function () {
661 closeModal();
662 return false;
663 });
664 }
665
666 registerEventHandlers();
667
668 $body.trigger('licenseActivationLoaded');
669
670 /**
671 * @author Leo Fajardo (@leorw)
672 * @since 2.0.0
673 */
674 function enableDisableSitesSelection() {
675 var
676 canApplyOnAllSites = $applyOnAllSites.is( ':enabled' ),
677 disableSitesSelection = null;
678
679 if ( ! canApplyOnAllSites ) {
680 var
681 selectedSites = $sitesListContainer.find( 'input[type="checkbox"]:checked' ).length,
682 activationsLeft = Math.max( 0, $activationsLeft.data( 'left' ) - selectedSites );
683
684 disableSitesSelection = ( 0 === activationsLeft );
685
686 $activationsLeft.text( activationsLeft );
687 } else {
688 disableSitesSelection = false;
689 }
690
691 $sitesListContainer
692 .find( 'input[type="checkbox"]:not(:checked)' )
693 .attr( 'disabled', disableSitesSelection );
694 }
695
696 /**
697 * @author Leo Fajardo (@leorw)
698 * @since 2.0.0
699 *
700 * @returns {Boolean}
701 */
702 function isOtherLicenseKeySelected() {
703 return ( hasLicenseTypes && 'other' === $licenseTypes.filter( ':checked' ).val() );
704 }
705
706 /**
707 * @author Leo Fajardo (@leorw)
708 * @since 2.0.0
709 *
710 * @returns {Boolean}
711 */
712 function hasValidLicenseKey() {
713 var licenseKey = '';
714 if ( hasLicenseTypes ) {
715 if ( 'available' === $licenseTypes.filter( ':checked' ).val() ) {
716 return true;
717 } else {
718 licenseKey = $otherLicenseKey.val();
719 }
720 } else {
721 licenseKey = $modal.find( 'input.fs-license-key' ).val();
722 }
723
724 return ( licenseKey.trim().length > 0 );
725 }
726
727 /**
728 * @author Leo Fajardo (@leorw)
729 * @since 2.0.0
730 *
731 * @returns {Boolean}
732 */
733 function hasSelectedSite() {
734 return ( $applyOnAllSites.is( ':checked' ) ||
735 $sitesListContainer.find( 'input[type="checkbox"]:checked:not(:disabled)' ).length > 0 );
736 }
737
738 /**
739 * @author Leo Fajardo (@leorw)
740 * @since 2.0.0
741 */
742 function toggleActivationOnAllSites() {
743 var activationsLeft,
744 licenseID;
745
746 if (hasLicensesDropdown) {
747 var $selectedOption = $licensesDropdown.find( ':selected' );
748 activationsLeft = $selectedOption.data('left');
749 licenseID = $selectedOption.data('id');
750 } else {
751 activationsLeft = $availableLicenseKey.data('left');
752 licenseID = $availableLicenseKey.data('id');
753 }
754
755 // Cleanup previously auto-selected site.
756 $modal.find( '.fs-sites-list-container input[type=checkbox]:disabled' )
757 .attr('disabled', false)
758 .attr('checked', false);
759
760 var $blogsWithActiveLicense = $modal.find( '.fs-sites-list-container tr[data-license-id=' + licenseID + '] input[type=checkbox]' );
761
762 if ($blogsWithActiveLicense.length > 0) {
763 $blogsWithActiveLicense.attr('checked', true)
764 .attr('disabled', true);
765
766 activationsLeft += $blogsWithActiveLicense.length;
767 }
768
769 if ( activationsLeft >= totalSites ) {
770 $applyOnAllSites.attr( 'disabled', false );
771 enableDisableSitesSelection();
772
773 resetActivateLicenseCheckboxLabel();
774
775 return;
776 }
777
778 $applyOnAllSites.attr( 'checked', false );
779 $applyOnAllSites.attr( 'disabled', true );
780
781 showSites( true );
782
783 var
784 activateLicenseCheckboxLabel = '<?php fs_esc_js_echo_inline( 'Choose up to %s site(s) to activate the license on.', 'choose-up-to-n-sites-to-activate-the-license-on', $slug ) ?>';
785
786 activateLicenseCheckboxLabel = activateLicenseCheckboxLabel.replace( '%s', '<span data-left="' + activationsLeft + '" class="activations-left">' + activationsLeft + '</span>' );
787
788 // Update the label of the "Activate license on all sites" checkbox.
789 $applyOnAllSites.parent().find( 'span' ).html( activateLicenseCheckboxLabel );
790 $activationsLeft = $modal.find( '.activations-left' );
791
792 if ( hasSelectedSite() ) {
793 enableActivateLicenseButton();
794 enableDisableSitesSelection();
795 } else {
796 disableActivateLicenseButton();
797 }
798 }
799
800 /**
801 * @author Leo Fajardo (@leorw)
802 * @since 2.0.0
803 */
804 function resetActivateLicenseCheckboxLabel() {
805 var activateLicenseCheckboxLabel = '<?php fs_esc_js_echo_inline( 'Activate license on all sites in the network.', 'activate-license-on-all-sites-in-the-network', $slug ) ?>';
806 $applyOnAllSites.parent().find( 'span' ).text( activateLicenseCheckboxLabel );
807 }
808
809 /**
810 * @author Leo Fajardo (@leorw)
811 * @since 2.0.0
812 *
813 * @param {Boolean} show
814 */
815 function showSites( show ) {
816 $sitesListContainer.toggle( show );
817 if ( show && null === maxSitesListHeight ) {
818 /**
819 * Set the visible number of rows to 5 (5 * height of the first row).
820 *
821 * @author Leo Fajardo (@leorw)
822 */
823 maxSitesListHeight = ( 5 * $sitesListContainer.find( 'tr:first' ).height() );
824 $sitesListContainer.css( 'max-height', maxSitesListHeight );
825 }
826 }
827
828 function showModal( evt ) {
829 resetModal();
830
831 // Display the dialog box.
832 $modal.addClass('active');
833 $body.addClass('has-fs-modal');
834
835 var
836 $singleInstallDetails = $( evt.target ).parents( 'tr.fs-install-details' ),
837 isSingleSiteActivation = ( $singleInstallDetails.length > 0 );
838
839 $modal.toggleClass( 'is-single-site-activation', isSingleSiteActivation );
840
841 singleBlogID = isSingleSiteActivation ?
842 $singleInstallDetails.prev().data( 'blog-id' ) :
843 null;
844
845 <?php if ( $fs->apply_filters( 'enable_per_site_activation', true ) ) : ?>
846 $multisiteOptionsContainer.toggle( isNetworkActivation && ! isSingleSiteActivation );
847 <?php endif ?>
848
849 if ( hasLicenseTypes ) {
850 $licenseTypes.attr( 'checked', false );
851
852 if ( hasLicensesDropdown ) {
853 $licensesDropdown.find( 'option:first' ).attr( 'selected', true ).trigger( 'change' );
854 } else {
855 $licenseTypes.filter( '[value="available"]' ).click();
856 }
857
858 $otherLicenseKey.val( '' );
859 } else {
860 $licenseKeyInput.val( '' );
861 $licenseKeyInput.focus();
862 }
863 }
864
865 function closeModal() {
866 $modal.removeClass('active');
867 $body.removeClass('has-fs-modal');
868 }
869
870 function resetActivateLicenseButton() {
871 enableActivateLicenseButton();
872 $activateLicenseButton.text( <?php echo json_encode( $activate_button_text ) ?> );
873 }
874
875 function resetModal() {
876 hideError();
877 resetActivateLicenseButton();
878 }
879
880 function enableActivateLicenseButton() {
881 $activateLicenseButton.removeClass( 'disabled' );
882 }
883
884 function disableActivateLicenseButton() {
885 $activateLicenseButton.addClass( 'disabled' );
886 }
887
888 function hideError() {
889 $licenseActivationMessage.hide();
890 }
891
892 function showError( msg ) {
893 $licenseActivationMessage.find( ' > p' ).html( msg );
894 $licenseActivationMessage.show();
895 }
896 });
897 })( jQuery );
898 </script>
899 <?php
900 fs_require_once_template( 'api-connectivity-message-js.php' );