1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
<?php /** * @package Freemius * @copyright Copyright (c) 2015, Freemius, Inc. * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 * @since 1.2.1.5 */
if ( ! defined( 'ABSPATH' ) ) { exit; }
/** * @var array $VARS * @var Freemius $fs */ $slug = $VARS['slug']; $plugin_id = $VARS['target_module_id'];
$fs = freemius( $VARS['id'] );
$action = $fs->is_tracking_allowed() ? 'stop_tracking' : 'allow_tracking';
$title = $fs->get_plugin_title();
if ( $plugin_id != $fs->get_id() ) { $addon = $fs->get_addon( $plugin_id );
if ( is_object( $addon ) ) { $title = $addon->title . ' ' . fs_text_inline( 'Add-On', 'addon', $slug ); } }
$plugin_title = sprintf( '<strong>%s</strong>', esc_html( $title ) );
$sec_countdown = 30; $countdown_html = sprintf( esc_js( /* translators: %s: Number of seconds */ fs_text_inline( '%s sec', 'x-sec', $slug ) ), sprintf( '<span class="fs-countdown">%s</span>', $sec_countdown ) );
fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' ); fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
$params = array(); $loader_html = fs_get_template( 'ajax-loader.php', $params );
// Pass unique auto installation URL if WP_Filesystem is needed. $install_url = $fs->_get_sync_license_url( $plugin_id, true, array( 'auto_install' => 'true' ) );
ob_start();
$method = ''; // Leave blank so WP_Filesystem can populate it as necessary.
$credentials = request_filesystem_credentials( esc_url_raw( $install_url ), $method, false, WP_PLUGIN_DIR, array() );
$credentials_form = ob_get_clean();
$require_credentials = ! empty( $credentials_form ); ?> <div class="fs-modal fs-modal-auto-install"> <div class="fs-modal-dialog"> <div class="fs-modal-header"> <h4><?php echo esc_js( fs_text_inline( 'Automatic Installation', 'auto-installation', $slug ) ) ?></h4> </div> <div class="fs-modal-body"> <div class="fs-notice-error" style="display: none"><p></p></div> <?php if ( $require_credentials ) : ?> <div id="request-filesystem-credentials-dialog"> <?php echo $credentials_form ?> </div> <?php else : ?> <p class="fs-installation-notice"><?php echo sprintf( fs_esc_html_inline( 'An automated download and installation of %s (paid version) from %s will start in %s. If you would like to do it manually - click the cancellation button now.', 'installing-in-n', $slug ), $plugin_title, sprintf( '<a href="%s" target="_blank">%s</a>', 'https://freemius.com', 'freemius.com' ), $countdown_html ) ?></p> <?php endif ?> <p class="fs-installing" style="display: none"><?php echo sprintf( fs_esc_html_inline( 'The installation process has started and may take a few minutes to complete. Please wait until it is done - do not refresh this page.', 'installing-module-x', $slug ), $plugin_title ) ?></p> </div> <div class="fs-modal-footer"> <?php echo $loader_html ?> <button class="button button-secondary button-cancel"><?php fs_esc_html_echo_inline( 'Cancel Installation', 'cancel-installation', $slug ) ?><?php if ( ! $require_credentials ) : ?> (<?php echo $countdown_html ?>)<?php endif ?></button> <button class="button button-primary"><?php fs_esc_html_echo_inline( 'Install Now', 'install-now', $slug ) ?></button> </div> </div> </div>'
<script type="text/javascript"> (function ($) { $(document).ready(function () { var $modal = $('.fs-modal-auto-install'), $body = $('body'), $countdown = $modal.find('.fs-countdown'), requireCredentials = <?php echo json_encode( $require_credentials ) ?>, $credentialsForm = $('#request-filesystem-credentials-dialog'), $errorNotice = $modal.find('.fs-notice-error'), installing = false;
$modal.appendTo($body);
var startAutoInstall = function () { if (installing) return;
installing = true;
// Start auto-install. $modal.addClass('fs-warn'); if (requireCredentials) { $credentialsForm.hide(); } else { $modal.find('.fs-installation-notice').hide(); }
$errorNotice.hide(); $modal.find('.fs-installing').show(); $modal.find('button').hide(); $modal.find('.fs-ajax-loader').show();
var data = { action : '<?php echo $fs->get_ajax_action( 'install_premium_version' ) ?>', security : '<?php echo $fs->get_ajax_security( 'install_premium_version' ) ?>', slug : '<?php echo $slug ?>', module_id : '<?php echo $fs->get_id() ?>', target_module_id: '<?php echo $plugin_id ?>' };
if (requireCredentials) { // Add filesystem credentials. data.hostname = $('#hostname').val(); data.username = $('#username').val(); data.password = $('#password').val(); data.connection_type = $('input[name="connection_type"]:checked').val(); data.public_key = $('#public_key').val(); data.private_key = $('#private_key').val(); }
$.ajax({ url : ajaxurl, method : 'POST', data : data, success: function (resultObj) { var reloadAccount = false;
if (resultObj.success) { // Reload account page to show new data. reloadAccount = true; } else { switch (resultObj.error.code) { case 'invalid_module_id': case 'premium_installed': reloadAccount = true; break; case 'invalid_license': case 'premium_version_missing': case 'unable_to_connect_to_filesystem': default: $modal.removeClass('fs-warn'); $modal.find('.fs-installing').hide(); $modal.find('.fs-ajax-loader').hide(); $modal.find('.button-cancel').html(<?php fs_json_encode_echo_inline( 'Cancel Installation', 'cancel-installation', $slug ) ?>); $modal.find('button').show();
$errorNotice.find('p').text(resultObj.error.message); $errorNotice.addClass('notice notice-alt notice-error').show(); if (requireCredentials) { $credentialsForm.show(); } break; } }
if (reloadAccount) { window.location = '<?php echo $fs->get_account_url() ?>'; }
installing = false; } }); };
var clearCountdown = function () { clearInterval(countdownInterval); countdownInterval = null; };
var cancelAutoInstall = function () { $modal.fadeOut(function () { $modal.remove(); $body.removeClass('has-fs-modal'); }); };
var countdown = <?php echo $sec_countdown ?>, countdownInterval = requireCredentials ? null : setInterval(function () { $countdown.html(--countdown); if (0 == countdown) { clearCountdown(); startAutoInstall(); } }, 1000);
$modal.addClass('active'); $body.addClass('has-fs-modal');
$modal.find('.button-primary').click(function () { clearCountdown(); startAutoInstall(); });
$modal.find('.button-cancel').click(function () { clearCountdown(); cancelAutoInstall(); });
if (requireCredentials) {
} }); })(jQuery); </script>
|