PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | modules/api-backups/classes/class-api-backups-3rd-party.php +313 -185 5.2.1 → 6.2.2 View file →
@@ -10,9 +10,15 @@
10 10
11 11 use WP_Error;
12 12 use MainWP\Dashboard\MainWP_DB;
13 13 use MainWP\Dashboard\MainWP_Extensions_Handler;
14 +use MainWP\Dashboard\MainWP_Site_Open;
14 15
16 +// Exit if accessed directly.
17 +if ( ! defined( 'ABSPATH' ) ) {
18 + exit;
19 +}
20 +
15 21 /**
16 22 * Class Api_Backups_3rd_Party
17 23 *
18 24 * This class is responsible for handling the 3rd party API requests for each available backup provider.
@@ -24,8 +30,10 @@
24 30 class Api_Backups_3rd_Party { //phpcs:ignore -- NOSONAR - multi methods.
25 31
26 32 // phpcs:disable WordPress.DB.RestrictedFunctions, Generic.Metrics.CyclomaticComplexity, WordPress.WP.AlternativeFunctions, WordPress.PHP.NoSilencedErrors -- Using cURL functions.
27 33
34 + const CLOUDWAYS_API_URL = 'https://api.cloudways.com/api/v2';
35 +
28 36 /**
29 37 * Public static variable to hold the single instance of the class.
30 38 *
31 39 * @var mixed Default null
@@ -33,8 +41,15 @@
33 41 protected static $instance = null;
34 42
35 43
36 44 /**
45 + * Public static variable to hold the saved access token value.
46 + *
47 + * @var mixed Default null
48 + */
49 + protected static $access_token = null;
50 +
51 + /**
37 52 * Public static variable.
38 53 */
39 54 const OPERATION = '/operation/'; // to clean code.
40 55
@@ -302,9 +317,9 @@
302 317 <div class="mainwp-sub-header">
303 318 <div class="ui grid">
304 319 <div class="ui two column row">
305 320 <div class="middle aligned column ui">
306 - <button id="action_backup_selected_sites" class="ui green mini button"><?php esc_html_e( 'Backup Selected Sites', 'mainwp' ); ?></button>
321 + <button id="action_backup_selected_sites" class="ui green mini button disabled"><?php esc_html_e( 'Backup Selected Sites', 'mainwp' ); ?></button>
307 322 </div>
308 323 <div class="right aligned middle aligned column">
309 324 <a href="admin.php?page=SettingsApiBackups" class="ui mini green basic button"><?php esc_html_e( 'Manage API Backups Settings', 'mainwp' ); ?></a>
310 325 </div>
@@ -310,18 +325,11 @@
310 325 </div>
311 326 </div>
312 327 </div>
313 328 </div>
314 - <div class="ui segment" id="mainwp-3rd-party-api-backups">
315 - <?php if ( Api_Backups_Utility::show_mainwp_message( 'mainwp-module-api-backups-info-message' ) ) : ?>
316 - <div class="ui info message">
317 - <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-module-api-backups-info-message"></i>
318 - <div><?php esc_html_e( 'This page will list the last backups created by the API Backups Extension for each Child Site that is setup with an API provider.', 'mainwp' ); ?></div>
319 - </div>
320 - <?php endif; ?>
329 + <div class="ui padded segment" id="mainwp-3rd-party-api-backups">
321 330 <?php static::action_notifications(); ?>
322 331 <?php static::render_api_backups_table( '3rd-party-api-backups' ); ?>
323 -
324 332 </div>
325 333 <?php
326 334 }
327 335
@@ -353,11 +361,9 @@
353 361 <input id="cb-select-all-top" type="checkbox"/>
354 362 </span>
355 363 </th>
356 364 <th scope="col"><?php esc_html_e( 'Site', 'mainwp' ); ?></th>
357 - <th scope="col" class="no-sort collapsing"><i class="sign in alternate icon"></i></th>
358 - <th scope="col"><?php esc_html_e( 'URL', 'mainwp' ); ?></th>
359 - <th scope="col"><?php esc_html_e( 'Provider', 'mainwp' ); ?></th>
365 + <th scope="col"><?php esc_html_e( 'API Provider', 'mainwp' ); ?></th>
360 366 <th scope="col"><?php esc_html_e( 'Last Manual Backup Date', 'mainwp' ); ?></th>
361 367 <th scope="col" class="no-sort collapsing"></th>
362 368 </tr>
363 369 </thead>
@@ -402,29 +408,33 @@
402 408 <label for="table-checkbox"></label>
403 409 </span>
404 410 <?php endif; ?>
405 411 </td>
406 - <td><a href="admin.php?page=ManageSitesApiBackups&id=<?php echo intval( $website->id ); ?>"><?php esc_html_e( $website->name, 'mainwp' ); ?></a> <span class="running"></span></td>
407 412 <td>
408 - <a href="<?php echo 'admin.php?page=SiteOpen&newWindow=yes&websiteid=' . intval( $website->id ); ?>&_opennonce=<?php echo esc_attr( wp_create_nonce( 'mainwp-admin-nonce' ) ); ?>" target="_blank">
409 - <i class="sign in alternate icon"></i>
410 - </a>
413 + <div>
414 + <a href="<?php MainWP_Site_Open::get_open_site_admin_link( $website->id, true ); //phpcs:ignore -- ok. ?>" target="_blank">
415 + <i class="sign in alternate icon"></i>
416 + </a>
417 + <a href="admin.php?page=ManageSitesApiBackups&id=<?php echo intval( $website->id ); ?>"><?php echo esc_html( $website->name ); ?></a> <span class="running"></span>
418 + </div>
419 + <span class="ui small text">
420 + <a href="<?php echo esc_url( $website->url ); ?>" target="_blank" class="ui grey text"><?php echo esc_url( $website->url ); ?></a>
421 + </span>
411 422 </td>
412 - <td><a href="<?php echo esc_url( $website->url ); ?>" target="_blank"><?php echo esc_url( $website->url ); ?></a></td>
413 - <td><?php esc_html_e( $api_provider, 'mainwp' ); ?></td>
423 + <td><?php echo esc_html( $api_provider ); ?></td>
414 424 <td class="last-backup-date" ><?php echo ( $last_backup ) ? esc_html( $last_backup ) : esc_html__( 'Awaiting first backup', 'mainwp' ); ?></td>
415 425 <td class="collapsing not-selectable">
416 426 <i class="ui notched circle loading icon" style="display:none;"></i>
417 - <div class="ui left pointing dropdown icon mini basic green button" style="z-index: 999">
418 - <a href="javascript:void(0)"><i class="ellipsis horizontal icon"></i></a>
427 + <div class="ui right pointing dropdown" style="z-index: 999">
428 + <a href="javascript:void(0)"><i class="ellipsis vertical icon"></i></a>
419 429 <div class="menu">
420 430 <?php if ( 'cPanel' === $api_provider ) : ?>
421 - <a class="mainwp_3rd_party_api_<?php esc_attr_e( $api_provider_options ); ?>_action_full_backup item"
431 + <a class="mainwp_3rd_party_api_<?php echo esc_attr( $api_provider_options ); ?>_action_full_backup item"
422 432 website_id="<?php echo intval( $website->id ); ?>" href="javascript:void(0)">
423 433 <?php esc_html_e( 'Backup', 'mainwp' ); ?>
424 434 </a>
425 435 <?php elseif ( 'None' !== $api_provider && 'cPanel' !== $api_provider ) : ?>
426 - <a class="mainwp_3rd_party_api_<?php esc_attr_e( $api_provider_options, 'mainwp' ); ?>_action_backup item"
436 + <a class="mainwp_3rd_party_api_<?php echo esc_attr( $api_provider_options ); ?>_action_backup item"
427 437 website_id="<?php echo intval( $website->id ); ?>" href="javascript:void(0)">
428 438 <?php esc_html_e( 'Backup', 'mainwp' ); ?>
429 439 </a>
430 440 <?php endif; ?>
@@ -458,9 +468,9 @@
458 468 "drawCallback": function( settings ) {
459 469 setTimeout(() => {
460 470 jQuery('#mainwp-3rd-party-backups-table .ui.checkbox').checkbox();
461 471 jQuery('.mainwp-api-backup-table .ui.dropdown').dropdown();
462 - mainwp_datatable_fix_menu_overflow();
472 + mainwp_datatable_fix_menu_overflow('#mainwp-3rd-party-backups-table');
463 473 }, 1000);
464 474 },
465 475 select: {
466 476 items: 'row',
@@ -479,13 +489,12 @@
479 489 .nodes()
480 490 .to$().find('td.check-column .ui.checkbox' ).checkbox('set unchecked');
481 491 }
482 492 }).on( 'columns-reordered', function () {
483 - console.log('columns-reordered');
484 493 setTimeout(() => {
485 494 jQuery( '#mainwp-3rd-party-backups-table .ui.dropdown' ).dropdown();
486 495 jQuery( '#mainwp-3rd-party-backups-table .ui.checkbox' ).checkbox();
487 - mainwp_datatable_fix_menu_overflow();
496 + mainwp_datatable_fix_menu_overflow('#mainwp-3rd-party-backups-table');
488 497 mainwp_table_check_columns_init(); // ajax: to fix checkbox all.
489 498 }, 1000);
490 499 });
491 500 } );
@@ -533,47 +542,29 @@
533 542 $available_backups = array();
534 543 }
535 544
536 545 if ( empty( $backup_api ) ) {
546 + $title = esc_html__( 'No API Backup Solution has been chosen.', 'mainwp' );
547 + /* translators: %1$s: Link to API Backups Settings page, %2$s: Link to Child Site Settings page */
548 + $msg_format = __( 'Please double check that you have set the API Key on the %1$s page and have set the Instance ID on the %2$s page.', 'mainwp' );
549 + $message = sprintf(
550 + $msg_format,
551 + '<a href="' . esc_url( admin_url( 'admin.php?page=SettingsApiBackups' ) ) . '">' . esc_html__( 'API Backups Settings', 'mainwp' ) . '</a>',
552 + '<a href="' . esc_url( admin_url( 'admin.php?page=managesites&id=' . intval( $website_id ) ) ) . '">' . esc_html__( 'Child Site &rarr; Settings page', 'mainwp' ) . '</a>'
553 + );
554 + $icon = '<em data-emoji=":closed_lock_with_key:" class="big"></em>';
555 + \MainWP\Dashboard\MainWP_UI::render_empty_page_placeholder( $title, $message, $icon );
556 + } else {
557 + $columns = 'one';
558 + if ( 'cpanel' === $backup_api || 'plesk' === $backup_api ) {
559 + $columns = 'two';
560 + }
537 561 ?>
538 - <div class="ui placeholder segment">
539 - <div class="ui icon header">
540 - <i class="key icon"></i>
541 - <?php
542 - printf(
543 - esc_html__(
544 - '%1$sNo API Backup Solution has been chosen.%2$s
545 - Please double check that you have set the %3$sAPI Key%4$s
546 - on the %5$s page%6$s
547 - and have set the %7$sInstance ID%8$s on the %9$s page.',
548 - 'mainwp'
549 - ),
550 - '<em>',
551 - '</em> <br/><br>',
552 - '<em>',
553 - '</em>',
554 - '<a href="admin.php?page=SettingsApiBackups">API Backups Settings</a>',
555 - '</br>',
556 - '<em>',
557 - '</em>',
558 - '<a href="admin.php?page=managesites&id=' . intval( $website_id ) . '">Child Site -> Edit</a>'
559 - );
560 - ?>
561 - </div>
562 - </div>
563 - <?php } else { ?>
564 -
565 - <?php
566 - $columns = 'one';
567 - if ( 'cpanel' === $backup_api || 'plesk' === $backup_api ) {
568 - $columns = 'two';
569 - }
570 - ?>
571 - <div class="mainwp-sub-header">
562 + <div class="mainwp-actions-bar">
572 563 <div class="ui grid">
573 564 <div class="ui <?php echo esc_html( $columns ); ?> column row">
574 565 <div class="middle aligned column ui">
575 - <?php if ( 'cpanel' === $backup_api ) : ?>
566 + <?php if ( 'cpanel' === $backup_api ) : ?>
576 567 <div id="mainwp_api_cpanel_backup_tabs" class="ui top attached tabular menu">
577 568 <div class="active item" data-tab="cpanel-native"><i class="fitted cpanel big icon"></i></div>
578 569 <div class="item" data-tab="cpanel-wp-toolkit"><i class="fitted wordpress big icon"></i></div><?php //phpcs:ignore -- skip wordpress.?>
579 570 </div>
@@ -579,31 +570,31 @@
579 570 </div>
580 571 <?php endif; ?>
581 572 </div>
582 573 <div class="right aligned middle aligned column">
583 - <?php if ( 'cpanel' === $backup_api ) : ?>
584 - <button id="mainwp_3rd_party_api_<?php esc_attr_e( $backup_api ); ?>_action_create_full_backup" website_id="<?php echo intval( $website['id'] ); ?>" class="ui mini green button"><?php esc_html_e( 'Backup Files &amp; Database', 'mainwp' ); ?></button>
585 - <button id="mainwp_3rd_party_api_<?php esc_attr_e( $backup_api ); ?>_action_create_wptk_backup" website_id="<?php echo intval( $website['id'] ); ?>" class="ui mini green button hidden"><?php esc_html_e( 'Backup Now', 'mainwp' ); ?></button>
574 + <?php if ( 'cpanel' === $backup_api ) : ?>
575 + <button id="mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_create_full_backup" website_id="<?php echo intval( $website['id'] ); ?>" class="ui mini green button"><?php esc_html_e( 'Backup Files &amp; Database', 'mainwp' ); ?></button>
576 + <button id="mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_create_wptk_backup" website_id="<?php echo intval( $website['id'] ); ?>" class="ui mini green button hidden"><?php esc_html_e( 'Backup Now', 'mainwp' ); ?></button>
586 577 <?php else : ?>
587 - <button id="mainwp_3rd_party_api_<?php esc_attr_e( $backup_api ); ?>_action_individual_create_backup" website_id="<?php echo intval( $website['id'] ); ?>" class="ui mini green button"><?php esc_html_e( 'Backup Now', 'mainwp' ); ?></button>
578 + <button id="mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_individual_create_backup" website_id="<?php echo intval( $website['id'] ); ?>" class="ui mini green button"><?php esc_html_e( 'Backup Now', 'mainwp' ); ?></button>
588 579 <?php endif; ?>
589 - <button id="mainwp_3rd_party_api_<?php esc_attr_e( $backup_api ); ?>_action_refresh_available_backups" website_id="<?php echo intval( $website['id'] ); ?>" class="ui mini green button"><?php esc_html_e( 'Refresh Available Backups', 'mainwp' ); ?></button>
580 + <button id="mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_refresh_available_backups" website_id="<?php echo intval( $website['id'] ); ?>" class="ui mini green button"><?php esc_html_e( 'Refresh Available Backups', 'mainwp' ); ?></button>
590 581
591 - <?php // Render DigitalOcean specific action buttons. ?>
592 - <?php
593 - if ( 'digitalocean' === $backup_api ) {
594 - // Grab Linode instance id.
595 - $digitalocean_droplet_id = Api_Backups_Helper::get_website_options(
596 - $website,
597 - array(
598 - 'mainwp_3rd_party_instance_id',
599 - )
600 - );
601 - $droplet_id = isset( $digitalocean_droplet_id['mainwp_3rd_party_instance_id'] ) ? $digitalocean_droplet_id['mainwp_3rd_party_instance_id'] : null;
602 - ?>
582 + <?php // Render DigitalOcean specific action buttons. ?>
583 + <?php
584 + if ( 'digitalocean' === $backup_api ) {
585 + // Grab Linode instance id.
586 + $digitalocean_droplet_id = Api_Backups_Helper::get_website_options(
587 + $website,
588 + array(
589 + 'mainwp_3rd_party_instance_id',
590 + )
591 + );
592 + $droplet_id = isset( $digitalocean_droplet_id['mainwp_3rd_party_instance_id'] ) ? $digitalocean_droplet_id['mainwp_3rd_party_instance_id'] : null;
593 + ?>
603 594 <a href="https://cloud.digitalocean.com/droplets/<?php echo esc_attr( $droplet_id ); ?>/snapshots" target="_blank" class="ui mini button">
604 595 <i class="external icon"></i>
605 - <?php esc_html_e( 'View on DigitalOcean', 'mainwp' ); ?>
596 + <?php esc_html_e( 'View on DigitalOcean', 'mainwp' ); ?>
606 597 </a>
607 598 <?php } ?>
608 599 <?php // Render Linode specific action buttons. ?>
609 600 <?php
@@ -616,9 +607,9 @@
616 607 )
617 608 );
618 609 $instance_id = isset( $linode_instance_id['mainwp_3rd_party_instance_id'] ) ? $linode_instance_id['mainwp_3rd_party_instance_id'] : null;
619 610 ?>
620 - <button id="mainwp_3rd_party_api_<?php esc_attr_e( $backup_api ); ?>_action_cancel_backups" website_id="<?php echo intval( $website['id'] ); ?>" class="ui mini button"><?php esc_html_e( 'Disable & Remove Backups on This Linode', 'mainwp' ); ?></button>
611 + <button id="mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_cancel_backups" website_id="<?php echo intval( $website['id'] ); ?>" class="ui mini button"><?php esc_html_e( 'Disable & Remove Backups on This Linode', 'mainwp' ); ?></button>
621 612 <a href="https://cloud.linode.com/linodes/<?php echo esc_attr( $instance_id ); ?>/backup" target="_blank" class="ui mini button">
622 613 <i class="external icon"></i>
623 614 <?php esc_html_e( 'View on Akamai (Linode)', 'mainwp' ); ?>
624 615 </a>
@@ -629,9 +620,9 @@
629 620 // Grab Cloudways app id.
630 621 $site_options = Api_Backups_Helper::get_website_options( $website, array( 'mainwp_3rd_party_app_id' ) );
631 622 $app_id = isset( $site_options['mainwp_3rd_party_app_id'] ) ? $site_options['mainwp_3rd_party_app_id'] : null;
632 623 ?>
633 - <button id="mainwp_3rd_party_api_<?php esc_attr_e( $backup_api ); ?>_action_delete_backup" website_id="<?php echo intval( $website['id'] ); ?>" class="ui mini button"><?php esc_html_e( 'Delete 24hr Restore Point', 'mainwp' ); ?></button>
624 + <button id="mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_delete_backup" website_id="<?php echo intval( $website['id'] ); ?>" class="ui mini button"><?php esc_html_e( 'Delete 24hr Restore Point', 'mainwp' ); ?></button>
634 625 <a href="https://platform.cloudways.com/apps/<?php echo esc_attr( $app_id ); ?>/restore" target="_blank" class="ui mini button">
635 626 <i class="external icon"></i>
636 627 <?php esc_html_e( 'View on Cloudways', 'mainwp' ); ?>
637 628 </a>
@@ -658,9 +649,9 @@
658 649 </div>
659 650 </div>
660 651 </div>
661 652 </div>
662 - <div class="ui segment">
653 + <div class="ui padded segment">
663 654
664 655 <?php // Render action notifications. I get replaced by JS. ?>
665 656 <div id="mainwp-api-backups-message-zone" class="ui message" style="display: none;">
666 657 <i class="icon close"></i>
@@ -737,10 +728,13 @@
737 728 <div class="ui info message">
738 729 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-module-api-backups-info-message"></i>
739 730 <div><?php esc_html_e( 'You can create up to 5 manual backups. Each manual backup will be stored for 14 days.', 'mainwp' ); ?></div>
740 731 </div>
741 - <?php endif; ?>
742 - <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%">
732 + <?php
733 + endif;
734 + $el_id_wp_1 = $website['id'];
735 + ?>
736 + <table id="mainwp-siteid-<?php echo intval( $el_id_wp_1 ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%">
743 737 <thead>
744 738 <tr>
745 739 <th scope="col"><?php esc_html_e( 'Backup Name', 'mainwp' ); ?></th>
746 740 <th scope="col"><?php esc_html_e( 'Note', 'mainwp' ); ?></th>
@@ -756,9 +750,9 @@
756 750 // Convert Kinsta backup date to human readable format.
757 751 $backup_date = Api_Backups_Utility::format_timestamp( intval( $backup->created_at / 1000 ) );
758 752 ?>
759 753 <tr>
760 - <td class="collapsing"><?php esc_html_e( $backup->name ); ?></td>
754 + <td class="collapsing"><?php echo esc_html( $backup->name ); ?></td>
761 755 <td class="collapsing"><?php echo esc_html( $backup->note ); ?></td>
762 756 <td class="collapsing"><?php echo esc_html( $backup->type ); ?></td>
763 757 <td class="collapsing"><?php echo esc_html( $backup_date ); ?></td>
764 758 <td></td>
@@ -794,9 +788,9 @@
794 788 </tr>
795 789 </tfoot>
796 790 </table>
797 791 <div class="ui divider hidden"></div>
798 - <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%">
792 + <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%"> <?php // NOSONAR - id ok. ?>
799 793 <thead>
800 794 <tr>
801 795 <th scope="col" colspan="3">
802 796 <div class="ui equal width grid">
@@ -832,10 +826,10 @@
832 826
833 827 ?>
834 828
835 829 <tr>
836 - <td class="collapsing"><?php esc_html_e( $created_date ); ?></td>
837 - <td class="collapsing"><?php esc_html_e( $expiry_date ); ?></td>
830 + <td class="collapsing"><?php echo esc_html( $created_date ); ?></td>
831 + <td class="collapsing"><?php echo esc_html( $expiry_date ); ?></td>
838 832 <td>
839 833 <a class="kinsta_download" href="<?php echo esc_attr( $backup->download_link ); ?>" target="_blank">
840 834 <button class="ui right labeled icon button">
841 835 <i class="right download icon"></i>
@@ -845,10 +839,10 @@
845 839 </td>
846 840 </tr>
847 841 <?php } else { ?>
848 842 <tr class="disabled">
849 - <td class="collapsing"><?php esc_html_e( $created_date ); ?></td>
850 - <td class="collapsing"><?php esc_html_e( $expiry_date ); ?></td>
843 + <td class="collapsing"><?php echo esc_html( $created_date ); ?></td>
844 + <td class="collapsing"><?php echo esc_html( $expiry_date ); ?></td>
851 845 <td>
852 846 <a class="kinsta_download" href="<?php echo esc_attr( $backup->download_link ); ?>" target="_blank">
853 847 <button class="ui right labeled icon button disabled">
854 848 <i class="right download icon"></i>
@@ -879,9 +873,9 @@
879 873 } else {
880 874 $available_backups = array();
881 875 }
882 876 ?>
883 - <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%">
877 + <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%"> <?php // NOSONAR - id ok. ?>
884 878 <thead>
885 879 <tr>
886 880 <th scope="col"><?php esc_html_e( 'Backup Name', 'mainwp' ); ?></th>
887 881 <th scope="col"><?php esc_html_e( 'Date Created', 'mainwp' ); ?></th>
@@ -905,9 +899,9 @@
905 899 $installation_id = $opts['mainwp_plesk_installation_id'] ?? '';
906 900 }
907 901 ?>
908 902 <tr>
909 - <td class="collapsing"><?php esc_html_e( $backup->value->fileName->value ); ?></td>
903 + <td class="collapsing"><?php echo esc_html( $backup->value->fileName->value ); ?></td>
910 904 <td class="collapsing"><?php echo esc_html( $backup_date ); ?></td>
911 905 <td></td>
912 906 <td class="collapsing right aligned">
913 907 <button id="plesk_restore_button" class="ui circular mini icon button mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_restore_backup item"
@@ -931,9 +925,9 @@
931 925 <a id="plesk_download_button" class="ui circular mini icon button mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_downlaod_backup item"
932 926 installation_id="<?php echo intval( $installation_id ); ?>"
933 927 website_id="<?php echo intval( $website['id'] ); ?>"
934 928 backup_name="<?php echo esc_attr( $backup->value->fileName->value ); ?>"
935 - href="admin.php?page=SiteOpen&websiteid=<?php echo intval( $website['id'] ); ?>&dirdl=<?php echo esc_attr( rawurlencode( $dirdl ) ); ?>&filedl=<?php echo esc_attr( rawurlencode( $backup->value->fileName->value ) ); ?>&_opennonce=<?php echo esc_html( wp_create_nonce( 'mainwp-admin-nonce' ) ); ?>"
929 + href="<?php MainWP_Site_Open::get_open_site_admin_link( $website['id'], true ); //phpcs:ignore -- ok. ?>&dirdl=<?php echo esc_attr( rawurlencode( $dirdl ) ); ?>&filedl=<?php echo esc_attr( rawurlencode( $backup->value->fileName->value ) ); ?>"
936 930 data-tooltip="<?php esc_attr_e( 'Download Backup', 'mainwp' ); ?>"
937 931 data-inverted=""
938 932 data-position="top center"
939 933 target="_blank">
@@ -1007,9 +1001,9 @@
1007 1001 $available_manual_database_backups = array();
1008 1002 }
1009 1003 ?>
1010 1004 <div class="ui bottom attached active tab" data-tab="cpanel-native">
1011 - <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%">
1005 + <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%"> <?php // NOSONAR - id ok. ?>
1012 1006 <thead>
1013 1007 <tr>
1014 1008 <th scope="col" colspan="4">
1015 1009 <?php esc_html_e( 'Automatic Host Backups', 'mainwp' ); ?>
@@ -1024,11 +1018,11 @@
1024 1018 </thead>
1025 1019 <tbody>
1026 1020 <?php foreach ( $available_backups_automatic_list as $backup ) { ?>
1027 1021 <tr>
1028 - <td><?php esc_html_e( $backup->backupID ); ?></td>
1029 - <td><?php esc_html_e( ucfirst( $backup->backupType ), 'mainwp' ); ?></td>
1030 - <td><?php echo esc_html_e( $backup->path ); ?></td>
1022 + <td><?php echo esc_html( $backup->backupID ); ?></td>
1023 + <td><?php echo esc_html( ucfirst( $backup->backupType ) ); ?></td>
1024 + <td><?php echo esc_html( $backup->path ); ?></td>
1031 1025 <td>
1032 1026 <a id="cpanel_automatic_backup_button" class="mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_restore_backup item"
1033 1027 website_id="<?php echo intval( $website['id'] ); ?>"
1034 1028 backup_type="<?php echo esc_attr( 'automatic' ); ?>"
@@ -1053,9 +1047,9 @@
1053 1047 </tr>
1054 1048 </tfoot>
1055 1049 </table>
1056 1050 <div class="ui divider hidden"></div>
1057 - <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%">
1051 + <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%"> <?php // NOSONAR - id ok. ?>
1058 1052 <thead>
1059 1053 <tr>
1060 1054 <th scope="col" colspan="3">
1061 1055 <div class="ui equal width grid">
@@ -1062,9 +1056,12 @@
1062 1056 <div class="left aligned middle aligned column">
1063 1057 <?php esc_html_e( 'Manual Account Backups', 'mainwp' ); ?>
1064 1058 </div>
1065 1059 <div class="right aligned middle aligned column">
1066 - <button id="mainwp_3rd_party_api_<?php esc_attr_e( $backup_api ); ?>_action_individual_create_backup" website_id="<?php echo intval( $website['id'] ); ?>" class="ui primary elastic green button"><?php esc_html_e( 'Backup', 'mainwp' ); ?></button>
1060 + <?php
1061 + $el_id_cp_api = $backup_api;
1062 + ?>
1063 + <button id="mainwp_3rd_party_api_<?php echo esc_attr( $el_id_cp_api ); ?>_action_individual_create_backup" website_id="<?php echo intval( $website['id'] ); ?>" class="ui primary elastic green button"><?php esc_html_e( 'Backup', 'mainwp' ); ?></button>
1067 1064 </div>
1068 1065 </div>
1069 1066 </th>
1070 1067 </tr>
@@ -1070,9 +1067,9 @@
1070 1067 </tr>
1071 1068 <tr>
1072 1069 <th scope="col" ><?php esc_html_e( 'Backup Name', 'mainwp' ); ?></th>
1073 1070 <th scope="col" ><?php esc_html_e( 'Date Created', 'mainwp' ); ?></th>
1074 - <th scope="col" ="no-sort collapsing"></th>
1071 + <th scope="col" class="no-sort collapsing"></th>
1075 1072 </tr>
1076 1073 </thead>
1077 1074 <tbody>
1078 1075 <?php foreach ( $available_backups_manual_list as $backup ) { ?>
@@ -1080,15 +1077,15 @@
1080 1077 $my_unix_timestamp = $backup->timestamp;
1081 1078 $backup_date = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $my_unix_timestamp ), get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) );
1082 1079 ?>
1083 1080 <tr>
1084 - <td class="collapsing"><?php esc_html_e( $backup->file_name ); ?></td>
1085 - <td class="collapsing"><?php esc_html_e( $backup_date ); ?></td>
1081 + <td class="collapsing"><?php echo esc_html( $backup->file_name ); ?></td>
1082 + <td class="collapsing"><?php echo esc_html( $backup_date ); ?></td>
1086 1083 <td>
1087 1084 <?php
1088 1085 $file_path = $backup->absolute_dir . '/';
1089 1086 ?>
1090 - <a class="open_newwindow_wpadmin" href="admin.php?page=SiteOpen&websiteid=<?php echo intval( $website['id'] ); ?>&dirdl=<?php echo esc_attr( rawurlencode( $file_path ) ); ?>&filedl=<?php echo esc_attr( rawurlencode( $backup->file_name ) ); ?>&_opennonce=<?php echo esc_html( wp_create_nonce( 'mainwp-admin-nonce' ) ); ?>" target="_blank">
1087 + <a class="open_newwindow_wpadmin" href="<?php MainWP_Site_Open::get_open_site_admin_link( $website['id'], true ); //phpcs:ignore -- ok. ?>&dirdl=<?php echo esc_attr( rawurlencode( $file_path ) ); ?>&filedl=<?php echo esc_attr( rawurlencode( $backup->file_name ) ); ?>" target="_blank">
1091 1088 <button class="ui right labeled icon button">
1092 1089 <i class="right download icon"></i>
1093 1090 <?php echo esc_html__( 'Download', 'mainwp' ); ?>
1094 1091 </button>
@@ -1105,9 +1102,9 @@
1105 1102 </tr>
1106 1103 </tfoot>
1107 1104 </table>
1108 1105 <div class="ui divider hidden"></div>
1109 - <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%">
1106 + <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%"> <?php // NOSONAR - id ok. ?>
1110 1107 <thead>
1111 1108 <tr>
1112 1109 <th scope="col" colspan="3">
1113 1110 <div class="ui equal width grid">
@@ -1114,9 +1111,9 @@
1114 1111 <div class="left aligned middle aligned column">
1115 1112 <?php esc_html_e( 'Manual Database Backups', 'mainwp' ); ?>
1116 1113 </div>
1117 1114 <div class="right aligned middle aligned column">
1118 - <button id="mainwp_3rd_party_api_<?php esc_attr_e( $backup_api ); ?>_action_create_database_backup" website_id="<?php echo intval( $website['id'] ); ?>" class="ui primary elastic green button"><?php esc_html_e( 'Backup', 'mainwp' ); ?></button>
1115 + <button id="mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_create_database_backup" website_id="<?php echo intval( $website['id'] ); ?>" class="ui primary elastic green button"><?php esc_html_e( 'Backup', 'mainwp' ); ?></button>
1119 1116 </div>
1120 1117 </div>
1121 1118 </th>
1122 1119 </tr>
@@ -1132,10 +1129,10 @@
1132 1129 $my_unix_timestamp = $backup->timestamp;
1133 1130 $backup_date = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $my_unix_timestamp ), get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) );
1134 1131 ?>
1135 1132 <tr>
1136 - <td class="collapsing"><?php esc_html_e( $backup->file_name ); ?></td>
1137 - <td class="collapsing"><?php esc_html_e( $backup_date ); ?></td>
1133 + <td class="collapsing"><?php echo esc_html( $backup->file_name ); ?></td>
1134 + <td class="collapsing"><?php echo esc_html( $backup_date ); ?></td>
1138 1135 <td>
1139 1136 <a id="database_backup_button" class="mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_restore_database_backup item"
1140 1137 website_id="<?php echo intval( $website['id'] ); ?>"
1141 1138 backup_path="<?php echo esc_attr( $backup->absolute_dir ); ?>"
@@ -1213,9 +1210,9 @@
1213 1210 $my_unix_timestamp = strtotime( $backup->value->createdAt->value );
1214 1211 $backup_date = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $my_unix_timestamp ), get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) );
1215 1212 ?>
1216 1213 <tr>
1217 - <td class=""><?php esc_html_e( $backup->value->fileName->value ); ?></td>
1214 + <td class=""><?php echo esc_html( $backup->value->fileName->value ); ?></td>
1218 1215 <td class=""><?php echo esc_html( $backup_date ); ?></td>
1219 1216 <td></td>
1220 1217 <td class="right aligned">
1221 1218 <button class="ui mini icon button mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_restore_wptk_backup item"
@@ -1236,9 +1233,9 @@
1236 1233 ?>
1237 1234 <button class="ui mini icon button mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_download_wptk_backup item"
1238 1235 website_id="<?php echo intval( $website['id'] ); ?>"
1239 1236 backup_name="<?php echo esc_attr( $backup->value->fileName->value ); ?>"
1240 - href="admin.php?page=SiteOpen&websiteid=<?php echo intval( $website['id'] ); ?>&dirdl=<?php echo esc_attr( rawurlencode( $dirdl ) ); ?>&filedl=<?php echo esc_attr( rawurlencode( $backup->value->fileName->value ) ); ?>&_opennonce=<?php echo esc_html( wp_create_nonce( 'mainwp-admin-nonce' ) ); ?>"
1237 + href="<?php MainWP_Site_Open::get_open_site_admin_link( $website['id'], true ); //phpcs:ignore -- ok. ?>&dirdl=<?php echo esc_attr( rawurlencode( $dirdl ) ); ?>&filedl=<?php echo esc_attr( rawurlencode( $backup->value->fileName->value ) ); ?>"
1241 1238 data-tooltip="<?php esc_attr_e( 'Download Backup', 'mainwp' ); ?>"
1242 1239 data-inverted=""
1243 1240 data-position="top center">
1244 1241 <i class="download icon"></i>
@@ -1264,33 +1261,14 @@
1264 1261 </tr>
1265 1262 </tfoot>
1266 1263 </table>
1267 1264 <?php else : // Display message if WP-Toolkit is not enabled. ?>
1268 - <div class="ui placeholder segment">
1269 - <div class="ui icon header">
1270 - <i class="key icon"></i>
1271 - <?php
1272 - printf(
1273 - esc_html__(
1274 - '%1$sThe WP-Toolkit API has not been enabled.%2$s
1275 - Please double check that you have set the cPanel %3$sAPI Key%4$s
1276 - on the %5$s page%6$s
1277 - and have enabled the %7$sWP Toolkit API%8$s on the %9$s page.',
1278 - 'mainwp'
1279 - ),
1280 - '<em>',
1281 - '</em> <br/><br>',
1282 - '<em>',
1283 - '</em>',
1284 - '<a href="admin.php?page=SettingsApiBackups">API Backups Settings</a>',
1285 - '</br>',
1286 - '<em>',
1287 - '</em>',
1288 - '<a href="admin.php?page=managesites&id=' . intval( $website_id ) . '">Child Site -> Edit</a>'
1289 - );
1290 - ?>
1291 - </div>
1292 - </div>
1265 + <?php
1266 + $title = esc_html__( 'The WP-Toolkit API has not been enabled.', 'mainwp' );
1267 + $message = esc_html__( 'Please double check that you have set the cPanel API Key on the API Backups Settings page and have enabled the WP Toolkit API on the Child Site -> Edit page.', 'mainwp' );
1268 + $icon = '<em data-emoji=":closed_lock_with_key:" class="big"></em>';
1269 + \MainWP\Dashboard\MainWP_UI::render_empty_page_placeholder( $title, $message, $icon );
1270 + ?>
1293 1271 <?php endif; ?>
1294 1272 </div>
1295 1273 <?php } ?>
1296 1274 <?php // Display GridPane Table. ?>
@@ -1306,9 +1284,9 @@
1306 1284 } else {
1307 1285 $available_backups_manual_list = array();
1308 1286 }
1309 1287 ?>
1310 - <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%">
1288 + <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%"> <?php // NOSONAR - id ok. ?>
1311 1289 <thead>
1312 1290 <tr>
1313 1291 <th scope="col" ><?php esc_html_e( 'GridPane Backup Name', 'mainwp' ); ?></th>
1314 1292 <th scope="col" ><?php esc_html_e( 'Type', 'mainwp' ); ?></th>
@@ -1318,9 +1296,9 @@
1318 1296 </thead>
1319 1297 <tbody>
1320 1298 <?php foreach ( $available_backups_automatic_list as $backup ) { ?>
1321 1299 <tr>
1322 - <td><i class="ui notched circle loading icon" style="display:none;"></i> <?php esc_html_e( $backup ); ?></td>
1300 + <td><i class="ui notched circle loading icon" style="display:none;"></i> <?php echo esc_html( $backup ); ?></td>
1323 1301 <td><?php esc_html_e( 'Automatic', 'mainwp' ); ?></td>
1324 1302 <td></td>
1325 1303 <td class="collapsing right aligned">
1326 1304 <a class="mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_restore_backup ui mini icon button"
@@ -1341,9 +1319,9 @@
1341 1319 </tr>
1342 1320 <?php } ?>
1343 1321 <?php foreach ( $available_backups_manual_list as $backup ) { ?>
1344 1322 <tr>
1345 - <td><i class="ui notched circle loading icon" style="display:none;"></i> <?php esc_html_e( $backup ); ?></td>
1323 + <td><i class="ui notched circle loading icon" style="display:none;"></i> <?php echo esc_html( $backup ); ?></td>
1346 1324 <td><?php esc_html_e( 'Manual', 'mainwp' ); ?></td>
1347 1325 <td></td>
1348 1326 <td class="collapsing right aligned">
1349 1327 <a class="mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_restore_backup ui mini icon button"
@@ -1352,9 +1330,9 @@
1352 1330 backup_name="<?php echo esc_attr( $backup ); ?>"
1353 1331 href="javascript:void(0)">
1354 1332 <i class="undo icon"></i>
1355 1333 </a>
1356 - <a class="mainwp_3rd_party_api_<?php esc_attr_e( $backup_api ); ?>_action_delete_backup ui mini icon button"
1334 + <a class="mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_delete_backup ui mini icon button"
1357 1335 website_id="<?php echo intval( $website['id'] ); ?>"
1358 1336 backup_type="<?php echo esc_attr( 'manual' ); ?>"
1359 1337 backup_name="<?php echo esc_attr( $backup ); ?>"
1360 1338 href="javascript:void(0)">
@@ -1385,9 +1363,9 @@
1385 1363 $available_backups = array();
1386 1364 }
1387 1365
1388 1366 ?>
1389 - <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%">
1367 + <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%"> <?php // NOSONAR - id ok. ?>
1390 1368 <thead>
1391 1369 <tr>
1392 1370 <th scope="col" ><?php esc_html_e( 'Cloudways Backup Type', 'mainwp' ); ?></th>
1393 1371 <th scope="col" ><?php esc_html_e( 'Date Created', 'mainwp' ); ?></th>
@@ -1430,9 +1408,9 @@
1430 1408 } else {
1431 1409 $available_backups_list = array();
1432 1410 }
1433 1411 ?>
1434 - <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%">
1412 + <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%"> <?php // NOSONAR - id ok. ?>
1435 1413 <thead>
1436 1414 <tr>
1437 1415 <th scope="col" ><?php esc_html_e( 'Vultr Backup Label', 'mainwp' ); ?></th>
1438 1416 <th scope="col" ><?php esc_html_e( 'Size', 'mainwp' ); ?></th>
@@ -1482,9 +1460,9 @@
1482 1460 snapshot_id="<?php echo esc_attr( $backup->id ); ?>"
1483 1461 href="javascript:void(0)">
1484 1462 <i class="undo icon"></i>
1485 1463 </a>
1486 - <a class="mainwp_3rd_party_api_<?php esc_attr_e( $backup_api ); ?>_action_delete_backup ui mini icon button"
1464 + <a class="mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_delete_backup ui mini icon button"
1487 1465 website_id="<?php echo intval( $website['id'] ); ?>"
1488 1466 snapshot_id="<?php echo esc_attr( $backup->id ); ?>"
1489 1467 href="javascript:void(0)">
1490 1468 <i class="trash icon"></i>
@@ -1523,9 +1501,9 @@
1523 1501 } else {
1524 1502 $available_backups_snapshot_list = array();
1525 1503 }
1526 1504 ?>
1527 - <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%">
1505 + <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%"> <?php // NOSONAR - id ok. ?>
1528 1506 <thead>
1529 1507 <tr>
1530 1508 <th scope="col" ><?php esc_html_e( 'Akamai (Linode) Backup Type', 'mainwp' ); ?></th>
1531 1509 <th scope="col" ><?php esc_html_e( 'Date Created', 'mainwp' ); ?></th>
@@ -1537,9 +1515,9 @@
1537 1515 </thead>
1538 1516 <tbody>
1539 1517 <?php foreach ( $available_backups_automatic_list as $backup ) { ?>
1540 1518 <tr>
1541 - <td><i class="ui notched circle loading icon" style="display:none;"></i> <?php esc_html_e( $backup->type ); ?></td>
1519 + <td><i class="ui notched circle loading icon" style="display:none;"></i> <?php echo esc_html( $backup->type ); ?></td>
1542 1520 <td><?php echo esc_html( Api_Backups_Utility::format_timestamp( strtotime( $backup->created ) ) ); ?></td>
1543 1521 <td class="operation_status"><?php echo esc_html( $backup->status ); ?></td>
1544 1522 <td></td>
1545 1523 <td></td>
@@ -1556,9 +1534,9 @@
1556 1534 <?php } ?>
1557 1535 <?php foreach ( $available_backups_snapshot_list as $backup ) { ?>
1558 1536 <?php if ( null !== $backup ) { ?>
1559 1537 <tr>
1560 - <td><i class="ui notched circle loading icon" style="display:none;"></i> <?php esc_html_e( $backup->type ); ?></td>
1538 + <td><i class="ui notched circle loading icon" style="display:none;"></i> <?php echo esc_html( $backup->type ); ?></td>
1561 1539 <td><?php echo esc_html( Api_Backups_Utility::format_timestamp( strtotime( $backup->created ) ) ); ?></td>
1562 1540 <td><?php echo esc_html( $backup->status ); ?></td>
1563 1541 <td></td>
1564 1542 <td></td>
@@ -1597,9 +1575,9 @@
1597 1575 if ( ! is_array( $available_backups ) ) {
1598 1576 $available_backups = array();
1599 1577 }
1600 1578 ?>
1601 - <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%">
1579 + <table id="mainwp-siteid-<?php echo intval( $website['id'] ); ?>-table" class="ui mainwp-api-backup-table table" style="width:100%"> <?php // NOSONAR - id ok. ?>
1602 1580 <thead>
1603 1581 <tr>
1604 1582 <th scope="col" ><?php esc_html_e( 'DigitalOcean Backup Label', 'mainwp' ); ?></th>
1605 1583 <th scope="col" ><?php esc_html_e( 'Size', 'mainwp' ); ?></th>
@@ -1610,9 +1588,9 @@
1610 1588 </thead>
1611 1589 <tbody>
1612 1590 <?php foreach ( $available_backups as $backup ) { ?>
1613 1591 <tr>
1614 - <td><i class="ui notched circle loading icon" style="display:none;"></i> <?php esc_html_e( $backup->name ); ?></td>
1592 + <td><i class="ui notched circle loading icon" style="display:none;"></i> <?php echo esc_html( $backup->name ); ?></td>
1615 1593 <td><?php echo intval( $backup->size_gigabytes ); ?>GB</td>
1616 1594 <td><?php echo esc_html( Api_Backups_Utility::format_timestamp( strtotime( $backup->created_at ) ) ); ?></td>
1617 1595 <td></td>
1618 1596 <td class="collapsing right aligned">
@@ -1621,9 +1599,9 @@
1621 1599 snapshot_id="<?php echo esc_attr( $backup->id ); ?>"
1622 1600 href="javascript:void(0)">
1623 1601 <i class="undo icon"></i>
1624 1602 </a>
1625 - <a class="mainwp_3rd_party_api_<?php esc_attr_e( $backup_api ); ?>_action_delete_backup ui mini icon button"
1603 + <a class="mainwp_3rd_party_api_<?php echo esc_attr( $backup_api ); ?>_action_delete_backup ui mini icon button"
1626 1604 website_id="<?php echo intval( $website['id'] ); ?>"
1627 1605 snapshot_id="<?php echo esc_attr( $backup->id ); ?>"
1628 1606 href="javascript:void(0)">
1629 1607 <i class="trash icon"></i>
@@ -1669,9 +1647,8 @@
1669 1647 mainwp_datatable_fix_menu_overflow('.mainwp-api-backup-table', -55, 10 );
1670 1648 }, 1000);
1671 1649 }
1672 1650 } ).on( 'columns-reordered', function () {
1673 - console.log('columns-reordered');
1674 1651 setTimeout(() => {
1675 1652 jQuery( '.mainwp-api-backup-table .ui.dropdown' ).dropdown();
1676 1653 jQuery( '.mainwp-api-backup-table .ui.checkbox' ).checkbox();
1677 1654 mainwp_datatable_fix_menu_overflow('.mainwp-api-backup-table', -55, 10 );
@@ -1680,11 +1657,35 @@
1680 1657 });
1681 1658 } );
1682 1659 </script>
1683 1660 <?php
1684 - } // END if.
1661 + } // END if.
1685 1662 }
1686 1663
1664 + /**
1665 + * Fetch Cloudways oAuth Access Token.
1666 + *
1667 + * Fetch the Cloudways oAuth access token from the given API credentials.
1668 + *
1669 + * @return mixed Return Cloudways Access Token.
1670 + */
1671 + public static function get_saved_v2_access_token() {
1672 + if ( null === static::$access_token ) {
1673 + static::$access_token = self::get_cloudways_access_token();
1674 + }
1675 + return static::$access_token;
1676 + }
1677 + /**
1678 + * Fetch Cloudways oAuth Access Token.
1679 + *
1680 + * Fetch the Cloudways oAuth access token from the given API credentials.
1681 + *
1682 + * @return mixed Return Cloudways Access Token.
1683 + */
1684 + public static function is_access_token_v2() {
1685 + return ! empty( self::get_saved_v2_access_token() );
1686 + }
1687 +
1687 1688 /*********************************************************************************
1688 1689 * Cloudways API Methods.
1689 1690 **********************************************************************************/
1690 1691
@@ -1697,11 +1698,68 @@
1697 1698 * 2. Enter in your account email address and API Key below.
1698 1699 *
1699 1700 * @param string $method GET|POST|PUT|DELETE.
1700 1701 * @param string $url relative URL for the call.
1702 + * @param array $post Optional post data for the call.
1703 + * @return object|false Output from CW API.
1704 + */
1705 + public static function call_cloudways_api_v2( $method, $url, $post = array() ) {
1706 +
1707 + $access_token = self::get_saved_v2_access_token();
1708 +
1709 + $ch = curl_init();
1710 +
1711 + curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $method );
1712 + curl_setopt( $ch, CURLOPT_URL, self::CLOUDWAYS_API_URL . $url );
1713 + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1714 +
1715 + curl_setopt(
1716 + $ch,
1717 + CURLOPT_HTTPHEADER,
1718 + array(
1719 + 'Authorization: Bearer ' . $access_token,
1720 + 'Accept: application/json',
1721 + )
1722 + );
1723 +
1724 + // Set Post Parameters.
1725 + $encoded = '';
1726 + if ( count( $post ) ) {
1727 + foreach ( $post as $name => $value ) {
1728 + $encoded .= rawurlencode( $name ) . '=' . rawurlencode( $value ) . '&';
1729 + }
1730 +
1731 + $encoded = substr( $encoded, 0, strlen( $encoded ) - 1 );
1732 +
1733 + curl_setopt( $ch, CURLOPT_POSTFIELDS, $encoded );
1734 + curl_setopt( $ch, CURLOPT_POST, 1 );
1735 + }
1736 +
1737 + $output = curl_exec( $ch );
1738 + $httpcode = (int) curl_getinfo( $ch, CURLINFO_HTTP_CODE );
1739 +
1740 + curl_close( $ch );
1741 +
1742 + if ( 200 !== $httpcode ) {
1743 + return false;
1744 + }
1745 +
1746 + return json_decode( $output );
1747 + }
1748 +
1749 + /**
1750 + * Call Cloudways API, Authenticate & perform given method.
1751 + *
1752 + * Use this function to contact CW API
1753 + * We use OAuth, an open standard for authorization. Here are the steps involved:
1754 + * 1. Get your API Key from here: https://platform.cloudways.com/api
1755 + * 2. Enter in your account email address and API Key below.
1756 + *
1757 + * @param string $method GET|POST|PUT|DELETE.
1758 + * @param string $url relative URL for the call.
1701 1759 * @param string $accessToken Access token generated using OAuth Call.
1702 1760 * @param array $post Optional post data for the call.
1703 - * @return object Output from CW API.
1761 + * @return object|false Output from CW API.
1704 1762 */
1705 1763 public static function call_cloudways_api( $method, $url, $accessToken, $post = array() ) {
1706 1764 $baseURL = 'https://api.cloudways.com/api/v1';
1707 1765
@@ -1730,12 +1788,14 @@
1730 1788 $output = curl_exec( $ch );
1731 1789
1732 1790 $httpcode = (string) curl_getinfo( $ch, CURLINFO_HTTP_CODE );
1733 1791
1792 + curl_close( $ch );
1793 +
1734 1794 if ( '200' !== $httpcode ) {
1735 1795 return false;
1736 1796 }
1737 - curl_close( $ch );
1797 +
1738 1798 return json_decode( $output );
1739 1799 }
1740 1800
1741 1801 /**
@@ -1770,13 +1830,19 @@
1770 1830 *
1771 1831 * @return mixed Returns available list of servers.
1772 1832 */
1773 1833 public static function fetch_cloudways_server_list() { //phpcs:ignore -- NOSONAR - complex.
1774 - // Grab access token.
1775 - $accessToken = static::fetch_cloudways_access_token();
1776 1834
1777 - // Fetch Server List.
1778 - $serverList = (array) static::call_cloudways_api( 'GET', '/server', $accessToken );
1835 + if ( static::is_access_token_v2() ) {
1836 + $serverList = (array) static::call_cloudways_api_v2( 'GET', '/server' );
1837 + } else {
1838 + // Grab access token.
1839 + $accessToken = static::fetch_cloudways_access_token();
1840 +
1841 + // Fetch Server List.
1842 + $serverList = (array) static::call_cloudways_api( 'GET', '/server', $accessToken );
1843 + }
1844 +
1779 1845 if ( ! array_key_exists( 'servers', $serverList ) ) {
1780 1846 return;
1781 1847 }
1782 1848 // Return the server list.
@@ -1892,21 +1958,34 @@
1892 1958 'server_id' => $server_id,
1893 1959 'app_id' => $app_id,
1894 1960 );
1895 1961
1896 - // Grab Cloudways access token.
1897 - $accessToken = static::fetch_cloudways_access_token();
1962 + $accessToken = '';
1898 1963
1899 - // Send Payload & create backup.
1900 - $api_response = (array) static::call_cloudways_api( 'POST', '/app/manage/takeBackup', $accessToken, $data );
1964 + if ( static::is_access_token_v2() ) {
1965 + $api_response = (array) static::call_cloudways_api_v2( 'POST', '/app/manage/takeBackup', $data );
1966 + } else {
1901 1967
1968 + // Grab Cloudways access token.
1969 + $accessToken = static::fetch_cloudways_access_token();
1970 +
1971 + // Send Payload & create backup.
1972 + $api_response = (array) static::call_cloudways_api( 'POST', '/app/manage/takeBackup', $accessToken, $data );
1973 + }
1974 +
1902 1975 $success = true;
1903 1976
1904 1977 if ( true !== $api_response['status'] ) {
1905 1978 $success = false;
1906 1979 } else {
1907 - // Save current backup operation.
1908 - $backup_operation = (array) static::call_cloudways_api( 'GET', static::OPERATION . $api_response['operation_id'], $accessToken );
1980 + if ( static::is_access_token_v2() ) {
1981 + // Save current backup operation.
1982 + $backup_operation = (array) static::call_cloudways_api_v2( 'GET', static::OPERATION . $api_response['operation_id'] );
1983 + } else {
1984 + // Save current backup operation.
1985 + $backup_operation = (array) static::call_cloudways_api( 'GET', static::OPERATION . $api_response['operation_id'], $accessToken );
1986 + }
1987 +
1909 1988 $backup_operation = wp_json_encode( $backup_operation['operation'] );
1910 1989 Api_Backups_Helper::update_website_option( $website_id, 'mainwp_3rd_party_cloudways_backup_operation', $backup_operation );
1911 1990
1912 1991 // Save Timestamp.
@@ -1955,13 +2034,19 @@
1955 2034 // Current backup operation.
1956 2035 $backup_operation = isset( $site_options['mainwp_3rd_party_cloudways_backup_operation'] ) ? $site_options['mainwp_3rd_party_cloudways_backup_operation'] : null;
1957 2036 $operation_id = json_decode( $backup_operation, true )['id'];
1958 2037
1959 - // Grab Cloudways access token.
1960 - $accessToken = static::fetch_cloudways_access_token();
2038 + if ( static::is_access_token_v2() ) {
2039 + // Send Payload & list backups. https://api.cloudways.com/api/v1/operation/{id}.
2040 + $operation_polling = static::call_cloudways_api_v2( 'GET', static::OPERATION . $operation_id );
2041 + } else {
1961 2042
1962 - // Send Payload & list backups. https://api.cloudways.com/api/v1/operation/{id}.
1963 - $operation_polling = static::call_cloudways_api( 'GET', static::OPERATION . $operation_id, $accessToken );
2043 + // Grab Cloudways access token.
2044 + $accessToken = static::fetch_cloudways_access_token();
2045 +
2046 + // Send Payload & list backups. https://api.cloudways.com/api/v1/operation/{id}.
2047 + $operation_polling = static::call_cloudways_api( 'GET', static::OPERATION . $operation_id, $accessToken );
2048 + }
1964 2049 $backup_polling_response = $operation_polling->operation;
1965 2050
1966 2051 // If backup has not been completed yet, sleep for 30 seconds and check again.
1967 2052 // If backup has been completed, save the backup operation results.
@@ -1997,10 +2082,8 @@
1997 2082 // Grab $_GET['data'] from url if not Ajax call.
1998 2083 $website_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0; //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended
1999 2084 }
2000 2085
2001 - // Grab Cloudways access token.
2002 - $accessToken = static::fetch_cloudways_access_token();
2003 2086
2004 2087 // Grab needed site options from WP_MAINWP_WP_OPTIONS table.
2005 2088 $site_options = Api_Backups_Helper::get_website_options(
2006 2089 $website_id,
@@ -2011,18 +2094,31 @@
2011 2094 );
2012 2095 $server_id = isset( $site_options['mainwp_3rd_party_instance_id'] ) ? $site_options['mainwp_3rd_party_instance_id'] : null;
2013 2096 $app_id = isset( $site_options['mainwp_3rd_party_app_id'] ) ? $site_options['mainwp_3rd_party_app_id'] : null;
2014 2097
2015 - // Grab Backup operation from API.
2016 - $backup_operation = static::call_cloudways_api( 'GET', '/app/manage/backup?server_id=' . $server_id . '&app_id=' . $app_id, $accessToken );
2017 - $operation_id = $backup_operation->operation_id;
2098 + if ( static::is_access_token_v2() ) {
2099 + // Grab Backup operation from API.
2100 + $backup_operation = static::call_cloudways_api_v2( 'GET', '/app/manage/backup?server_id=' . $server_id . '&app_id=' . $app_id );
2101 + } else {
2102 + // Grab Cloudways access token.
2103 + $accessToken = static::fetch_cloudways_access_token();
2104 + // Grab Backup operation from API.
2105 + $backup_operation = static::call_cloudways_api( 'GET', '/app/manage/backup?server_id=' . $server_id . '&app_id=' . $app_id, $accessToken );
2106 + }
2018 2107
2108 + $operation_id = $backup_operation->operation_id;
2109 +
2019 2110 sleep( 3 ); // REQUIRED! Wait 3 seconds for cURL connection to be closed before opening a new one.
2020 2111
2021 - // Send Payload & list backups. https://api.cloudways.com/api/v1/operation/{id}.
2022 - $operation_polling = static::call_cloudways_api( 'GET', static::OPERATION . $operation_id, $accessToken );
2023 - $operation = $operation_polling->operation;
2112 + if ( static::is_access_token_v2() ) {
2113 + $operation_polling = static::call_cloudways_api_v2( 'GET', static::OPERATION . $operation_id );
2114 + } else {
2115 + // Send Payload & list backups. https://api.cloudways.com/api/v1/operation/{id}.
2116 + $operation_polling = static::call_cloudways_api( 'GET', static::OPERATION . $operation_id, $accessToken );
2117 + }
2024 2118
2119 + $operation = $operation_polling->operation;
2120 +
2025 2121 // Save backup operation.
2026 2122 Api_Backups_Helper::update_website_option( $website_id, 'mainwp_3rd_party_cloudways_available_backups', $operation->parameters );
2027 2123
2028 2124 Api_Backups_Utility::save_lasttime_backup( $website_id, $operation->parameters, 'cloudways' );
@@ -2070,13 +2166,17 @@
2070 2166 'time' => $backup_date,
2071 2167 'type' => 'complete',
2072 2168 );
2073 2169
2074 - // Grab Cloudways access token.
2075 - $accessToken = static::fetch_cloudways_access_token();
2170 + if ( static::is_access_token_v2() ) {
2171 + $api_response = static::call_cloudways_api_v2( 'POST', '/app/manage/restore', $data );
2172 + } else {
2173 + // Grab Cloudways access token.
2174 + $accessToken = static::fetch_cloudways_access_token();
2076 2175
2077 - // Send Payload & create backup.
2078 - $api_response = static::call_cloudways_api( 'POST', '/app/manage/restore', $accessToken, $data );
2176 + // Send Payload & create backup.
2177 + $api_response = static::call_cloudways_api( 'POST', '/app/manage/restore', $accessToken, $data );
2178 + }
2079 2179
2080 2180 // Handle API response.
2081 2181 if ( 1 !== (int) $api_response->status ) {
2082 2182 wp_die( 'false' );
@@ -2267,8 +2367,16 @@
2267 2367 return Api_Backups_Utility::get_instance()->get_api_key( 'cloudways' );
2268 2368 }
2269 2369
2270 2370 /**
2371 + * Method get_cloudways_access_token().
2372 + */
2373 + public static function get_cloudways_access_token() {
2374 + return Api_Backups_Utility::get_instance()->get_api_key( 'cloudways', '', 'access_token' );
2375 + }
2376 +
2377 +
2378 + /**
2271 2379 * Method get_cpanel_account_password().
2272 2380 */
2273 2381 public static function get_cpanel_account_password() {
2274 2382 return Api_Backups_Utility::get_instance()->get_api_key( 'cpanel' );
@@ -2785,9 +2893,9 @@
2785 2893 $local_time = current_datetime();
2786 2894 $current_time = $local_time->getTimestamp() + $local_time->getOffset();
2787 2895 Api_Backups_Helper::update_website_option( $website_id, 'mainwp_3rd_party_gridpane_last_backup', $current_time );
2788 2896 } else {
2789 - $error = new WP_Error( $backup_status->error->code, __( $backup_status->error->message, 'mainwp' ) );
2897 + $error = new WP_Error( $backup_status->error->code, $backup_status->error->message );
2790 2898 }
2791 2899
2792 2900 if ( $ret_val ) {
2793 2901 return $backup_status;
@@ -3056,9 +3164,9 @@
3056 3164 }
3057 3165
3058 3166 // Handle response.
3059 3167 if ( isset( $linode_response->errors ) ) {
3060 - $error = new WP_Error( '400', __( $linode_response->errors['0']->reason, 'mainwp' ) );
3168 + $error = new WP_Error( '400', $linode_response->errors['0']->reason );
3061 3169 // Return AJAX.
3062 3170 if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) {
3063 3171 wp_send_json_error( $error );
3064 3172
@@ -3524,8 +3632,15 @@
3524 3632 * @return array Output from cPanel API.
3525 3633 */
3526 3634 public static function call_plesk_api( $method, $url, $baseurl, $api_key, $backup_data = array() ) {
3527 3635
3636 + // To fix double slash issue in url if exists. If url starts with / and baseurl ends with /, then remove the last slash from baseurl.
3637 + if ( '/' === substr( $url, 0, 1 ) && '/' === substr( $baseurl, -1 ) ) {
3638 + $baseurl = rtrim( $baseurl, '/' );
3639 + }
3640 +
3641 + $full_url = $baseurl . $url;
3642 +
3528 3643 $curl = curl_init();
3529 3644
3530 3645 $api_Key = $api_key;
3531 3646 curl_setopt_array(
@@ -3530,9 +3645,9 @@
3530 3645 $api_Key = $api_key;
3531 3646 curl_setopt_array(
3532 3647 $curl,
3533 3648 array(
3534 - CURLOPT_URL => $baseurl . $url,
3649 + CURLOPT_URL => $full_url,
3535 3650 CURLOPT_RETURNTRANSFER => true,
3536 3651 CURLOPT_ENCODING => '',
3537 3652 CURLOPT_MAXREDIRS => 10,
3538 3653 CURLOPT_TIMEOUT => 0,
@@ -5154,14 +5269,17 @@
5154 5269 * Kinsta: Action refresh available backups.
5155 5270 *
5156 5271 * Save backups to DB for the selected server.
5157 5272 *
5158 - * @return void
5273 + * @param array $credentials Kinsta credentials.
5274 + * @param bool $return_result Return or not.
5275 + *
5276 + * @return mixed
5159 5277 */
5160 - public static function kinsta_action_refresh_available_backups() {
5278 + public static function kinsta_action_refresh_available_backups( $credentials = array(), $return_result = false ) {
5161 5279
5162 5280 // Authenticate kinsta account.
5163 - $kinsta_authentication_credentials = static::get_kinsta_authentication_credentials();
5281 + $kinsta_authentication_credentials = empty( $credentials ) || ! is_array( $credentials ) ? static::get_kinsta_authentication_credentials() : $credentials;
5164 5282 $kinsta_baseurl = $kinsta_authentication_credentials[0]['kinsta_baseurl'];
5165 5283 $kinsta_api_key = $kinsta_authentication_credentials[0]['kinsta_api_key'];
5166 5284 $kinsta_env_id = $kinsta_authentication_credentials[0]['kinsta_environment_id'];
5167 5285 $website_id = $kinsta_authentication_credentials[0]['website_id'];
@@ -5171,8 +5289,10 @@
5171 5289
5172 5290 // Grab backup meta.
5173 5291 $api_response = static::call_kinsta_api( 'GET', '/sites/environments/' . $kinsta_env_id . '/backups', $kinsta_baseurl, $kinsta_api_key, $action );
5174 5292
5293 + $success = false;
5294 +
5175 5295 if ( 'true' === $api_response['status'] ) {
5176 5296 $all_backups = $api_response['response'];
5177 5297 Api_Backups_Helper::update_website_option( $website_id, 'mainwp_3rd_party_kinsta_available_backups', $all_backups );
5178 5298 Api_Backups_Utility::save_lasttime_backup( $website_id, $all_backups, 'kinsta' );
@@ -5179,9 +5299,9 @@
5179 5299
5180 5300 $action = 'kinsta_action_refresh_available_backups_downloadable';
5181 5301
5182 5302 $downloadable_backups = static::call_kinsta_api( 'GET', '/sites/environments/' . $kinsta_env_id . '/downloadable-backups', $kinsta_baseurl, $kinsta_api_key, $action );
5183 -
5303 + $success = true;
5184 5304 } else {
5185 5305 Api_Backups_Utility::log_debug( 'Kinsta API Error: ' . $api_response['response'] );
5186 5306 }
5187 5307 if ( $downloadable_backups ) {
@@ -5192,8 +5312,12 @@
5192 5312 } else {
5193 5313 Api_Backups_Utility::log_debug( 'Kinsta API Error: There was an issue while refreshing available backups.' );
5194 5314 }
5195 5315
5316 + if ( $return_result ) {
5317 + return $success;
5318 + }
5319 +
5196 5320 // Return AJAX.
5197 5321 if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) {
5198 5322 // Store Last Backup timestamp.
5199 5323 if ( 'true' === $api_response['status'] ) {
@@ -5230,9 +5354,9 @@
5230 5354 // Prepare Backup Payload.
5231 5355 $backup_data = array(
5232 5356 'tag' => 'MainWP API Backups - ' . $website['name'],
5233 5357 );
5234 - $backup_data = json_encode( $backup_data );
5358 + $backup_data = wp_json_encode( $backup_data );
5235 5359
5236 5360 // Send Payload & create backup.
5237 5361 $api_response = static::call_kinsta_api( 'POST', '/sites/environments/' . $kinsta_env_id . '/manual-backups', $kinsta_baseurl, $kinsta_api_key, $backup_data );
5238 5362
@@ -5281,8 +5405,12 @@
5281 5405
5282 5406 // Send Payload & create backup.
5283 5407 $api_response = static::call_kinsta_api( 'DELETE', $payload_url, $kinsta_baseurl, $kinsta_api_key, '' );
5284 5408
5409 + if ( is_array( $api_response ) && isset( $api_response['status'] ) && 'true' === $api_response['status'] ) {
5410 + static::kinsta_action_refresh_available_backups( $kinsta_authentication_credentials, true );
5411 + }
5412 +
5285 5413 if ( $return_values ) {
5286 5414 return $api_response;
5287 5415 }
5288 5416
@@ -5325,9 +5453,9 @@
5325 5453 $backup_data = array(
5326 5454 'backup_id' => $backup_id,
5327 5455 'notified_user_id' => $company_user_id,
5328 5456 );
5329 - $backup_data = json_encode( $backup_data );
5457 + $backup_data = wp_json_encode( $backup_data );
5330 5458
5331 5459 // Send Payload & create backup.
5332 5460 $api_response = static::call_kinsta_api( 'POST', $payload_url, $kinsta_baseurl, $kinsta_api_key, '', $backup_data );
5333 5461