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
optout.php
217 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.1.5 |
| 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 | $action = $fs->is_tracking_allowed() ? |
| 20 | 'stop_tracking' : |
| 21 | 'allow_tracking'; |
| 22 | |
| 23 | $plugin_title = "<strong>{$fs->get_plugin()->title}</strong>"; |
| 24 | $opt_out_button_text = __fs( 'opt-out', $slug ); |
| 25 | // @todo Change 'plugin' with module type when migrating with 1.2.2 (themes version). |
| 26 | $opt_out_message_appreciation = sprintf( __fs( 'opt-out-message-appreciation', $slug ), 'plugin' ); |
| 27 | $opt_out_message_usage_tracking = sprintf( __fs( 'opt-out-message-usage-tracking', $slug ), $plugin_title ); |
| 28 | $opt_out_message_clicking_opt_out = sprintf( |
| 29 | __fs( 'opt-out-message-clicking-opt-out', $slug ), |
| 30 | $plugin_title, |
| 31 | sprintf( |
| 32 | '<a href="%s" target="_blank">%s</a>', |
| 33 | 'https://freemius.com', |
| 34 | 'freemius.com' |
| 35 | ) |
| 36 | ); |
| 37 | |
| 38 | $admin_notice_params = array( |
| 39 | 'id' => '', |
| 40 | 'slug' => $fs->get_id(), |
| 41 | 'type' => 'success', |
| 42 | 'sticky' => false, |
| 43 | 'plugin' => $fs->get_plugin()->title, |
| 44 | 'message' => $opt_out_message_appreciation |
| 45 | ); |
| 46 | |
| 47 | $admin_notice_html = fs_get_template( 'admin-notice.php', $admin_notice_params ); |
| 48 | |
| 49 | $modal_content_html = <<< HTML |
| 50 | <h2>{$opt_out_message_appreciation}</h2> |
| 51 | <div class="notice notice-error inline opt-out-error-message"><p></p></div> |
| 52 | <p>{$opt_out_message_usage_tracking}</p> |
| 53 | <p>{$opt_out_message_clicking_opt_out}</p> |
| 54 | HTML; |
| 55 | |
| 56 | fs_enqueue_local_style( 'dialog-boxes', '/admin/dialog-boxes.css' ); |
| 57 | fs_enqueue_local_style( 'fs_common', '/admin/common.css' ); |
| 58 | ?> |
| 59 | <script type="text/javascript"> |
| 60 | (function( $ ) { |
| 61 | $( document ).ready(function() { |
| 62 | var modalContentHtml = <?php echo json_encode( $modal_content_html ) ?>, |
| 63 | modalHtml = |
| 64 | '<div class="fs-modal fs-modal-opt-out">' |
| 65 | + ' <div class="fs-modal-dialog">' |
| 66 | + ' <div class="fs-modal-header">' |
| 67 | + ' <h4><?php echo esc_js($opt_out_button_text) ?></h4>' |
| 68 | + ' </div>' |
| 69 | + ' <div class="fs-modal-body">' |
| 70 | + ' <div class="fs-modal-panel active">' + modalContentHtml + '</div>' |
| 71 | + ' </div>' |
| 72 | + ' <div class="fs-modal-footer">' |
| 73 | + ' <button class="button button-secondary button-opt-out" tabindex="1"><?php echo esc_js($opt_out_button_text) ?></button>' |
| 74 | + ' <button class="button button-primary button-close" tabindex="2"><?php echo esc_js( __fs( 'opt-out-cancel', $slug ) ) ?></button>' |
| 75 | + ' </div>' |
| 76 | + ' </div>' |
| 77 | + '</div>', |
| 78 | $modal = $( modalHtml ), |
| 79 | $adminNotice = $( <?php echo json_encode( $admin_notice_html ) ?> ), |
| 80 | action = '<?php echo $action ?>', |
| 81 | optOutActionTag = '<?php echo $fs->get_action_tag( 'stop_tracking' ) ?>', |
| 82 | optInActionTag = '<?php echo $fs->get_action_tag( 'allow_tracking' ) ?>', |
| 83 | $actionLink = $( 'span.opt-in-or-opt-out.<?php echo $VARS['slug'] ?> a' ), |
| 84 | $optOutButton = $modal.find( '.button-opt-out' ), |
| 85 | $optOutErrorMessage = $modal.find( '.opt-out-error-message' ), |
| 86 | pluginSlug = '<?php echo $slug ?>'; |
| 87 | |
| 88 | $actionLink.attr( 'data-action', action ); |
| 89 | $modal.appendTo( $( 'body' ) ); |
| 90 | |
| 91 | function registerEventHandlers() { |
| 92 | $actionLink.click(function( evt ) { |
| 93 | evt.preventDefault(); |
| 94 | |
| 95 | if ( 'stop_tracking' == $actionLink.attr( 'data-action' ) ) { |
| 96 | showModal(); |
| 97 | } else { |
| 98 | optIn(); |
| 99 | } |
| 100 | }); |
| 101 | |
| 102 | $modal.on( 'click', '.button-opt-out', function( evt ) { |
| 103 | evt.preventDefault(); |
| 104 | |
| 105 | if ( $( this ).hasClass( 'disabled' ) ) { |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | disableOptOutButton(); |
| 110 | optOut(); |
| 111 | }); |
| 112 | |
| 113 | // If the user has clicked outside the window, close the modal. |
| 114 | $modal.on( 'click', '.fs-close, .button-close', function() { |
| 115 | closeModal(); |
| 116 | return false; |
| 117 | }); |
| 118 | } |
| 119 | |
| 120 | registerEventHandlers(); |
| 121 | |
| 122 | function showModal() { |
| 123 | resetModal(); |
| 124 | |
| 125 | // Display the dialog box. |
| 126 | $modal.addClass( 'active' ); |
| 127 | $( 'body' ).addClass( 'has-fs-modal' ); |
| 128 | } |
| 129 | |
| 130 | function closeModal() { |
| 131 | $modal.removeClass( 'active' ); |
| 132 | $( 'body' ).removeClass( 'has-fs-modal' ); |
| 133 | } |
| 134 | |
| 135 | function resetOptOutButton() { |
| 136 | enableOptOutButton(); |
| 137 | $optOutButton.text( <?php echo json_encode($opt_out_button_text) ?> ); |
| 138 | } |
| 139 | |
| 140 | function resetModal() { |
| 141 | hideError(); |
| 142 | resetOptOutButton(); |
| 143 | } |
| 144 | |
| 145 | function optIn() { |
| 146 | sendRequest(); |
| 147 | } |
| 148 | |
| 149 | function optOut() { |
| 150 | sendRequest(); |
| 151 | } |
| 152 | |
| 153 | function sendRequest() { |
| 154 | $.ajax({ |
| 155 | url: ajaxurl, |
| 156 | method: 'POST', |
| 157 | data: { |
| 158 | action: ( 'stop_tracking' == action ? optOutActionTag : optInActionTag ), |
| 159 | slug : pluginSlug |
| 160 | }, |
| 161 | beforeSend: function() { |
| 162 | if ( 'opt-in' == action ) { |
| 163 | $actionLink.text( <?php fs_json_encode_echo( 'opting-in', $slug ) ?> ) |
| 164 | } else { |
| 165 | $optOutButton.text( <?php fs_json_encode_echo( 'opting-out', $slug ) ?> ); |
| 166 | } |
| 167 | }, |
| 168 | success: function( resultObj ) { |
| 169 | if ( resultObj.success ) { |
| 170 | if ( 'allow_tracking' == action ) { |
| 171 | action = 'stop_tracking'; |
| 172 | $actionLink.text( <?php fs_json_encode_echo( 'opt-out', $slug ) ?> ); |
| 173 | showOptInAppreciationMessageAndScrollToTop(); |
| 174 | } else { |
| 175 | action = 'allow_tracking'; |
| 176 | $actionLink.text( <?php fs_json_encode_echo( 'opt-in', $slug ) ?> ); |
| 177 | closeModal(); |
| 178 | |
| 179 | if ( $adminNotice.length > 0 ) { |
| 180 | $adminNotice.remove(); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | $actionLink.attr( 'data-action', action ); |
| 185 | } else { |
| 186 | showError( resultObj.error ); |
| 187 | resetOptOutButton(); |
| 188 | } |
| 189 | } |
| 190 | }); |
| 191 | } |
| 192 | |
| 193 | function enableOptOutButton() { |
| 194 | $optOutButton.removeClass( 'disabled' ); |
| 195 | } |
| 196 | |
| 197 | function disableOptOutButton() { |
| 198 | $optOutButton.addClass( 'disabled' ); |
| 199 | } |
| 200 | |
| 201 | function hideError() { |
| 202 | $optOutErrorMessage.hide(); |
| 203 | } |
| 204 | |
| 205 | function showOptInAppreciationMessageAndScrollToTop() { |
| 206 | $adminNotice.insertAfter( $( '#wpbody-content' ).find( ' > .wrap > h1' ) ); |
| 207 | window.scrollTo(0, 0); |
| 208 | } |
| 209 | |
| 210 | function showError( msg ) { |
| 211 | $optOutErrorMessage.find( ' > p' ).html( msg ); |
| 212 | $optOutErrorMessage.show(); |
| 213 | } |
| 214 | }); |
| 215 | })( jQuery ); |
| 216 | </script> |
| 217 |