Plugin Directory

source: ultimakit-for-wp/tags/1.2.0/src/freemius/templates/forms/data-debug-mode.php @ 3096242

Last change on this file since 3096242 was 3096242, checked in by ankitmaru, 8 weeks ago

1.2.0. - New modules added: (Free) - Change Admin Email, Show Active Plugins First, Redirect After Login, Redirect After Logout, Term Order; (PRO) - Front-End Login Form, UTM Builder; Modules listing layout updated; Minimize and maximize modules listing; Search modules feature added; Minor fixes & improvements.

File size: 7.8 KB
Line 
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     2.3.1
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    $last_license_user_id     = $fs->get_last_license_user_id();
22    $has_last_license_user_id = FS_User::is_valid_id( $last_license_user_id );
23   
24        $message_above_input_field = ( ! $has_last_license_user_id ) ?
25                fs_text_inline( 'Please enter the license key to enable the debug mode:', 'submit-developer-license-key-message', $slug ) :
26                sprintf(
27                        fs_text_inline( 'To enter the debug mode, please enter the secret key of the license owner (UserID = %d), which you can find in your "My Profile" section of your User Dashboard:', 'submit-addon-developer-key-message', $slug ),
28                        $last_license_user_id
29                );
30
31    $processing_text          = ( fs_esc_js_inline( 'Processing', 'processing', $slug ) . '...' );
32    $submit_button_text       = fs_text_inline( 'Submit', 'submit', $slug );
33    $debug_license_link_text  = fs_esc_html_inline( 'Start Debug', 'start-debug-license', $slug );
34    $license_or_user_key_text = ( ! $has_last_license_user_id ) ?
35        fs_text_inline( 'License key', 'license-key' , $slug ) :
36        fs_text_inline( 'User key', 'user-key' , $slug );
37    $input_html               = "<input class='fs-license-or-user-key' type='password' placeholder='{$license_or_user_key_text}' tabindex='1' />";
38
39        $modal_content_html = <<< HTML
40        <div class="notice notice-error inline license-or-user-key-submission-message"><p></p></div>
41        <p>{$message_above_input_field}</p>
42        {$input_html}
43HTML;
44
45        fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' );
46?>
47<script type="text/javascript">
48( function( $ ) {
49        $( document ).ready( function() {
50                var modalContentHtml          = <?php echo json_encode( $modal_content_html ) ?>,
51                        modalHtml                 =
52                                '<div class="fs-modal fs-modal-developer-license-debug-mode fs-modal-developer-license-debug-mode-<?php echo $unique_affix ?>">'
53                                + '     <div class="fs-modal-dialog">'
54                                + '             <div class="fs-modal-body">'
55                                + '                     <div class="fs-modal-panel active">' + modalContentHtml + '</div>'
56                                + '             </div>'
57                                + '             <div class="fs-modal-footer">'
58                                + '                     <button class="button button-secondary button-close" tabindex="4"><?php fs_esc_js_echo_inline( 'Cancel', 'cancel', $slug ) ?></button>'
59                                + '                     <button class="button button-primary button-submit-license-or-user-key"  tabindex="3"><?php echo esc_js( $submit_button_text ) ?></button>'
60                                + '             </div>'
61                                + '     </div>'
62                                + '</div>',
63                        $modal                             = $( modalHtml ),
64            $debugLicenseLink                  = $( '.debug-license-trigger' ),
65                        $submitKeyButton                   = $modal.find( '.button-submit-license-or-user-key' ),
66                        $licenseOrUserKeyInput             = $modal.find( 'input.fs-license-or-user-key' ),
67                        $licenseOrUserKeySubmissionMessage = $modal.find( '.license-or-user-key-submission-message' ),
68            isDebugMode                        = <?php echo $fs->is_data_debug_mode() ? 'true' : 'false' ?>;
69
70                $modal.appendTo( $( 'body' ) );
71
72                function registerEventHandlers() {
73            $debugLicenseLink.click(function (evt) {
74                evt.preventDefault();
75
76                if ( isDebugMode ) {
77                    setDeveloperLicenseDebugMode();
78                    return true;
79                }
80
81                showModal( evt );
82            });
83
84                        $modal.on( 'input propertychange', 'input.fs-license-or-user-key', function () {
85                                var licenseOrUserKey = $( this ).val().trim();
86
87                                /**
88                                 * If license or user key is not empty, enable the submission button.
89                                 */
90                                if ( licenseOrUserKey.length > 0 ) {
91                                        enableSubmitButton();
92                                }
93                        });
94
95                        $modal.on( 'blur', 'input.fs-license-or-user-key', function () {
96                                var licenseOrUserKey = $( this ).val().trim();
97
98                /**
99                 * If license or user key is empty, disable the submission button.
100                 */
101                if ( 0 === licenseOrUserKey.length ) {
102                   disableSubmitButton();
103                }
104                        });
105
106                        $modal.on( 'click', '.button-submit-license-or-user-key', function ( evt ) {
107                                evt.preventDefault();
108
109                                if ( $( this ).hasClass( 'disabled' ) ) {
110                                        return;
111                                }
112
113                                var licenseOrUserKey = $licenseOrUserKeyInput.val().trim();
114
115                                disableSubmitButton();
116
117                                if ( 0 === licenseOrUserKey.length ) {
118                                        return;
119                                }
120
121                setDeveloperLicenseDebugMode( licenseOrUserKey );
122                        });
123
124                        // If the user has clicked outside the window, close the modal.
125                        $modal.on( 'click', '.fs-close, .button-secondary', function () {
126                                closeModal();
127                                return false;
128                        } );
129                }
130
131                registerEventHandlers();
132
133                function setDeveloperLicenseDebugMode( licenseOrUserKey ) {
134            var data = {
135                action             : '<?php echo $fs->get_ajax_action( 'set_data_debug_mode' ) ?>',
136                security           : '<?php echo $fs->get_ajax_security( 'set_data_debug_mode' ) ?>',
137                license_or_user_key: licenseOrUserKey,
138                is_debug_mode      : isDebugMode,
139                module_id          : '<?php echo $fs->get_id() ?>'
140            };
141
142            $.ajax( {
143                url       : <?php echo Freemius::ajax_url() ?>,
144                method    : 'POST',
145                data      : data,
146                beforeSend: function () {
147                    $debugLicenseLink.find('span').text( '<?php echo $processing_text ?>' );
148                    $submitKeyButton.text( '<?php echo $processing_text ?>' );
149                },
150                success   : function ( result ) {
151                    if ( result.success ) {
152                        closeModal();
153
154                        // Reload the "Account" page so that the pricing/upgrade link will be properly hidden/shown.
155                        window.location.reload();
156                    } else {
157                        showError( result.error.message ? result.error.message : result.error );
158                        resetButtons();
159                    }
160                },
161                error     : function () {
162                    showError( <?php echo json_encode( fs_text_inline( 'An unknown error has occurred.', 'unknown-error', $slug ) ) ?> );
163                    resetButtons();
164                }
165            });
166        }
167
168                function showModal( evt ) {
169                        resetModal();
170
171                        // Display the dialog box.
172                        $modal.addClass( 'active' );
173                        $( 'body' ).addClass( 'has-fs-modal' );
174
175            $licenseOrUserKeyInput.val( '' );
176            $licenseOrUserKeyInput.focus();
177                }
178
179                function closeModal() {
180                        $modal.removeClass( 'active' );
181                        $( 'body' ).removeClass( 'has-fs-modal' );
182                }
183
184                function resetButtons() {
185                        enableSubmitButton();
186                        $submitKeyButton.text( <?php echo json_encode( $submit_button_text ) ?> );
187                        $debugLicenseLink.find('span').text( <?php echo json_encode( $debug_license_link_text ) ?> );
188                }
189
190                function resetModal() {
191                        hideError();
192                        resetButtons();
193                }
194
195                function enableSubmitButton() {
196                        $submitKeyButton.removeClass( 'disabled' );
197                }
198
199                function disableSubmitButton() {
200                        $submitKeyButton.addClass( 'disabled' );
201                }
202
203                function hideError() {
204                        $licenseOrUserKeySubmissionMessage.hide();
205                }
206
207                function showError( msg ) {
208                        $licenseOrUserKeySubmissionMessage.find( ' > p' ).html( msg );
209                        $licenseOrUserKeySubmissionMessage.show();
210                }
211        } );
212} )( jQuery );
213</script>
Note: See TracBrowser for help on using the repository browser.