deactivation
9 years ago
index.php
9 years ago
license-activation.php
9 years ago
optout.php
9 years ago
resend-key.php
9 years ago
trial-start.php
9 years ago
trial-start.php
179 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package Freemius |
| 4 | * @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 6 | * @since 1.2.0 |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * @var array $VARS |
| 15 | */ |
| 16 | $slug = $VARS['slug']; |
| 17 | $fs = freemius( $slug ); |
| 18 | |
| 19 | $message_header = sprintf( |
| 20 | fs_text( 'start-trial-prompt-header', $slug ), |
| 21 | '<span class="var-trial_period"></span>', |
| 22 | '<span class="var-plan_title"></span>' |
| 23 | ); |
| 24 | $message_content = sprintf( |
| 25 | fs_text( 'start-trial-prompt-message', $slug ), |
| 26 | sprintf( |
| 27 | '<a href="%s" target="_blank">%s</a>', |
| 28 | 'https://freemius.com', |
| 29 | 'freemius.com' |
| 30 | ) |
| 31 | ); |
| 32 | |
| 33 | $modal_content_html = <<< HTML |
| 34 | <div class="notice notice-error inline"><p></p></div> |
| 35 | <h3>{$message_header}</h3> |
| 36 | <p>{$message_content}</p> |
| 37 | HTML; |
| 38 | |
| 39 | fs_enqueue_local_style( 'dialog-boxes', '/admin/dialog-boxes.css' ); |
| 40 | ?> |
| 41 | <script type="text/javascript"> |
| 42 | (function ($) { |
| 43 | $(document).ready(function () { |
| 44 | var modalContentHtml = <?php echo json_encode( $modal_content_html ); ?>, |
| 45 | modalHtml = |
| 46 | '<div class="fs-modal fs-modal-license-key-resend">' |
| 47 | + ' <div class="fs-modal-dialog">' |
| 48 | + ' <div class="fs-modal-header">' |
| 49 | + ' <h4><?php fs_esc_js_echo( 'start-free-trial', $slug ) ?></h4>' |
| 50 | + ' </div>' |
| 51 | + ' <div class="fs-modal-body">' + modalContentHtml + '</div>' |
| 52 | + ' <div class="fs-modal-footer">' |
| 53 | + ' <button class="button button-secondary button-close">' + <?php fs_json_encode_echo( 'cancel', $slug ) ?> +'</button>' |
| 54 | + ' <button class="button button-primary button-connect">' + <?php fs_json_encode_echo( 'approve-start-trial', $slug ) ?> +'</button>' |
| 55 | + ' </div>' |
| 56 | + ' </div>' |
| 57 | + '</div>', |
| 58 | $modal = $(modalHtml), |
| 59 | moduleSlug = '<?php echo $slug; ?>', |
| 60 | trialData; |
| 61 | |
| 62 | $modal.appendTo($('body')); |
| 63 | |
| 64 | var $errorNotice = $modal.find('.notice-error'); |
| 65 | |
| 66 | registerEventHandlers(); |
| 67 | |
| 68 | function registerEventHandlers() { |
| 69 | $modal.on('click', '.button-close', function () { |
| 70 | closeModal(); |
| 71 | return false; |
| 72 | }); |
| 73 | |
| 74 | $modal.on('click', '.button-connect', function (evt) { |
| 75 | evt.preventDefault(); |
| 76 | |
| 77 | var $button = $(this); |
| 78 | |
| 79 | $.ajax({ |
| 80 | url : ajaxurl, |
| 81 | method : 'POST', |
| 82 | data : { |
| 83 | action : '<?php echo $fs->get_ajax_action( 'start_trial' ) ?>', |
| 84 | security: '<?php echo $fs->get_ajax_security( 'start_trial' ) ?>', |
| 85 | slug : moduleSlug, |
| 86 | trial : trialData |
| 87 | }, |
| 88 | beforeSend: function () { |
| 89 | // Disable all buttons during trial activation. |
| 90 | $modal.find('.button').prop('disabled', true); |
| 91 | |
| 92 | $button.text(<?php fs_json_encode_echo( 'starting-trial', $slug ) ?> + '...'); |
| 93 | |
| 94 | setLoadingMode(); |
| 95 | }, |
| 96 | success : function (resultObj) { |
| 97 | if (resultObj.success) { |
| 98 | $button.text(<?php fs_json_encode_echo( 'please-wait', $slug ) ?> + '...'); |
| 99 | |
| 100 | // Redirect to the "Account" page and sync the license. |
| 101 | window.location.href = resultObj.data.next_page; |
| 102 | } else { |
| 103 | $button.text(<?php fs_json_encode_echo( 'approve-start-trial', $slug ) ?>); |
| 104 | |
| 105 | resetLoadingMode(); |
| 106 | showError(resultObj.error); |
| 107 | } |
| 108 | } |
| 109 | }); |
| 110 | }); |
| 111 | } |
| 112 | |
| 113 | window.openTrialConfirmationModal = function showModal(data) { |
| 114 | resetModal(); |
| 115 | |
| 116 | // Display the dialog box. |
| 117 | $modal.addClass('active'); |
| 118 | |
| 119 | trialData = data; |
| 120 | |
| 121 | var $modalBody = $modal.find('.fs-modal-body'), |
| 122 | $var; |
| 123 | |
| 124 | for (var key in data) { |
| 125 | if (data.hasOwnProperty(key)) { |
| 126 | $var = $modalBody.find('.var-' + key); |
| 127 | |
| 128 | if ($var.length > 0) |
| 129 | $var.html(data[key]); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | $('body').addClass('has-fs-modal'); |
| 134 | }; |
| 135 | |
| 136 | function closeModal() { |
| 137 | $modal.removeClass('active'); |
| 138 | |
| 139 | $('body').removeClass('has-fs-modal'); |
| 140 | } |
| 141 | |
| 142 | function resetModal() { |
| 143 | hideError(); |
| 144 | } |
| 145 | |
| 146 | function hideError() { |
| 147 | $errorNotice.hide(); |
| 148 | } |
| 149 | |
| 150 | function setLoadingMode() { |
| 151 | $modal.find('.button') |
| 152 | // Re-enable all buttons. |
| 153 | .prop('disabled', trialData) |
| 154 | // Stop loading cursor. |
| 155 | .css({'cursor': 'wait'}); |
| 156 | |
| 157 | // Stop loading cursor. |
| 158 | $(document.body).css({'cursor': 'wait'}); |
| 159 | } |
| 160 | |
| 161 | function resetLoadingMode() { |
| 162 | $modal.find('.button') |
| 163 | // Re-enable all buttons. |
| 164 | .prop('disabled', false) |
| 165 | // Stop loading cursor. |
| 166 | .css({'cursor': 'initial'}); |
| 167 | |
| 168 | // Stop loading cursor. |
| 169 | $(document.body).css({'cursor': 'initial'}); |
| 170 | } |
| 171 | |
| 172 | function showError(msg) { |
| 173 | $errorNotice.find(' > p').html(msg); |
| 174 | $errorNotice.show(); |
| 175 | } |
| 176 | }); |
| 177 | })(jQuery); |
| 178 | </script> |
| 179 |