PluginProbe
WP Directory Kit / trunk
WP Directory Kit vtrunk
1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 1.4.0 1.4.1 All 35 releases
wpdirectorykit / vendor / freemius / templates / debug.php

debug.php in WP Directory Kit trunk, at vendor/freemius/templates/debug.php

951 lines 43.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.1
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 global $fs_active_plugins;
14
15 $fs_options = FS_Options::instance( WP_FS__ACCOUNTS_OPTION_NAME, true );
16
17 $off_text = fs_text_x_inline( 'Off', 'as turned off' );
18 $on_text = fs_text_x_inline( 'On', 'as turned on' );
19
20 // For some reason css was missing
21 fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
22
23 $has_any_active_clone = false;
24
25 $is_multisite = is_multisite();
26
27 $auto_off_timestamp = wp_next_scheduled( 'fs_debug_turn_off_logging_hook' ) * 1000;
28 ?>
29 <h1><?php echo fs_text_inline( 'Freemius Debug' ) . ' - ' . fs_text_inline( 'SDK' ) . ' v.' . $fs_active_plugins->newest->version ?></h1>
30 <div>
31 <!-- Debugging Switch -->
32 <span class="fs-switch-label"><?php fs_esc_html_echo_x_inline( 'Debugging', 'as code debugging' ) ?></span>
33
34 <div class="fs-switch fs-round <?php echo WP_FS__DEBUG_SDK ? 'fs-on' : 'fs-off' ?>">
35 <div class="fs-toggle"></div>
36 </div>
37
38 <span class="auto-off-debug-countdown hidden"><?php echo fs_esc_html_echo_x_inline( 'Auto off in:', 'timer for auto-disabling debug' ); ?> <span class="time">23:59:59</span>
39
40 <script type="text/javascript">
41 (function ($) {
42 $(document).ready(function () {
43 // Switch toggle
44 $( '.fs-switch' ).click( function () {
45 $( this )
46 .toggleClass( 'fs-on' )
47 .toggleClass( 'fs-off' );
48
49 var is_on = ($(this).hasClass( 'fs-on' ) ? 1 : 0);
50
51 $.post( <?php echo Freemius::ajax_url() ?>, {
52 action: 'fs_toggle_debug_mode',
53 // As such we don't need to use `wp_json_encode` method but using it to follow wp.org guideline.
54 _wpnonce : <?php echo wp_json_encode( wp_create_nonce( 'fs_toggle_debug_mode' ) ); ?>,
55 is_on
56 }, function (response) {
57 if (is_on) {
58 startCountdownManually();
59 } else {
60 stopCountdownManually();
61 }
62
63 if ( 1 == response ) {
64 // Refresh page on success.
65 location.reload();
66 }
67 });
68 });
69
70 // Countdown
71 var countdownElement = document.querySelector('.auto-off-debug-countdown');
72 var timeElement = countdownElement.querySelector('.time');
73 var targetTime = <?php echo wp_json_encode( $auto_off_timestamp ); ?>;
74 var countdownTimeout;
75
76 function updateCountdown() {
77 var currentTime = new Date().getTime();
78 var remainingTimeInMs = targetTime - currentTime;
79 var hours = Math.floor((remainingTimeInMs % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
80 var minutes = Math.floor((remainingTimeInMs % (1000 * 60 * 60)) / (1000 * 60));
81 var seconds = Math.floor((remainingTimeInMs % (1000 * 60)) / 1000);
82
83
84 if (remainingTimeInMs < 1000) {
85 countdownElement.classList.add('hidden');
86 countdownTimeout = null;
87 } else {
88 timeElement.innerHTML = hours + ":"
89 + minutes.toString().padStart(2, '0') + ":"
90 + seconds.toString().padStart(2, '0');
91 countdownElement.classList.remove('hidden');
92
93 if (countdownTimeout) {
94 clearTimeout(countdownTimeout);
95 }
96 countdownTimeout = setTimeout(updateCountdown, 1000);
97 }
98 }
99
100 function startCountdownManually() {
101 targetTime = ( new Date().getTime() ) + (24 * 60 * 60 * 1000) - 1;
102 updateCountdown();
103 }
104
105 function stopCountdownManually() {
106 targetTime = new Date().getTime();
107 updateCountdown();
108 }
109
110 updateCountdown();
111 // End countdown
112
113 });
114 }(jQuery));
115 </script>
116 </div>
117 <h2><?php fs_esc_html_echo_inline( 'Actions', 'actions' ) ?></h2>
118 <table>
119 <tbody>
120 <tr>
121 <td>
122 <!-- Delete All Accounts -->
123 <form action="" method="POST">
124 <input type="hidden" name="fs_action" value="restart_freemius">
125 <?php wp_nonce_field( 'restart_freemius' ) ?>
126 <button class="button button-primary"
127 onclick="if (confirm('<?php fs_esc_attr_echo_inline( 'Are you sure you want to delete all Freemius data?', 'delete-all-confirm' ) ?>')) this.parentNode.submit(); return false;"><?php fs_esc_html_echo_inline( 'Delete All Accounts' ) ?></button>
128 </form>
129 </td>
130 <td>
131 <!-- Clear API Cache -->
132 <form action="" method="POST">
133 <input type="hidden" name="fs_clear_api_cache" value="true">
134 <button class="button button-primary"><?php fs_esc_html_echo_inline( 'Clear API Cache' ) ?></button>
135 </form>
136 </td>
137 <td>
138 <!-- Clear Updates Transients -->
139 <form action="" method="POST">
140 <input type="hidden" name="fs_action" value="clear_updates_data">
141 <?php wp_nonce_field( 'clear_updates_data' ) ?>
142 <button class="button"><?php fs_esc_html_echo_inline( 'Clear Updates Transients' ) ?></button>
143 </form>
144 </td>
145 <?php if ( Freemius::is_deactivation_snoozed() ) : ?>
146 <td>
147 <!-- Reset Deactivation Snoozing -->
148 <form action="" method="POST">
149 <input type="hidden" name="fs_action" value="reset_deactivation_snoozing">
150 <?php wp_nonce_field( 'reset_deactivation_snoozing' ) ?>
151 <button class="button"><?php fs_esc_html_echo_inline( 'Reset Deactivation Snoozing' ) ?> (Expires in <?php echo ( Freemius::deactivation_snooze_expires_at() - time() ) ?> sec)</button>
152 </form>
153 </td>
154 <?php endif ?>
155 <td>
156 <!-- Sync Data with Server -->
157 <form action="" method="POST">
158 <input type="hidden" name="background_sync" value="true">
159 <button class="button button-primary"><?php fs_esc_html_echo_inline( 'Sync Data From Server' ) ?></button>
160 </form>
161 </td>
162 <?php if ( fs_is_network_admin() && true !== $fs_options->get_option( 'ms_migration_complete', false, true ) ) : ?>
163 <td>
164 <!-- Migrate Options to Network -->
165 <form action="" method="POST">
166 <input type="hidden" name="fs_action" value="migrate_options_to_network">
167 <?php wp_nonce_field( 'migrate_options_to_network' ) ?>
168 <button class="button button-primary"><?php fs_esc_html_echo_inline( 'Migrate Options to Network' ) ?></button>
169 </form>
170 </td>
171 <?php endif ?>
172 <td>
173 <button id="fs_load_db_option" class="button"><?php fs_esc_html_echo_inline( 'Load DB Option' ) ?></button>
174 </td>
175 <td>
176 <button id="fs_set_db_option" class="button"><?php fs_esc_html_echo_inline( 'Set DB Option' ) ?></button>
177 </td>
178 <td>
179 <?php
180 $fs_debug_page_url = 'admin.php?page=freemius&fs_action=allow_clone_resolution_notice';
181 $fs_debug_page_url = fs_is_network_admin() ?
182 network_admin_url( $fs_debug_page_url ) :
183 admin_url( $fs_debug_page_url );
184 ?>
185 <a href="<?php echo wp_nonce_url( $fs_debug_page_url, 'fs_allow_clone_resolution_notice' ) ?>" class="button button-primary">Resolve Clone(s)</a>
186 </td>
187 </tr>
188 </tbody>
189 </table>
190 <script type="text/javascript">
191 (function ($) {
192 $('#fs_load_db_option').click(function () {
193 var optionName = prompt('Please enter the option name:');
194
195 if (optionName) {
196 $.post(<?php echo Freemius::ajax_url() ?>, {
197 action : 'fs_get_db_option',
198 // As such we don't need to use `wp_json_encode` method but using it to follow wp.org guideline.
199 _wpnonce : <?php echo wp_json_encode( wp_create_nonce( 'fs_get_db_option' ) ); ?>,
200 option_name: optionName
201 }, function (response) {
202 if (response.data.value)
203 prompt('The option value is:', response.data.value);
204 else
205 alert('Oops... Option does not exist in the DB.');
206 });
207 }
208 });
209
210 $('#fs_set_db_option').click(function () {
211 var optionName = prompt('Please enter the option name:');
212
213 if (optionName) {
214 var optionValue = prompt('Please enter the option value:');
215
216 if (optionValue) {
217 $.post(<?php echo Freemius::ajax_url() ?>, {
218 action : 'fs_set_db_option',
219 // As such we don't need to use `wp_json_encode` method but using it to follow wp.org guideline.
220 _wpnonce : <?php echo wp_json_encode( wp_create_nonce( 'fs_set_db_option' ) ); ?>,
221 option_name : optionName,
222 option_value: optionValue
223 }, function () {
224 alert('Option was successfully set.');
225 });
226 }
227 }
228 });
229 })(jQuery);
230 </script>
231 <?php
232 if ( ! defined( 'FS_API__ADDRESS' ) ) {
233 define( 'FS_API__ADDRESS', '://api.freemius.com' );
234 }
235 if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
236 define( 'FS_API__SANDBOX_ADDRESS', '://sandbox-api.freemius.com' );
237 }
238
239 $defines = array(
240 array(
241 'key' => 'WP_FS__REMOTE_ADDR',
242 'val' => WP_FS__REMOTE_ADDR,
243 ),
244 array(
245 'key' => 'WP_FS__ADDRESS_PRODUCTION',
246 'val' => WP_FS__ADDRESS_PRODUCTION,
247 ),
248 array(
249 'key' => 'FS_API__ADDRESS',
250 'val' => FS_API__ADDRESS,
251 ),
252 array(
253 'key' => 'FS_API__SANDBOX_ADDRESS',
254 'val' => FS_API__SANDBOX_ADDRESS,
255 ),
256 array(
257 'key' => 'WP_FS__DIR',
258 'val' => WP_FS__DIR,
259 ),
260 array(
261 'key' => 'wp_using_ext_object_cache()',
262 'val' => wp_using_ext_object_cache() ? 'true' : 'false',
263 ),
264 array(
265 'key' => 'Freemius::get_unfiltered_site_url()',
266 'val' => Freemius::get_unfiltered_site_url(),
267 ),
268 )
269 ?>
270 <br>
271 <table class="widefat">
272 <thead>
273 <tr>
274 <th><?php fs_esc_html_echo_inline( 'Key', 'key' ) ?></th>
275 <th><?php fs_esc_html_echo_inline( 'Value', 'value' ) ?></th>
276 </tr>
277 </thead>
278 <tbody>
279 <?php $alternate = false;
280 foreach ( $defines as $p ) : ?>
281 <tr<?php if ( $alternate ) {
282 echo ' class="alternate"';
283 } ?>>
284 <td><?php echo $p['key'] ?></td>
285 <td><?php echo $p['val'] ?></td>
286 </tr>
287 <?php $alternate = ! $alternate ?>
288 <?php endforeach ?>
289 </tbody>
290 </table>
291 <h2>
292 <button class="fs-debug-table-toggle-button" aria-expanded="true">
293 <span class="fs-debug-table-toggle-icon"></span>
294 </button>
295 <?php fs_esc_html_echo_x_inline( 'SDK Versions', 'as software development kit versions', 'sdk-versions' ) ?>
296 </h2>
297 <table id="fs_sdks" class="widefat fs-debug-table">
298 <thead>
299 <tr>
300 <th><?php fs_esc_html_echo_x_inline( 'Version', 'product version' ) ?></th>
301 <th><?php fs_esc_html_echo_inline( 'SDK Path' ) ?></th>
302 <th><?php fs_esc_html_echo_inline( 'Module Path' ) ?></th>
303 <th><?php fs_esc_html_echo_inline( 'Is Active' ) ?></th>
304 </tr>
305 </thead>
306 <tbody>
307 <?php foreach ( $fs_active_plugins->plugins as $sdk_path => $data ) : ?>
308 <?php $is_active = ( WP_FS__SDK_VERSION == $data->version ) ?>
309 <tr<?php if ( $is_active ) {
310 echo ' style="background: #E6FFE6; font-weight: bold"';
311 } ?>>
312 <td><?php echo $data->version ?></td>
313 <td><?php echo $sdk_path ?></td>
314 <td><?php echo $data->plugin_path ?></td>
315 <td><?php echo ( $is_active ) ? 'Active' : 'Inactive' ?></td>
316 </tr>
317 <?php endforeach ?>
318 </tbody>
319 </table>
320
321 <?php
322 $module_types = array(
323 WP_FS__MODULE_TYPE_PLUGIN,
324 WP_FS__MODULE_TYPE_THEME
325 );
326 ?>
327 <?php $active_modules_by_id = array() ?>
328 <?php foreach ( $module_types as $module_type ) : ?>
329 <?php $modules = fs_get_entities( $fs_options->get_option( $module_type . 's' ), FS_Plugin::get_class_name() ) ?>
330 <?php if ( is_array( $modules ) && count( $modules ) > 0 ) : ?>
331 <h2>
332 <button class="fs-debug-table-toggle-button" aria-expanded="true">
333 <span class="fs-debug-table-toggle-icon"></span>
334 </button>
335 <?php echo esc_html( ( WP_FS__MODULE_TYPE_PLUGIN == $module_type ) ? fs_text_inline( 'Plugins', 'plugins' ) : fs_text_inline( 'Themes', 'themes' ) ) ?>
336 </h2>
337 <table id="fs_<?php echo $module_type ?>" class="widefat fs-debug-table">
338 <thead>
339 <tr>
340 <th><?php fs_esc_html_echo_inline( 'ID', 'id' ) ?></th>
341 <th><?php fs_esc_html_echo_inline( 'Slug' ) ?></th>
342 <th><?php fs_esc_html_echo_x_inline( 'Version', 'product version' ) ?></th>
343 <th><?php fs_esc_html_echo_inline( 'Title' ) ?></th>
344 <th><?php fs_esc_html_echo_x_inline( 'API', 'as application program interface' ) ?></th>
345 <th><?php fs_esc_html_echo_inline( 'Freemius State' ) ?></th>
346 <th><?php fs_esc_html_echo_inline( 'Module Path' ) ?></th>
347 <th><?php fs_esc_html_echo_inline( 'Public Key' ) ?></th>
348 <?php if ( $is_multisite ) : ?>
349 <th><?php fs_esc_html_echo_inline( 'Network Blog' ) ?></th>
350 <th><?php fs_esc_html_echo_inline( 'Network User' ) ?></th>
351 <?php endif ?>
352 <th><?php fs_esc_html_echo_inline( 'Actions' ) ?></th>
353 </tr>
354 </thead>
355 <tbody>
356 <?php $alternate = false; ?>
357 <?php foreach ( $modules as $slug => $data ) : ?>
358 <?php
359 if ( WP_FS__MODULE_TYPE_THEME !== $module_type ) {
360 $is_active = is_plugin_active( $data->file );
361 } else {
362 $current_theme = wp_get_theme();
363 $is_active = ( $current_theme->stylesheet === $data->file );
364
365 if ( ! $is_active && is_child_theme() ) {
366 $parent_theme = $current_theme->parent();
367
368 $is_active = ( ( $parent_theme instanceof WP_Theme ) && $parent_theme->stylesheet === $data->file );
369 }
370 }
371 ?>
372 <?php
373 $fs = null;
374 if ( $is_active ) {
375 $fs = freemius( $data->id );
376
377 $active_modules_by_id[ $data->id ] = true;
378 }
379 ?>
380 <tr<?php if ( $alternate ) { echo ' class="alternate" '; } ?><?php if ( $is_active ) {
381 $has_api_connectivity = $fs->has_api_connectivity();
382
383 if ( true === $has_api_connectivity && $fs->is_on() ) {
384 echo ' style="background: #E6FFE6; font-weight: bold"';
385 } else if ( false === $has_api_connectivity || ! $fs->is_on() ) {
386 echo ' style="background: #ffd0d0; font-weight: bold"';
387 }
388 } ?>>
389 <td><?php echo $data->id ?></td>
390 <td><?php echo $slug ?></td>
391 <td><?php echo $data->version ?></td>
392 <td><?php echo $data->title ?></td>
393 <td<?php if ( $is_active && false === $has_api_connectivity ) {
394 echo ' style="color: red; text-transform: uppercase;"';
395 } ?>><?php if ( $is_active ) {
396 echo esc_html( true === $has_api_connectivity ?
397 fs_text_x_inline( 'Connected', 'as connection was successful' ) :
398 ( false === $has_api_connectivity ?
399 fs_text_x_inline( 'Blocked', 'as connection blocked' ) :
400 fs_text_x_inline( 'No requests yet', 'API connectivity state is unknown' ) )
401 );
402 } ?></td>
403 <td<?php if ( $is_active && ! $fs->is_on() ) {
404 echo ' style="color: red; text-transform: uppercase;"';
405 } ?>><?php if ( $is_active ) {
406 echo esc_html( $fs->is_on() ?
407 $on_text :
408 $off_text
409 );
410 } ?></td>
411 <td><?php echo $data->file ?></td>
412 <td><?php echo $data->public_key ?></td>
413 <?php if ( $is_multisite ) : ?>
414 <?php
415 $network_blog_id = null;
416 $network_user = null;
417
418 if ( is_object( $fs ) ) {
419 $network_blog_id = $fs->get_network_install_blog_id();
420 $network_user = $fs->get_network_user();
421 }
422 ?>
423 <td><?php echo is_numeric( $network_blog_id ) ? $network_blog_id : '' ?></td>
424 <td><?php if ( is_object( $network_user ) ) {
425 echo $network_user->email;
426 } ?></td>
427 <?php endif ?>
428 <td>
429 <?php if ( $is_active ) : ?>
430 <?php if ( $fs->has_trial_plan() ) : ?>
431 <form action="" method="POST">
432 <input type="hidden" name="fs_action" value="simulate_trial">
433 <input type="hidden" name="module_id" value="<?php echo $fs->get_id() ?>">
434 <?php wp_nonce_field( 'simulate_trial' ) ?>
435
436 <button type="submit" class="button button-primary simulate-trial"><?php fs_esc_html_echo_inline( 'Simulate Trial Promotion' ) ?></button>
437 </form>
438 <?php endif ?>
439 <?php if ( $fs->is_registered() ) : ?>
440 <a class="button" href="<?php echo $fs->get_account_url() ?>"><?php fs_esc_html_echo_inline( 'Account', 'account' ) ?></a>
441 <?php endif ?>
442 <?php if ( fs_is_network_admin() && ! $fs->is_network_upgrade_mode() ) : ?>
443 <form action="" method="POST">
444 <input type="hidden" name="fs_action" value="simulate_network_upgrade">
445 <input type="hidden" name="module_id" value="<?php echo $fs->get_id() ?>">
446 <?php wp_nonce_field( 'simulate_network_upgrade' ) ?>
447
448 <button type="submit" class="button button-small"><?php fs_esc_html_echo_inline( 'Simulate Network Upgrade' ) ?></button>
449 </form>
450 <?php endif ?>
451 <?php endif ?>
452 </td>
453 </tr>
454 <?php $alternate = ! $alternate ?>
455 <?php endforeach ?>
456 </tbody>
457 </table>
458 <?php endif ?>
459 <?php endforeach ?>
460 <?php foreach ( $module_types as $module_type ) : ?>
461 <?php
462 /**
463 * @var array $VARS
464 * @var array[string]FS_Site|array[string]FS_Site[] $sites_map
465 */
466 $sites_map = $VARS[ $module_type . '_sites' ];
467
468 $all_plans = false;
469 ?>
470 <?php if ( is_array( $sites_map ) && count( $sites_map ) > 0 ) : ?>
471 <h2>
472 <button class="fs-debug-table-toggle-button" aria-expanded="true">
473 <span class="fs-debug-table-toggle-icon"></span>
474 </button>
475 <?php echo esc_html( sprintf(
476 /* translators: %s: 'plugin' or 'theme' */
477 fs_text_inline( '%s Installs', 'module-installs' ),
478 ( WP_FS__MODULE_TYPE_PLUGIN === $module_type ? fs_text_inline( 'Plugin', 'plugin' ) : fs_text_inline( 'Theme', 'theme' ) )
479 ) ) ?> / <?php fs_esc_html_echo_x_inline( 'Sites', 'like websites', 'sites' ) ?>
480 </h2>
481 <table id="fs_<?php echo $module_type ?>_installs" class="widefat fs-debug-table">
482 <thead>
483 <tr>
484 <th><?php fs_esc_html_echo_inline( 'ID', 'id' ) ?></th>
485 <?php if ( $is_multisite ) : ?>
486 <th><?php fs_esc_html_echo_inline( 'Blog ID' ) ?></th>
487 <th><?php fs_esc_html_echo_inline( 'Address' ) ?></th>
488 <?php endif ?>
489 <th><?php fs_esc_html_echo_inline( 'Slug' ) ?></th>
490 <th><?php fs_esc_html_echo_inline( 'User ID' ) ?></th>
491 <th><?php fs_esc_html_echo_inline( 'License ID' ) ?></th>
492 <th><?php fs_esc_html_echo_x_inline( 'Plan', 'as product pricing plan', 'plan' ) ?></th>
493 <th><?php fs_esc_html_echo_inline( 'Public Key' ) ?></th>
494 <th><?php fs_esc_html_echo_inline( 'Secret Key' ) ?></th>
495 <th><?php fs_esc_html_echo_inline( 'Actions' ) ?></th>
496 </tr>
497 </thead>
498 <tbody>
499 <?php $site_url = null ?>
500 <?php foreach ( $sites_map as $slug => $sites ) : ?>
501 <?php foreach ( $sites as $site ) : ?>
502 <?php
503 $blog_id = $is_multisite ?
504 $site->blog_id :
505 null;
506
507 if ( is_null( $site_url ) || $is_multisite ) {
508 $site_url = Freemius::get_unfiltered_site_url(
509 $blog_id,
510 true,
511 true
512 );
513 }
514
515 $is_active_clone = ( $site->is_clone( $site_url ) && isset( $active_modules_by_id[ $site->plugin_id ] ) );
516
517 if ( $is_active_clone ) {
518 $has_any_active_clone = true;
519 }
520 ?>
521 <tr>
522 <td>
523 <?php echo $site->id ?>
524 <?php if ( $is_active_clone ) : ?>
525 <label class="fs-tag fs-warn">Clone</label>
526 <?php endif ?>
527 </td>
528 <?php if ( $is_multisite ) : ?>
529 <td><?php echo $blog_id ?></td>
530 <td><?php echo fs_strip_url_protocol( $site->url ) ?></td>
531 <?php endif ?>
532 <td><?php echo $slug ?></td>
533 <td><?php echo $site->user_id ?></td>
534 <td><?php echo !empty($site->license_id) ? $site->license_id : '' ?></td>
535 <td><?php
536 $plan_name = '';
537 if ( FS_Plugin_Plan::is_valid_id( $site->plan_id ) ) {
538 if ( false === $all_plans ) {
539 $option_name = 'plans';
540 if ( WP_FS__MODULE_TYPE_PLUGIN !== $module_type ) {
541 $option_name = $module_type . '_' . $option_name;
542 }
543
544 $all_plans = fs_get_entities( $fs_options->get_option( $option_name, array() ), FS_Plugin_Plan::get_class_name() );
545 }
546
547 foreach ( $all_plans[ $slug ] as $plan ) {
548 $plan_id = Freemius::_decrypt( $plan->id );
549
550 if ( $site->plan_id == $plan_id ) {
551 $plan_name = Freemius::_decrypt( $plan->name );
552 break;
553 }
554 }
555 }
556
557 echo $plan_name;
558 ?></td>
559 <td><?php echo $site->public_key ?></td>
560 <td><?php
561 $plugin_storage = FS_Storage::instance( $module_type, $slug );
562
563 echo $plugin_storage->is_whitelabeled ?
564 FS_Plugin_License::mask_secret_key_for_html( $site->secret_key ) :
565 esc_html( $site->secret_key );
566 ?></td>
567 <td>
568 <form action="" method="POST">
569 <input type="hidden" name="fs_action" value="delete_install">
570 <?php wp_nonce_field( 'delete_install' ) ?>
571 <input type="hidden" name="module_id" value="<?php echo $site->plugin_id ?>">
572 <?php if ( $is_multisite ) : ?>
573 <input type="hidden" name="blog_id" value="<?php echo $site->blog_id ?>">
574 <?php endif ?>
575 <input type="hidden" name="module_type" value="<?php echo $module_type ?>">
576 <input type="hidden" name="slug" value="<?php echo $slug ?>">
577 <button type="submit" class="button"><?php fs_esc_html_echo_x_inline( 'Delete', 'verb', 'delete' ) ?></button>
578 </form>
579 </td>
580 </tr>
581 <?php endforeach ?>
582 <?php endforeach ?>
583 </tbody>
584 </table>
585 <?php endif ?>
586 <?php endforeach ?>
587 <?php
588 $addons = $VARS['addons'];
589 ?>
590 <?php foreach ( $addons as $plugin_id => $plugin_addons ) : ?>
591 <h2>
592 <button class="fs-debug-table-toggle-button" aria-expanded="true">
593 <span class="fs-debug-table-toggle-icon"></span>
594 </button>
595 <?php echo esc_html( sprintf( fs_text_inline( 'Add Ons of module %s', 'addons-of-x' ), $plugin_id ) ) ?>
596 </h2>
597 <table id="fs_addons" class="widefat fs-debug-table">
598 <thead>
599 <tr>
600 <th><?php fs_esc_html_echo_inline( 'ID', 'id' ) ?></th>
601 <th><?php fs_esc_html_echo_inline( 'Title' ) ?></th>
602 <th><?php fs_esc_html_echo_inline( 'Slug' ) ?></th>
603 <th><?php fs_esc_html_echo_x_inline( 'Version', 'product version' ) ?></th>
604 <th><?php fs_esc_html_echo_inline( 'Public Key' ) ?></th>
605 <th><?php fs_esc_html_echo_inline( 'Secret Key' ) ?></th>
606 </tr>
607 </thead>
608 <tbody>
609 <?php
610 /**
611 * @var FS_Plugin[] $plugin_addons
612 */
613 foreach ( $plugin_addons as $addon ) : ?>
614 <tr>
615 <td><?php echo $addon->id ?></td>
616 <td><?php echo $addon->title ?></td>
617 <td><?php echo $addon->slug ?></td>
618 <td><?php echo $addon->version ?></td>
619 <td><?php echo $addon->public_key ?></td>
620 <td><?php echo esc_html( $addon->secret_key ) ?></td>
621 </tr>
622 <?php endforeach ?>
623 </tbody>
624 </table>
625 <?php endforeach ?>
626 <?php
627 /**
628 * @var FS_User[] $users
629 */
630 $users = $VARS['users'];
631 $user_ids_map = array();
632 $users_with_developer_license_by_id = array();
633
634 if ( is_array( $users ) && ! empty( $users ) ) {
635 foreach ( $users as $user ) {
636 $user_ids_map[ $user->id ] = true;
637 }
638 }
639
640 foreach ( $module_types as $module_type ) {
641 /**
642 * @var FS_Plugin_License[] $licenses
643 */
644 $licenses = $VARS[ $module_type . '_licenses' ];
645
646 foreach ( $licenses as $license ) {
647 if ( $license->is_whitelabeled ) {
648 $users_with_developer_license_by_id[ $license->user_id ] = true;
649 }
650 }
651 }
652
653 ?>
654 <?php if ( is_array( $users ) && 0 < count( $users ) ) : ?>
655 <h2>
656 <button class="fs-debug-table-toggle-button" aria-expanded="true">
657 <span class="fs-debug-table-toggle-icon"></span>
658 </button>
659 <?php fs_esc_html_echo_inline( 'Users' ) ?>
660 </h2>
661 <table id="fs_users" class="widefat fs-debug-table">
662 <thead>
663 <tr>
664 <th><?php fs_esc_html_echo_inline( 'ID', 'id' ) ?></th>
665 <th><?php fs_esc_html_echo_inline( 'Name' ) ?></th>
666 <th><?php fs_esc_html_echo_inline( 'Email' ) ?></th>
667 <th><?php fs_esc_html_echo_inline( 'Verified' ) ?></th>
668 <th><?php fs_esc_html_echo_inline( 'Public Key' ) ?></th>
669 <th><?php fs_esc_html_echo_inline( 'Secret Key' ) ?></th>
670 <th><?php fs_esc_html_echo_inline( 'Actions' ) ?></th>
671 </tr>
672 </thead>
673 <tbody>
674 <?php foreach ( $users as $user_id => $user ) : ?>
675 <?php $has_developer_license = isset( $users_with_developer_license_by_id[ $user_id ] ) ?>
676 <tr>
677 <td><?php echo $user->id ?></td>
678 <td><?php echo $has_developer_license ? '' : $user->get_name() ?></td>
679 <td>
680 <?php if ( ! $has_developer_license ) : ?>
681 <a href="mailto:<?php echo esc_attr( $user->email ) ?>"><?php echo $user->email ?></a>
682 <?php endif ?>
683 </td>
684 <td><?php echo $has_developer_license ? '' : json_encode( $user->is_verified ) ?></td>
685 <td><?php echo $user->public_key ?></td>
686 <td><?php echo $has_developer_license ? FS_Plugin_License::mask_secret_key_for_html($user->secret_key) : esc_html( $user->secret_key ) ?></td>
687 <td>
688 <?php if ( ! $has_developer_license ) : ?>
689 <form action="" method="POST">
690 <input type="hidden" name="fs_action" value="delete_user">
691 <?php wp_nonce_field( 'delete_user' ) ?>
692 <input type="hidden" name="user_id" value="<?php echo $user->id ?>">
693 <button type="submit" class="button"><?php fs_esc_html_echo_x_inline( 'Delete', 'verb', 'delete' ) ?></button>
694 </form>
695 <?php endif ?>
696 </td>
697 </tr>
698 <?php endforeach ?>
699 </tbody>
700 </table>
701 <?php endif ?>
702 <?php foreach ( $module_types as $module_type ) : ?>
703 <?php
704 /**
705 * @var FS_Plugin_License[] $licenses
706 */
707 $licenses = $VARS[ $module_type . '_licenses' ] ?>
708 <?php if ( is_array( $licenses ) && count( $licenses ) > 0 ) : ?>
709 <h2>
710 <button class="fs-debug-table-toggle-button" aria-expanded="true">
711 <span class="fs-debug-table-toggle-icon"></span>
712 </button>
713 <?php echo esc_html( sprintf( fs_text_inline( '%s Licenses', 'module-licenses' ), ( WP_FS__MODULE_TYPE_PLUGIN === $module_type ? fs_text_inline( 'Plugin', 'plugin' ) : fs_text_inline( 'Theme', 'theme' ) ) ) ) ?>
714 </h2>
715 <table id="fs_<?php echo $module_type ?>_licenses" class="widefat fs-debug-table">
716 <thead>
717 <tr>
718 <th><?php fs_esc_html_echo_inline( 'ID', 'id' ) ?></th>
719 <th><?php fs_esc_html_echo_inline( 'Plugin ID' ) ?></th>
720 <th><?php fs_esc_html_echo_inline( 'User ID' ) ?></th>
721 <th><?php fs_esc_html_echo_inline( 'Plan ID' ) ?></th>
722 <th><?php fs_esc_html_echo_inline( 'Quota' ) ?></th>
723 <th><?php fs_esc_html_echo_inline( 'Activated' ) ?></th>
724 <th><?php fs_esc_html_echo_inline( 'Blocking' ) ?></th>
725 <th><?php fs_esc_html_echo_inline( 'Type' ) ?></th>
726 <th><?php fs_esc_html_echo_inline( 'License Key' ) ?></th>
727 <th><?php fs_esc_html_echo_x_inline( 'Expiration', 'as expiration date' ) ?></th>
728 </tr>
729 </thead>
730 <tbody>
731 <?php foreach ( $licenses as $license ) : ?>
732 <tr>
733 <td><?php echo $license->id ?></td>
734 <td><?php echo $license->plugin_id ?></td>
735 <td><?php echo $license->user_id ?></td>
736 <td><?php echo $license->plan_id ?></td>
737 <td><?php echo $license->is_unlimited() ? 'Unlimited' : ( $license->is_single_site() ? 'Single Site' : $license->quota ) ?></td>
738 <td><?php echo $license->activated ?></td>
739 <td><?php echo $license->is_block_features ? 'Blocking' : 'Flexible' ?></td>
740 <td><?php echo $license->is_whitelabeled ? 'Whitelabeled' : 'Normal' ?></td>
741 <td><?php
742 echo ( $license->is_whitelabeled || ! isset( $user_ids_map[ $license->user_id ] ) ) ?
743 $license->get_html_escaped_masked_secret_key() :
744 esc_html( $license->secret_key );
745 ?></td>
746 <td><?php echo $license->expiration ?></td>
747 </tr>
748 <?php endforeach ?>
749 </tbody>
750 </table>
751 <?php endif ?>
752 <?php endforeach ?>
753 <?php
754 $page_params = array( 'is_fs_debug_page' => true );
755 fs_require_template( 'debug/scheduled-crons.php', $page_params );
756 ?>
757 <?php if ( FS_Logger::is_storage_logging_on() ) : ?>
758
759 <h2><?php fs_esc_html_echo_inline( 'Debug Log', 'debug-log' ) ?></h2>
760
761 <div id="fs_debug_filters">
762 <select name="type">
763 <option value="" selected="selected"><?php fs_esc_html_echo_inline( 'All Types', 'all-types' ) ?></option>
764 <option value="warn_error">Warnings & Errors</option>
765 <option value="error">Errors</option>
766 <option value="warn">Warnings</option>
767 <option value="info">Info</option>
768 </select>
769 <select name="request_type">
770 <option value="" selected="selected"><?php fs_esc_html_echo_inline( 'All Requests', 'all-requests' ) ?></option>
771 <option value="call">Sync</option>
772 <option value="ajax">AJAX</option>
773 <option value="cron">WP Cron</option>
774 </select>
775 <input name="file" type="text" placeholder="<?php fs_esc_attr_echo_inline( 'File' ) ?>"/>
776 <input name="function" type="text" placeholder="<?php fs_esc_attr_echo_inline( 'Function' ) ?>"/>
777 <input name="process_id" type="text" placeholder="<?php fs_esc_attr_echo_inline( 'Process ID' ) ?>"/>
778 <input name="logger" type="text" placeholder="<?php fs_esc_attr_echo_inline( 'Logger' ) ?>"/>
779 <input name="message" type="text" placeholder="<?php fs_esc_attr_echo_inline( 'Message' ) ?>"/>
780 <div style="margin: 10px 0">
781 <button id="fs_filter" class="button" style="float: left"><i class="dashicons dashicons-filter"></i> <?php fs_esc_html_echo_inline( 'Filter', 'filter' ) ?>
782 </button>
783
784 <form action="" method="POST" style="float: left; margin-left: 10px;">
785 <input type="hidden" name="fs_action" value="download_logs">
786 <?php wp_nonce_field( 'download_logs' ) ?>
787 <div class="fs-filters"></div>
788 <button id="fs_download" class="button" type="submit"><i
789 class="dashicons dashicons-download"></i> <?php fs_esc_html_echo_inline( 'Download' ) ?></button>
790 </form>
791 <div style="clear: both"></div>
792 </div>
793 </div>
794
795 <div id="fs_log_book" style="height: 300px; overflow: auto;">
796 <table class="widefat">
797 <thead>
798 <tr>
799 <th>#</th>
800 <th><?php fs_esc_html_echo_inline( 'Type' ) ?></th>
801 <th><?php fs_esc_html_echo_inline( 'ID', 'id' ) ?></th>
802 <th><?php fs_esc_html_echo_inline( 'Function' ) ?></th>
803 <th><?php fs_esc_html_echo_inline( 'Message' ) ?></th>
804 <th><?php fs_esc_html_echo_inline( 'File' ) ?></th>
805 <th><?php fs_esc_html_echo_inline( 'Timestamp' ) ?></th>
806 </tr>
807 </thead>
808 <tbody>
809 <tr style="display: none">
810 <td>{$log.log_order}.</td>
811 <td class="fs-col--type">{$log.type}</td>
812 <td class="fs-col--logger">{$log.logger}</td>
813 <td class="fs-col--function">{$log.function}</td>
814 <td class="fs-col--message">
815 <a href="#" onclick="jQuery(this).parent().find('div').toggle(); return false;">
816 <nobr>{$log.message_short}</nobr>
817 </a>
818 <div style="display: none;">{$log.message}</div>
819 </td>
820 <td class="fs-col--file">{$log.file}:{$log.line}</td>
821 <td class="fs-col--timestamp">{$log.created}</td>
822 </tr>
823
824 </tbody>
825 </table>
826 </div>
827 <script type="text/javascript">
828 jQuery(document).ready(function ($) {
829 var filtersChanged = false,
830 offset = 0,
831 limit = 200,
832 prevFiltersSignature = null;
833
834 var getFilters = function () {
835 var filters = {},
836 signature = '';
837
838 $('#fs_debug_filters').find('select, input').each(function (i, e) {
839 var $element = $(e);
840
841 if ('hidden' === $element.attr('type'))
842 return;
843
844 var val = $element.val();
845 if ('' !== val.trim()) {
846 var name = $(e).attr('name');
847 filters[name] = val;
848 signature += name + '=' + val + '~';
849 }
850 });
851
852 if (signature != prevFiltersSignature) {
853 filtersChanged = true;
854 prevFiltersSignature = signature;
855 } else {
856 filtersChanged = false;
857 }
858
859 return filters;
860 };
861
862 $('#fs_download').parent().submit(function () {
863 var filters = getFilters(),
864 hiddenFields = '';
865
866 for (var f in filters) {
867 if (filters.hasOwnProperty(f)) {
868 hiddenFields += '<input type="hidden" name="filters[' + f + ']" value="' + filters[f] + '" />';
869 }
870 }
871
872 $(this).find('.fs-filters').html(hiddenFields);
873 });
874
875 var loadLogs = function () {
876 var $tbody = $('#fs_log_book tbody'),
877 template = $tbody.find('tr:first-child').html(),
878 filters = getFilters();
879
880 if (!filtersChanged) {
881 offset += limit;
882 } else {
883 // Cleanup table for new filter (only keep template row).
884 $tbody.find('tr').each(function (i, e) {
885 if (0 == i)
886 return;
887
888 $(e).remove();
889 });
890
891 offset = 0;
892 }
893
894 $.post(<?php echo Freemius::ajax_url() ?>, {
895 action : 'fs_get_debug_log',
896 // As such we don't need to use `wp_json_encode` method but using it to follow wp.org guideline.
897 _wpnonce : <?php echo wp_json_encode( wp_create_nonce( 'fs_get_debug_log' ) ); ?>,
898 filters: filters,
899 offset : offset,
900 limit : limit
901 }, function (response) {
902
903 for (var i = 0; i < response.data.length; i++) {
904 var templateCopy = template;
905
906 response.data[i].message_short = (response.data[i].message.length > 32) ?
907 response.data[i].message.substr(0, 32) + '...' :
908 response.data[i].message;
909
910 for (var p in response.data[i]) {
911 if (response.data[i].hasOwnProperty(p)) {
912 templateCopy = templateCopy.replace('{$log.' + p + '}', response.data[i][p]);
913 }
914 }
915
916 $tbody.append('<tr' + (i % 2 ? ' class="alternate"' : '') + '>' + templateCopy + '</tr>');
917 }
918 });
919 };
920
921 $('#fs_filter').click(function () {
922 loadLogs();
923
924 return false;
925 });
926
927 loadLogs();
928 });
929 </script>
930 <?php endif ?>
931 <script type="text/javascript">
932 // JavaScript to toggle the visibility of the table body and change the caret icon
933 jQuery( document ).ready( function ( $ ) {
934 $( '.fs-debug-table-toggle-button' ).on( 'click', function () {
935 const button = $( this );
936 const table = button.closest( 'h2' ).next( 'table' );
937 const isExpanded = ( 'false' === button.attr( 'aria-expanded' ) );
938
939 button.attr( 'aria-expanded', isExpanded );
940 button.find( '.fs-debug-table-toggle-icon' ).text( isExpanded ? '' : '' );
941
942 table.css( {
943 display : isExpanded ? 'table' : 'block',
944 borderBottomWidth: isExpanded ? '1px' : '0',
945 maxHeight : isExpanded ? 'auto' : '0',
946 } );
947 } );
948
949 $( '.fs-debug-table-toggle-button:last' ).click();
950 } );
951 </script>