PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.1.6
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.1.6
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
mainwp / pages / page-mainwp-manage-backups.php

page-mainwp-manage-backups.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 6.1.6, at pages/page-mainwp-manage-backups.php

1,241 lines 61.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Legacy Backups Page.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Class MainWP_Manage_Backups
17 *
18 * @package MainWP\Dashboard
19 */
20 class MainWP_Manage_Backups { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
21
22 /**
23 * Get Class Name.
24 *
25 * @return string __CLASS__
26 */
27 public static function get_class_name() {
28 return __CLASS__;
29 }
30
31 /**
32 * Subpages variable.
33 *
34 * @var undefined $subPages Subpages variable.
35 */
36 public static $subPages;
37
38 /**
39 * Whether or not to show the Backups Submenu.
40 *
41 * @var boolean $hideSubmenuBackups true|false,
42 * .
43 */
44 private static $hideSubmenuBackups = false;
45
46 /**
47 * Instance variable.
48 *
49 * @var null Instance variable.
50 */
51 private static $instance = null;
52
53 /**
54 * Create instance.
55 *
56 * @return self $instance.
57 *
58 * @uses \MainWP\Dashboard\MainWP_Manage_Backups
59 */
60 public static function instance() {
61 if ( null === static::$instance ) {
62 static::$instance = new MainWP_Manage_Backups();
63 }
64
65 return static::$instance;
66 }
67
68 /** Instantiate Hooks. */
69 public static function init() {
70 /**
71 * This hook allows you to render the Backups page header via the 'mainwp-pageheader-backups' action.
72 *
73 * @link http://codex.mainwp.com/#mainwp-pageheader-backups
74 *
75 * This hook is normally used in the same context of 'mainwp-getsubpages-backups'
76 * @link http://codex.mainwp.com/#mainwp-getsubpages-backups
77 *
78 * @see \MainWP_Manage_Backups::render_header
79 */
80 add_action( 'mainwp-pageheader-backups', array( static::get_class_name(), 'render_header' ) );
81
82 /**
83 * This hook allows you to render the Backups page footer via the 'mainwp-pagefooter-backups' action.
84 *
85 * @link http://codex.mainwp.com/#mainwp-pagefooter-backups
86 *
87 * This hook is normally used in the same context of 'mainwp-getsubpages-backups'
88 * @link http://codex.mainwp.com/#mainwp-getsubpages-backups
89 *
90 * @see \MainWP_Manage_Backups::render_footer
91 */
92 add_action( 'mainwp-pagefooter-backups', array( static::get_class_name(), 'render_footer' ) );
93 }
94
95 /**
96 * Instantiate Legacy Backups Menu.
97 *
98 * @return void
99 *
100 * @uses \MainWP\Dashboard\MainWP_Menu::add_left_menu()
101 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
102 */
103 public static function init_menu() { //phpcs:ignore -- NOSONAR - complex.
104 $enable_legacy_backup = get_option( 'mainwp_enableLegacyBackupFeature' );
105 $mainwp_primaryBackup = get_option( 'mainwp_primaryBackup' );
106
107 /**
108 * Backups Subpages
109 *
110 * Filters subpages for the Backups page.
111 *
112 * @since Unknown
113 */
114 $customPage = apply_filters_deprecated( 'mainwp-getcustompage-backups', array( false ), '4.0.7.2', 'mainwp_getcustompage_backups' ); // @deprecated Use 'mainwp_getcustompage_backups' instead. NOSONAR - not IP.
115 $customPage = apply_filters( 'mainwp_getcustompage_backups', $customPage );
116
117 if ( is_array( $customPage ) && isset( $customPage['slug'] ) && ! empty( $mainwp_primaryBackup ) ) {
118 static::$hideSubmenuBackups = true;
119 add_submenu_page( 'mainwp_tab', $customPage['title'], '<span id="mainwp-Backups">' . $customPage['title'] . '</span>', 'read', 'ManageBackups' . $customPage['slug'], $customPage['callback'] );
120 MainWP_Menu::add_left_menu(
121 array(
122 'title' => $customPage['title'],
123 'parent_key' => 'mainwp_tab',
124 'slug' => 'ManageBackups' . $customPage['slug'],
125 'href' => 'admin.php?page=ManageBackups' . $customPage['slug'],
126 'icon' => '<i class="hdd outline icon"></i>',
127 ),
128 1
129 );
130
131 } elseif ( $enable_legacy_backup ) {
132 add_submenu_page( 'mainwp_tab', esc_html__( 'Backups', 'mainwp' ), '<span id="mainwp-Backups">' . esc_html__( 'Backups', 'mainwp' ) . '</span>', 'read', 'ManageBackups', array( static::get_class_name(), 'render_manager' ) );
133 if ( \mainwp_current_user_can( 'dashboard', 'add_backup_tasks' ) ) {
134 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'ManageBackupsAddNew' ) ) {
135 add_submenu_page( 'mainwp_tab', esc_html__( 'Add New Schedule', 'mainwp' ), '<div class="mainwp-hidden">' . esc_html__( 'Add New', 'mainwp' ) . '</div>', 'read', 'ManageBackupsAddNew', array( static::get_class_name(), 'render_new' ) );
136 }
137 }
138 } else {
139 return;
140 }
141
142 /**
143 * This hook allows you to add extra sub pages to the Backups page via the 'mainwp-getsubpages-backups' filter.
144 *
145 * @link http://codex.mainwp.com/#mainwp-getsubpages-backups
146 */
147
148 $sub_pages = array();
149 $sub_pages = apply_filters_deprecated( 'mainwp-getsubpages-backups', array( $sub_pages ), '4.0.7.2', 'mainwp_getsubpages_backups' ); // @deprecated Use 'mainwp_getsubpages_backups' instead. NOSONAR - not IP.
150 static::$subPages = apply_filters( 'mainwp_getsubpages_backups', $sub_pages );
151 if ( isset( static::$subPages ) && is_array( static::$subPages ) ) {
152 foreach ( static::$subPages as $subPage ) {
153 if ( MainWP_Menu::is_disable_menu_item( 3, 'ManageBackups' . $subPage['slug'] ) ) {
154 continue;
155 }
156 add_submenu_page( 'mainwp_tab', $subPage['title'], '<div class="mainwp-hidden">' . $subPage['title'] . '</div>', 'read', 'ManageBackups' . $subPage['slug'], $subPage['callback'] );
157 }
158 }
159 static::init_left_menu( static::$subPages, $enable_legacy_backup );
160 }
161
162 /**
163 * Instantiate legacy backups subpages.
164 *
165 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
166 */
167 public static function init_subpages_menu() { //phpcs:ignore -- NOSONAR - complex.
168 if ( static::$hideSubmenuBackups && ( empty( static::$subPages ) || ! is_array( static::$subPages ) ) ) {
169 return;
170 }
171 ?>
172 <div id="menu-mainwp-Backups" class="mainwp-submenu-wrapper">
173 <div class="wp-submenu sub-open" style="">
174 <div class="mainwp_boxout">
175 <?php
176 if ( ! static::$hideSubmenuBackups ) {
177 ?>
178 <div class="mainwp_boxoutin"></div>
179 <a href="<?php echo esc_url( admin_url( 'admin.php?page=ManageBackups' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Manage Backups', 'mainwp' ); ?></a>
180 <?php if ( \mainwp_current_user_can( 'dashboard', 'add_backup_tasks' ) ) { ?>
181 <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'ManageBackupsAddNew' ) ) { ?>
182 <a href="<?php echo esc_url( admin_url( 'admin.php?page=ManageBackupsAddNew' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Add New', 'mainwp' ); ?></a>
183 <?php } ?>
184 <?php } ?>
185 <?php } ?>
186 <?php
187 if ( isset( static::$subPages ) && is_array( static::$subPages ) ) {
188 foreach ( static::$subPages as $subPage ) {
189 if ( MainWP_Menu::is_disable_menu_item( 3, 'ManageBackups' . $subPage['slug'] ) ) {
190 continue;
191 }
192 ?>
193 <a href="<?php echo esc_url( admin_url( 'admin.php?page=ManageBackups' . $subPage['slug'] ) ); ?>" class="mainwp-submenu"><?php echo esc_html( $subPage['title'] ); ?></a>
194 <?php
195 }
196 }
197 ?>
198 </div>
199 </div>
200 </div>
201 <?php
202 }
203
204 /**
205 * Instantiate Legacy Backups Menu.
206 *
207 * @param array $subPages Legacy Backup Subpages.
208 * @param bool $enableLegacyBackup ture|false, whether or not to enable menu.
209 *
210 * @uses \MainWP\Dashboard\MainWP_Menu::add_left_menu()
211 * @uses \MainWP\Dashboard\MainWP_Menu::init_subpages_left_menu()
212 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
213 */
214 public static function init_left_menu( $subPages = array(), $enableLegacyBackup = true ) {
215 if ( ! static::$hideSubmenuBackups && $enableLegacyBackup ) {
216 MainWP_Menu::add_left_menu(
217 array(
218 'title' => esc_html__( 'Backups', 'mainwp' ),
219 'parent_key' => 'managesites',
220 'slug' => 'ManageBackups',
221 'href' => 'admin.php?page=ManageBackups',
222 'icon' => '<i class="hdd outline icon"></i>',
223 ),
224 1
225 );
226
227 $init_sub_subleftmenu = array(
228 array(
229 'title' => esc_html__( 'Manage Backups', 'mainwp' ),
230 'parent_key' => 'ManageBackups',
231 'href' => 'admin.php?page=ManageBackups',
232 'slug' => 'ManageBackups',
233 'right' => '',
234 ),
235 array(
236 'title' => esc_html__( 'Add New', 'mainwp' ),
237 'parent_key' => 'ManageBackups',
238 'href' => 'admin.php?page=ManageBackupsAddNew',
239 'slug' => 'ManageBackupsAddNew',
240 'right' => 'add_backup_tasks',
241 ),
242 );
243
244 MainWP_Menu::init_subpages_left_menu( $subPages, $init_sub_subleftmenu, 'ManageBackups', 'ManageBackups' );
245
246 foreach ( $init_sub_subleftmenu as $item ) {
247 if ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) {
248 continue;
249 }
250 MainWP_Menu::add_left_menu( $item, 2 );
251 }
252 }
253 }
254
255 /**
256 * Render MainWP Legacy Backups Page Header.
257 *
258 * @param string $shownPage The page slug shown at this moment.
259 *
260 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
261 * @uses \MainWP\Dashboard\MainWP_UI::render_top_header()
262 * @uses \MainWP\Dashboard\MainWP_UI::render_page_navigation()
263 */
264 public static function render_header( $shownPage = '' ) { //phpcs:ignore -- NOSONAR - complex.
265
266 $params = array(
267 'title' => esc_html__( 'Backups', 'mainwp' ),
268 );
269
270 MainWP_UI::render_top_header( $params );
271
272 $renderItems = array();
273
274 $renderItems[] = array(
275 'title' => esc_html__( 'Manage Backups', 'mainwp' ),
276 'href' => 'admin.php?page=ManageBackups',
277 'active' => ( '' === $shownPage ) ? true : false,
278 'disabled' => MainWP_Menu::is_disable_menu_item( 3, 'ManageBackups' ) ? true : false,
279 );
280
281 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'ManageBackupsAddNew' ) ) {
282 $renderItems[] = array(
283 'title' => esc_html__( 'Add New', 'mainwp' ),
284 'href' => 'admin.php?page=ManageBackupsAddNew',
285 'access' => \mainwp_current_user_can( 'dashboard', 'add_backup_tasks' ),
286 'active' => ( 'AddNew' === $shownPage ) ? true : false,
287 'disabled' => MainWP_Menu::is_disable_menu_item( 3, 'ManageBackupsAddNew' ) ? true : false,
288 );
289 }
290
291 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'ManageBackupsEdit' ) ) {
292 if ( 'ManageBackupsEdit' === $shownPage ) {
293 $renderItems[] = array(
294 'title' => esc_html__( 'Edit', 'mainwp' ),
295 'href' => '#',
296 'active' => true,
297 );
298 }
299 }
300
301 if ( isset( static::$subPages ) && is_array( static::$subPages ) ) {
302 foreach ( static::$subPages as $subPage ) {
303 if ( MainWP_Menu::is_disable_menu_item( 3, 'ManageBackups' . $subPage['slug'] ) ) {
304 continue;
305 }
306
307 $item = array();
308 $item['title'] = esc_html( $subPage['title'] );
309 $item['href'] = 'admin.php?page=ManageBackups' . $subPage['slug'];
310 $item['active'] = ( $subPage['slug'] === $shownPage ) ? true : false;
311 $renderItems[] = $item;
312 }
313 }
314
315 MainWP_UI::render_page_navigation( $renderItems );
316 }
317
318 /**
319 * Render MainWP Legacy Backups Footer.
320 */
321 public static function render_footer() {
322 echo '</div>';
323 }
324
325 /**
326 * Render Legacy Backups page.
327 *
328 * @uses \MainWP\Dashboard\MainWP_DB_Backup::get_backup_task_by_id()
329 * @uses \MainWP\Dashboard\MainWP_DB_Backup::get_backup_tasks_for_user()
330 * @uses \MainWP\Dashboard\MainWP_UI::render_modal_edit_notes()
331 * @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::can_edit_backuptask()
332 * @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::validate_backup_tasks()
333 */
334 public static function render_manager() { //phpcs:ignore -- NOSONAR - complex.
335 $backupTask = null;
336 //phpcs:disable WordPress.Security.NonceVerification.Recommended
337 if ( isset( $_GET['id'] ) ) {
338 if ( ! \mainwp_current_user_can( 'dashboard', 'edit_backup_tasks' ) ) {
339 \mainwp_do_not_have_permissions( esc_html__( 'edit backup tasks', 'mainwp' ) );
340 return;
341 }
342 $backupTaskId = intval( $_GET['id'] );
343
344 $backupTask = MainWP_DB_Backup::instance()->get_backup_task_by_id( $backupTaskId );
345 if ( ! MainWP_Manage_Backups_Handler::can_edit_backuptask( $backupTask ) ) {
346 $backupTask = null;
347 }
348
349 if ( ! empty( $backupTask ) ) {
350 if ( ! MainWP_Manage_Backups_Handler::validate_backup_tasks( array( $backupTask ) ) ) {
351 $backupTask = MainWP_DB_Backup::instance()->get_backup_task_by_id( $backupTaskId );
352 }
353 }
354 }
355
356 $primary_methods = array();
357 $primary_methods = apply_filters_deprecated( 'mainwp-getprimarybackup-methods', array( $primary_methods ), '4.0.7.2', 'mainwp_getprimarybackup_methods' ); // @deprecated Use 'mainwp_getprimarybackup_methods' instead. NOSONAR - not IP.
358 $primaryBackupMethods = apply_filters( 'mainwp_getprimarybackup_methods', $primary_methods );
359
360 if ( ! is_array( $primaryBackupMethods ) ) {
361 $primaryBackupMethods = array();
362 }
363
364 if ( null === $backupTask ) {
365
366 $backup_items = MainWP_DB_Backup::instance()->get_backup_tasks_for_user();
367 if ( ! MainWP_Manage_Backups_Handler::validate_backup_tasks( $backup_items ) ) {
368 $backup_items = MainWP_DB_Backup::instance()->get_backup_tasks_for_user();
369 }
370
371 static::render_header( '' );
372 ?>
373 <?php if ( 0 === count( $primaryBackupMethods ) ) { ?>
374 <div class="ui blue message"><?php /* translators: 1: opening anchor tag, 2: closing anchor tag */ printf( esc_html__( 'Did you know that MainWP has extensions for working with popular backup plugins? Visit the %1$sextensions site%2$s for options.', 'mainwp' ), '<a href="https://mainwp.com/extensions/extension-category/backups/" target="_blank" ?>', '</a>' ); // NOSONAR - noopener - open safe. ?></div>
375 <?php } ?>
376 <div class="ui alt segment">
377 <div id="mainwp_managebackups_add_message" class="ui green message" style="display:
378 <?php
379 if ( isset( $_GET['a'] ) && '1' === $_GET['a'] ) {
380 echo 'block';
381 } else {
382 echo 'none';
383 }
384 ?>
385 ">
386 <?php
387 if ( isset( $_GET['a'] ) && '1' === $_GET['a'] ) {
388 echo '<p>' . esc_html__( 'The backup task was added successfully', 'mainwp' ) . '</p>';
389 }
390 ?>
391 </div>
392
393 <form method="post" class="mainwp-table-container">
394 <?php MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' ); ?>
395 <?php
396 MainWP_UI::render_modal_edit_notes();
397 static::instance()->display( $backup_items );
398 ?>
399 </form>
400 </div>
401
402 <div class="ui modal" id="managebackups-task-status-box" tabindex="0">
403 <div class="header">Running task</div>
404 <div class="content mainwp-modal-content"></div>
405 <div class="actions mainwp-modal-actions">
406 <input id="managebackups-task-status-close" type="button" name="Close" value="<?php esc_attr_e( 'Cancel', 'mainwp' ); ?>" class="button" />
407 </div>
408 </div>
409 <?php
410 static::render_footer( '' );
411 } else {
412 static::render_edit( $backupTask );
413 }
414 //phpcs:enable
415 }
416
417 /**
418 * Render MainWP Legacy Backups Table.
419 *
420 * @param mixed $backup_items List Item.
421 *
422 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_group_id()
423 */
424 public function display( $backup_items ) { //phpcs:ignore -- NOSONAR - complex.
425 $can_trigger = true;
426 if ( ! \mainwp_current_user_can( 'dashboard', 'run_backup_tasks' ) ) {
427 $can_trigger = false;
428 }
429 ?>
430 <table id="mainwp-backups-table" class="ui padded selectable compact single line table">
431 <thead class="full-width">
432 <tr>
433 <th id="mainwp-title"><?php esc_html_e( 'Task name', 'mainwp' ); ?></th>
434 <th id="mainwp-type"><?php esc_html_e( 'Type', 'mainwp' ); ?></th>
435 <th id="mainwp-schedule"><?php esc_html_e( 'Schedule', 'mainwp' ); ?></th>
436 <th id="mainwp-dest" class="no-sort"><?php esc_html_e( 'Destination', 'mainwp' ); ?></th>
437 <th id="mainwp-website"><?php esc_html_e( 'Website', 'mainwp' ); ?></th>
438 <th id="mainwp-details" class="no-sort"><?php esc_html_e( 'Details', 'mainwp' ); ?></th>
439 <?php if ( $can_trigger ) { ?>
440 <th id="mainwp-trigger" class="no-sort"><?php esc_html_e( 'Trigger', 'mainwp' ); ?></th>
441 <?php } ?>
442 <th id="mainwp-actions" class="no-sort"></th>
443 </tr>
444 </thead>
445 <tbody>
446 <?php
447 if ( $backup_items ) {
448 $columns = array(
449 'task_name' => esc_html__( 'Task Name', 'mainwp' ),
450 'type' => esc_html__( 'Type', 'mainwp' ),
451 'schedule' => esc_html__( 'Schedule', 'mainwp' ),
452 'destination' => esc_html__( 'Destination', 'mainwp' ),
453 'websites' => esc_html__( 'Websites', 'mainwp' ),
454 'details' => esc_html__( 'Details', 'mainwp' ),
455 'trigger' => esc_html__( 'Trigger', 'mainwp' ),
456 'actions' => esc_html__( 'Trigger', 'mainwp' ),
457 );
458
459 if ( ! $can_trigger ) {
460 unset( $columns['trigger'] );
461 }
462
463 foreach ( $backup_items as $item ) {
464 $sites = ( empty( $item->sites ) ? array() : explode( ',', $item->sites ) );
465 $groups = ( empty( $item->groups ) ? array() : explode( ',', $item->groups ) );
466 foreach ( $groups as $group ) {
467 $websites = MainWP_DB::instance()->get_websites_by_group_id( $group );
468 if ( empty( $websites ) ) {
469 continue;
470 }
471
472 foreach ( $websites as $website ) {
473 if ( ! in_array( $website->id, $sites ) ) {
474 $sites[] = $website->id;
475 }
476 }
477 }
478
479 $item->the_sites = $sites;
480
481 $this->single_row( $item, $columns );
482 }
483 }
484 ?>
485 </tbody>
486 </table>
487 <script type="text/javascript">
488 jQuery( document ).ready( function () {
489 jQuery( '#mainwp-backups-table' ).DataTable( {
490 "colReorder" : true,
491 "stateSave": true,
492 "pagingType": "full_numbers",
493 "order": [],
494 "columnDefs": [ {
495 "targets": 'no-sort',
496 "orderable": false
497 } ],
498 "drawCallback": function( settings ) {
499 jQuery( '#mainwp-backups-table .ui.dropdown' ).dropdown();
500 },
501 } );
502 } );
503 </script>
504 <?php
505 }
506
507 /**
508 * Single row Content.
509 *
510 * @param mixed $item Item to go in column.
511 * @param mixed $columns Columns Array.
512 */
513 public function single_row( $item, $columns ) {
514 ?>
515 <tr>
516 <?php
517 foreach ( $columns as $column_name => $title ) {
518 if ( method_exists( $this, 'column_' . $column_name ) ) {
519 echo '<td>';
520 echo call_user_func( array( $this, 'column_' . $column_name ), $item ); // phpcs:ignore WordPress.Security.EscapeOutput
521 echo '</td>';
522 } else {
523 echo '<td></td>';
524 }
525 }
526 ?>
527 </tr>
528 <?php
529 }
530
531 /**
532 * Column Actions.
533 *
534 * @param mixed $item Item to go in column.
535 *
536 * @return string Action content.
537 */
538 public function column_actions( $item ) {
539
540 $actions = array(
541 'edit' => sprintf( '<a class="item" href="admin.php?page=ManageBackups&id=%s"><i class="edit outline icon"></i> ' . esc_html__( 'Edit', 'mainwp' ) . '</a>', $item->id ),
542 'delete' => sprintf( '<a class="submitdelete item" href="#" task_id="%s" onClick="return managebackups_remove(this);"><i class="trash alternate outline icon"></i> ' . esc_html__( 'Delete', 'mainwp' ) . '</a>', $item->id ),
543 );
544
545 if ( ! \mainwp_current_user_can( 'dashboard', 'edit_backup_tasks' ) ) {
546 unset( $actions['edit'] );
547 }
548
549 if ( ! \mainwp_current_user_can( 'dashboard', 'delete_backup_tasks' ) ) {
550 unset( $actions['delete'] );
551 }
552
553 if ( 1 === (int) $item->paused ) {
554 if ( \mainwp_current_user_can( 'dashboard', 'pause_resume_backup_tasks' ) ) {
555 $actions['resume'] = sprintf( '<a href="#" class="item" task_id="%s" onClick="return managebackups_resume(this)"><i class="play icon"></i> ' . esc_html__( 'Resume', 'mainwp' ) . '</a>', $item->id );
556 }
557 } elseif ( \mainwp_current_user_can( 'dashboard', 'pause_resume_backup_tasks' ) ) {
558 $actions['pause'] = sprintf( '<a href="#" class="item" task_id="%s" onClick="return managebackups_pause(this)"><i class="pause icon"></i> ' . esc_html__( 'Pause', 'mainwp' ) . '</a>', $item->id );
559 }
560
561 $out = '<div class="ui right pointing dropdown" style="z-index:999">
562 <i class="ellipsis vertical icon"></i>
563 <div class="menu">
564 <div class="header">' . esc_html__( 'Backup Actions', 'mainwp' ) . '</div>
565 <div class="divider"></div>';
566 foreach ( $actions as $link ) {
567 $out .= $link;
568 }
569 $out .= '</div>
570 </div>';
571
572 return $out;
573 }
574
575 /**
576 * Column Task Name.
577 *
578 * @param mixed $item Item to go in column.
579 *
580 * @return string Action content.
581 */
582 public function column_task_name( $item ) {
583 return stripslashes( $item->name );
584 }
585
586 /**
587 * Column Type.
588 *
589 * @param mixed $item Item to go in column.
590 *
591 * @return string Action content.
592 */
593 public function column_type( $item ) {
594 return 'db' === $item->type ? esc_html__( 'DATABASE BACKUP', 'mainwp' ) : esc_html__( 'FULL BACKUP', 'mainwp' );
595 }
596
597 /**
598 * Column Schdule.
599 *
600 * @param mixed $item Item to go in column.
601 *
602 * @return string Action content.
603 */
604 public function column_schedule( $item ) {
605 return strtoupper( $item->schedule );
606 }
607
608 /**
609 * Column Destination.
610 *
611 * @param mixed $item Item to go in column.
612 *
613 * @return string Action content.
614 */
615 public function column_destination( $item ) {
616 $extraOutput = apply_filters( 'mainwp_backuptask_column_destination', '', $item->id );
617 if ( '' !== $extraOutput ) {
618 return trim( $extraOutput, '<br />' );
619 }
620
621 return esc_html__( 'SERVER', 'mainwp' );
622 }
623
624 /**
625 * Column Websites.
626 *
627 * @param mixed $item Item to go in column.
628 */
629 public function column_websites( $item ) {
630 if ( 0 === count( $item->the_sites ) ) {
631 echo( '<span style="color: red; font-weight: bold; ">' . count( $item->the_sites ) . '</span>' );
632 } else {
633 echo count( $item->the_sites );
634 }
635 }
636
637 /**
638 * Column Details.
639 *
640 * @param mixed $item Item to go in column.
641 *
642 * @return string Action content.
643 *
644 * @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp()
645 * @uses \MainWP\Dashboard\MainWP_Utility::get_timestamp()
646 */
647 public function column_details( $item ) {
648 $output = '<strong>' . esc_html__( 'LAST RUN MANUALLY: ', 'mainwp' ) . '</strong>' . ( empty( $item->last_run_manually ) ? '-' : MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( $item->last_run_manually ) ) ) . '<br />';
649 $output .= '<strong>' . esc_html__( 'LAST RUN: ', 'mainwp' ) . '</strong>' . ( empty( $item->last_run ) ? '-' : MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( $item->last_run ) ) ) . '<br />';
650 $output .= '<strong>' . esc_html__( 'LAST COMPLETED: ', 'mainwp' ) . '</strong>' . ( empty( $item->completed ) ? '-' : MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( $item->completed ) ) ) . '<br />';
651 $output .= '<strong>' . esc_html__( 'NEXT RUN: ', 'mainwp' ) . '</strong>' . ( empty( $item->last_run ) ? esc_html__( 'Any minute', 'mainwp' ) : MainWP_Utility::format_timestamp( ( 'daily' === $item->schedule ? ( 60 * 60 * 24 ) : ( 'weekly' === $item->schedule ? ( 60 * 60 * 24 * 7 ) : ( 60 * 60 * 24 * 30 ) ) ) + MainWP_Utility::get_timestamp( $item->last_run ) ) );
652 $output .= '<strong>';
653 if ( ! empty( $item->last_run ) && $item->completed < $item->last_run ) {
654 $output .= esc_html__( '<br />CURRENTLY RUNNING: ', 'mainwp' ) . '</strong>';
655 $completed_sites = $item->completed_sites;
656 if ( '' !== $completed_sites ) {
657 $completed_sites = json_decode( $completed_sites, 1 );
658 }
659 if ( ! is_array( $completed_sites ) ) {
660 $completed_sites = array();
661 }
662 $output .= count( $completed_sites ) . '/' . count( $item->the_sites );
663 }
664 return $output;
665 }
666
667 /**
668 * Column Trigger.
669 *
670 * @param mixed $item Item to go in column.
671 *
672 * @return string Action content.
673 */
674 public function column_trigger( $item ) {
675 return '<span class="backup_run_loading"><img src="' . MAINWP_PLUGIN_URL . 'assets/images/loader.gif" /></span>&nbsp;<a href="#" class="backup_run_now" task_id="' . $item->id . '" task_type="' . $item->type . '">' . esc_html__( 'Run now', 'mainwp' ) . '</a>';
676 }
677
678 /**
679 * Render edit.
680 *
681 * @param mixed $task Task to edit.
682 */
683 public static function render_edit( $task ) {
684 static::render_header( 'ManageBackupsEdit' );
685 ?>
686 <div class="ui alt segment">
687 <div class="ui message" id="mainwp-message-zone" style="display:none"></div>
688 <form method="POST" action="" class="ui form">
689 <?php MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' ); ?>
690 <input type="hidden" name="mainwp_managebackups_edit_id" id="mainwp_managebackups_edit_id" value="<?php echo esc_attr( $task->id ); ?>"/>
691 <?php
692 static::render_new_edit( $task );
693 ?>
694 </form>
695 </div>
696 <?php
697 static::render_footer( 'ManageBackupsEdit' );
698 }
699
700 /** Render New Task Form. */
701 public static function render_new() {
702 if ( ! \mainwp_current_user_can( 'dashboard', 'add_backup_tasks' ) ) {
703 \mainwp_do_not_have_permissions( esc_html__( 'add backup tasks', 'mainwp' ) );
704 return;
705 }
706 static::render_header( 'AddNew' );
707 ?>
708 <div class="ui alt segment">
709 <div class="ui message" id="mainwp-message-zone" style="display:none"></div>
710 <form method="POST" action="" id="mainwp-backup-task-form" class="ui form">
711 <?php MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' ); ?>
712 <?php static::render_new_edit( null ); ?>
713 </form>
714 </div>
715 <?php
716 static::render_footer( 'AddNew' );
717 }
718
719 /**
720 * Render New edit Form.
721 *
722 * @param mixed $task Task to edit.
723 */
724 public static function render_new_edit( $task ) {
725 $selected_websites = array();
726 $selected_groups = array();
727 if ( ! empty( $task ) ) {
728 if ( '' !== $task->sites ) {
729 $selected_websites = explode( ',', $task->sites );
730 }
731 if ( '' !== $task->groups ) {
732 $selected_groups = explode( ',', $task->groups );
733 }
734 }
735 ?>
736
737 <div class="mainwp-main-content">
738 <?php static::render_schedule_backup(); ?>
739 </div>
740 <div class="mainwp-side-content mainwp-no-padding">
741 <div class="mainwp-select-sites">
742 <div class="ui header"><?php esc_html_e( 'Select Sites', 'mainwp' ); ?></div>
743 <?php
744 $sel_params = array(
745 'selected_sites' => $selected_websites,
746 'selected_groups' => $selected_groups,
747 'enable_offline_sites' => true,
748 );
749 MainWP_UI_Select_Sites::select_sites_box( $sel_params );
750 ?>
751 </div>
752 <div class="ui divider"></div>
753 <div class="mainwp-search-submit">
754 <?php if ( ! empty( $task ) ) : ?>
755 <input type="hidden" id="backup_task_id" value="<?php echo esc_attr( $task->id ); ?>"/>
756 <input type="button" name="mainwp_managebackups_update" id="mainwp_managebackups_update" class="ui big green fluid button" value="<?php esc_attr_e( 'Update Schedule Backup', 'mainwp' ); ?>"/>
757 <?php else : ?>
758 <input type="button" name="mainwp_managebackups_add" id="mainwp_managebackups_add" class="ui big green fluid button" value="<?php esc_attr_e( 'Schedule Backup', 'mainwp' ); ?>"/>
759 <?php endif; ?>
760 </div>
761 </div>
762 <div class="ui hidden clearing divider"></div>
763 <?php
764 }
765
766 /**
767 * Render Scheduled Backup.
768 *
769 * @return void
770 * @uses \MainWP\Dashboard\MainWP_DB_Backup::get_backup_task_by_id()
771 * @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::can_edit_backuptask()
772 * @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::validate_backup_tasks()
773 */
774 public static function render_schedule_backup() { //phpcs:ignore -- NOSONAR - complex.
775 $backupTask = null;
776 $backupTaskId = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
777
778 if ( ! empty( $backupTaskId ) ) {
779 if ( ! \mainwp_current_user_can( 'dashboard', 'edit_backup_tasks' ) ) {
780 \mainwp_do_not_have_permissions( esc_html__( 'edit backup tasks', 'mainwp' ) );
781 return;
782 }
783
784 $backupTask = MainWP_DB_Backup::instance()->get_backup_task_by_id( $backupTaskId );
785 if ( ! MainWP_Manage_Backups_Handler::can_edit_backuptask( $backupTask ) ) {
786 $backupTask = null;
787 }
788
789 if ( ! empty( $backupTask ) ) {
790 if ( ! MainWP_Manage_Backups_Handler::validate_backup_tasks( array( $backupTask ) ) ) {
791 $backupTask = MainWP_DB_Backup::instance()->get_backup_task_by_id( $backupTaskId );
792 }
793 }
794 }
795 $task = $backupTask;
796
797 $globalArchiveFormat = get_option( 'mainwp_archiveFormat' );
798 if ( false === $globalArchiveFormat ) {
799 $globalArchiveFormat = 'tar.gz';
800 }
801 if ( 'zip' === $globalArchiveFormat ) {
802 $globalArchiveFormatText = 'Zip';
803 } elseif ( 'tar' === $globalArchiveFormat ) {
804 $globalArchiveFormatText = 'Tar';
805 } elseif ( 'tar.gz' === $globalArchiveFormat ) {
806 $globalArchiveFormatText = 'Tar GZip';
807 } elseif ( 'tar.bz2' === $globalArchiveFormat ) {
808 $globalArchiveFormatText = 'Tar BZip2';
809 }
810
811 $archiveFormat = isset( $task ) ? $task->archiveFormat : 'site';
812 $useGlobal = ( 'global' === $archiveFormat );
813 $useSite = ( empty( $archiveFormat ) || 'site' === $archiveFormat );
814
815 static::render_task_details( $task, $globalArchiveFormatText, $archiveFormat, $useGlobal, $useSite );
816 }
817
818 /**
819 * Render Task Details.
820 *
821 * @param mixed $task Task to perform.
822 * @param mixed $globalArchiveFormatText Global Archived Format Text.
823 * @param mixed $archiveFormat Archive Format.
824 * @param mixed $useGlobal Use Global.
825 * @param mixed $useSite Use Site.
826 */
827 public static function render_task_details( $task, $globalArchiveFormatText, $archiveFormat, $useGlobal, $useSite ) { // phpcs:ignore -- NOSONAR - complex.
828 ?>
829
830 <div class="ui divider hidden"></div>
831 <div class="ui message" id="mainwp-message-zone" style="display:none"></div>
832 <h3 class="header"><?php esc_html_e( 'Backup Details', 'mainwp' ); ?></h3>
833 <div class="ui grid field">
834 <label class="six wide column middle aligned"><?php esc_html_e( 'Backup task name', 'mainwp' ); ?></label>
835 <div class="ten wide column">
836 <input type="text" id="mainwp_managebackups_add_name" name="mainwp_managebackups_add_name" value="<?php echo isset( $task ) ? esc_html( stripslashes( $task->name ) ) : ''; ?>"/>
837 </div>
838 </div>
839 <div class="ui grid field">
840 <label class="six wide column middle aligned"><?php esc_html_e( 'Backup file name', 'mainwp' ); ?></label>
841 <div class="ten wide column">
842 <input type="text" id="backup_filename" name="backup_filename" value="<?php echo isset( $task ) ? esc_html( stripslashes( $task->filename ) ) : ''; ?>"/>
843 </div>
844 </div>
845 <div class="ui grid field">
846 <label class="six wide column middle aligned"><?php esc_html_e( 'Backup type', 'mainwp' ); ?></label>
847 <div class="ten wide column">
848 <select name="mainwp-backup-type" id="mainwp-backup-type" class="ui dropdown">
849 <option value="full" <?php echo ! isset( $task ) || 'full' === $task->type ? 'selected' : ''; ?>><?php esc_html_e( 'Full Backup', 'mainwp' ); ?></option>
850 <option value="db" <?php echo isset( $task ) && 'db' === $task->type ? 'selected' : ''; ?>><?php esc_html_e( 'Database Backup', 'mainwp' ); ?></option>
851 </select>
852 </div>
853 </div>
854 <div class="ui grid field">
855 <label class="six wide column middle aligned"><?php esc_html_e( 'Schedule', 'mainwp' ); ?></label>
856 <div class="ten wide column">
857 <select name="mainwp-backup-task-schedule" id="mainwp-backup-task-schedule" class="ui dropdown">
858 <option value="daily" <?php echo( ! isset( $task ) || 'daily' === $task->schedule ? 'selected' : '' ); ?>><?php esc_html_e( 'Daily', 'mainwp' ); ?></option>
859 <option value="weekly" <?php echo( ! isset( $task ) || 'weekly' === $task->schedule ? 'selected' : '' ); ?>><?php esc_html_e( 'Weekly', 'mainwp' ); ?></option>
860 <option value="monthly" <?php echo( ! isset( $task ) || 'monthly' === $task->schedule ? 'selected' : '' ); ?>><?php esc_html_e( 'Monthly', 'mainwp' ); ?></option>
861 </select>
862 </div>
863 </div>
864 <div class="ui grid field">
865 <label class="six wide column middle aligned"><?php esc_html_e( 'Archive type', 'mainwp' ); ?></label>
866 <div class="ten wide column">
867 <select name="mainwp_archiveFormat" id="mainwp_archiveFormat" class="ui dropdown">
868 <option value="site"
869 <?php
870 if ( $useSite ) :
871 ?>
872 selected<?php endif; ?>><?php esc_html_e( 'Site specific setting', 'mainwp' ); ?></option>
873 <option value="global"
874 <?php
875 if ( $useGlobal ) :
876 ?>
877 selected<?php endif; ?>><?php esc_html_e( 'Global setting', 'mainwp' ); ?> (<?php echo esc_html( $globalArchiveFormatText ); ?>)</option>
878 <option value="zip"
879 <?php
880 if ( 'zip' === $archiveFormat ) :
881 ?>
882 selected<?php endif; ?>><?php esc_html_e( 'Zip', 'mainwp' ); ?></option>
883 <option value="tar"
884 <?php
885 if ( 'tar' === $archiveFormat ) :
886 ?>
887 selected<?php endif; ?>><?php esc_html_e( 'Tar', 'mainwp' ); ?></option>
888 <option value="tar.gz"
889 <?php
890 if ( 'tar.gz' === $archiveFormat ) :
891 ?>
892 selected<?php endif; ?>><?php esc_html_e( 'Tar GZip', 'mainwp' ); ?></option>
893 <option value="tar.bz2"
894 <?php
895 if ( 'tar.bz2' === $archiveFormat ) :
896 ?>
897 selected<?php endif; ?>><?php esc_html_e( 'Tar BZip2', 'mainwp' ); ?></option>
898 </select>
899 </div>
900 </div>
901 <?php
902 $style = isset( $task ) && 'db' === $task->type ? 'style="display: none;"' : '';
903 ?>
904 <div class="mainwp-backup-full-exclude" <?php echo $style; //phpcs:ignore -- ok. ?>>
905 <h3 class="header"><?php esc_html_e( 'Backup Excludes', 'mainwp' ); ?></h3>
906 <div class="ui grid field">
907 <label class="six wide column middle aligned"><?php esc_html_e( 'Known backup locations', 'mainwp' ); ?></label>
908 <div class="ten wide column ui toggle checkbox">
909 <input type="checkbox" id="mainwp-known-backup-locations" <?php echo( ! isset( $task ) || 1 === (int) $task->excludebackup ? 'checked' : '' ); ?>>
910 </div>
911 </div>
912 <div class="ui grid field">
913 <label class="six wide column middle aligned"></label>
914 <div class="ten wide column ui toggle checkbox">
915 <textarea id="mainwp-kbl-content" disabled></textarea><br />
916 <em><?php esc_html_e( 'This adds known backup locations of popular WordPress backup plugins to the exclude list. Old backups can take up a lot of space and can cause your current MainWP backup to timeout.', 'mainwp' ); ?></em>
917 </div>
918 </div>
919 <div class="ui grid field">
920 <label class="six wide column middle aligned"><?php esc_html_e( 'Known cache locations', 'mainwp' ); ?></label>
921 <div class="ten wide column ui toggle checkbox">
922 <input type="checkbox" id="mainwp-known-cache-locations" <?php echo( ! isset( $task ) || 1 === (int) $task->excludecache ? 'checked' : '' ); ?>><br />
923 </div>
924 </div>
925 <div class="ui grid field">
926 <label class="six wide column middle aligned"></label>
927 <div class="ten wide column ui toggle checkbox">
928 <textarea id="mainwp-kcl-content" disabled></textarea><br />
929 <em><?php esc_html_e( 'This adds known cache locations of popular WordPress cache plugins to the exclude list. A cache can be massive with thousands of files and can cause your current MainWP backup to timeout. Your cache will be rebuilt by your caching plugin when the backup is restored.', 'mainwp' ); ?></em>
930 </div>
931 </div>
932 <div class="ui grid field">
933 <label class="six wide column middle aligned"><?php esc_html_e( 'Non-WordPress folders', 'mainwp' ); ?></label>
934 <div class="ten wide column ui toggle checkbox">
935 <input type="checkbox" id="mainwp-non-wordpress-folders" <?php echo( ! isset( $task ) || 1 === (int) $task->excludenonwp ? 'checked' : '' ); ?>><br />
936 </div>
937 </div>
938 <div class="ui grid field">
939 <label class="six wide column middle aligned"></label>
940 <div class="ten wide column ui toggle checkbox">
941 <textarea id="mainwp-nwl-content" disabled></textarea><br />
942 <em><?php esc_html_e( 'This adds folders that are not part of the WordPress core (wp-admin, wp-content and wp-include) to the exclude list. Non-WordPress folders can contain a large amount of data or may be a sub-domain or add-on domain that should be backed up individually and not with this backup.', 'mainwp' ); ?></em>
943 </div>
944 </div>
945 <div class="ui grid field">
946 <label class="six wide column middle aligned"><?php esc_html_e( 'ZIP archives', 'mainwp' ); ?></label>
947 <div class="ten wide column ui toggle checkbox">
948 <input type="checkbox" id="mainwp-zip-archives" <?php echo( ! isset( $task ) || 1 === (int) $task->excludezip ? 'checked' : '' ); ?>>
949 </div>
950 </div>
951 <div class="ui grid field">
952 <label class="six wide column middle aligned"><?php esc_html_e( 'Custom excludes', 'mainwp' ); ?></label>
953 <div class="ten wide column ui toggle checkbox">
954 <textarea id="excluded_folders_list">
955 <?php
956 $excluded = ( isset( $task ) ? $task->exclude : '' );
957 if ( '' !== $excluded ) {
958 $excluded = explode( ',', $excluded );
959 $excluded = is_array( $excluded ) ? array_map( 'sanitize_text_field', $excluded ) : array();
960 echo implode( "/\n", $excluded ) . "/\n"; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
961 }
962 ?>
963 </textarea>
964 </div>
965 </div>
966 </div>
967 <?php
968 }
969
970
971 /**
972 * Method render_settings()
973 *
974 * Render backup settings.
975 */
976 public static function render_settings() { //phpcs:ignore -- NOSONAR - complex.
977
978 $backupsOnServer = get_option( 'mainwp_backupsOnServer' );
979 $backupOnExternalSources = get_option( 'mainwp_backupOnExternalSources' );
980 $archiveFormat = get_option( 'mainwp_archiveFormat' );
981 $maximumFileDescriptors = get_option( 'mainwp_maximumFileDescriptors' );
982 $maximumFileDescriptorsAuto = get_option( 'mainwp_maximumFileDescriptorsAuto' );
983 $maximumFileDescriptorsAuto = ( 1 === $maximumFileDescriptorsAuto || false === $maximumFileDescriptorsAuto );
984
985 $notificationOnBackupFail = get_option( 'mainwp_notificationOnBackupFail' );
986 $notificationOnBackupStart = get_option( 'mainwp_notificationOnBackupStart' );
987 $chunkedBackupTasks = get_option( 'mainwp_chunkedBackupTasks' );
988 $enableLegacyBackupFeature = get_option( 'mainwp_enableLegacyBackupFeature' );
989
990 $loadFilesBeforeZip = get_option( 'mainwp_options_loadFilesBeforeZip' );
991 $loadFilesBeforeZip = ( 1 === $loadFilesBeforeZip || false === $loadFilesBeforeZip );
992
993 $primaryBackup = get_option( 'mainwp_primaryBackup' );
994 $primary_methods = array();
995 $primary_methods = apply_filters_deprecated( 'mainwp-getprimarybackup-methods', array( $primary_methods ), '4.0.7.2', 'mainwp_getprimarybackup_methods' ); // @deprecated Use 'mainwp_getprimarybackup_methods' instead. NOSONAR - not IP.
996 $primaryBackupMethods = apply_filters( 'mainwp_getprimarybackup_methods', $primary_methods );
997
998 if ( ! is_array( $primaryBackupMethods ) ) {
999 $primaryBackupMethods = array();
1000 }
1001
1002 /**
1003 * MainWP use external primary backup method.
1004 *
1005 * @global string
1006 */
1007 global $mainwpUseExternalPrimaryBackupsMethod;
1008
1009 $hidden_elems = false;
1010 if ( ! $enableLegacyBackupFeature || ( ! empty( $primaryBackup ) && $primaryBackup === $mainwpUseExternalPrimaryBackupsMethod ) ) {
1011 $hidden_elems = true;
1012 }
1013 ?>
1014 <h3 class="ui dividing header">
1015 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-backups' ); ?>
1016 <?php esc_html_e( 'Backup Settings', 'mainwp' ); ?>
1017 <div class="sub header"><?php /* translators: 1: opening anchor tag, 2: closing anchor tag */ printf( esc_html__( 'MainWP is actively moving away from further development of the native backups feature. The best long-term solution would be one of the %1$sBackup Extensions%2$s.', 'mainwp' ), '<a href="https://mainwp.com/extensions/extension-category/backups/" target="_blank" ?>', '</a>' ); // NOSONAR - noopener - open safe. ?></div>
1018 </h3>
1019 <?php if ( ! empty( $primaryBackupMethods ) ) : ?>
1020 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-backups">
1021 <label class="six wide column middle aligned"><?php esc_html_e( 'Select primary backup system', 'mainwp' ); ?></label>
1022 <div class="ten wide column">
1023 <select class="ui dropdown" name="mainwp_primaryBackup" id="mainwp_primaryBackup">
1024 <?php if ( $enableLegacyBackupFeature || empty( $primaryBackup ) ) { ?>
1025 <option value="" ><?php esc_html_e( 'Native backups', 'mainwp' ); ?></option>
1026 <?php } ?>
1027 <?php
1028 foreach ( $primaryBackupMethods as $method ) {
1029 echo '<option value="' . esc_attr( $method['value'] ) . '" ' . ( ( $primaryBackup === $method['value'] ) ? 'selected' : '' ) . '>' . esc_html( $method['title'] ) . '</option>';
1030 }
1031 ?>
1032
1033 </select>
1034 </div>
1035 </div>
1036 <?php endif; ?>
1037
1038 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-backups">
1039 <label class="six wide column middle aligned">
1040 <?php
1041 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_enableLegacyBackupFeature', (int) $enableLegacyBackupFeature );
1042 esc_html_e( 'Enable legacy backup feature', 'mainwp' );
1043 ?>
1044 </label>
1045 <div class="ten wide column ui toggle checkbox">
1046 <input type="checkbox" class="settings-field-value-change-handler" name="mainwp_options_enableLegacyBackupFeature" id="mainwp_options_enableLegacyBackupFeature" <?php echo 0 === (int) $enableLegacyBackupFeature ? '' : 'checked="true"'; ?>/>
1047 </div>
1048 </div>
1049 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-backups" <?php echo $hidden_elems ? 'style="display:none"' : ''; ?> default-indi-value="1">
1050 <label class="six wide column middle aligned">
1051 <?php
1052 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_backupsOnServer', (int) $backupsOnServer );
1053 esc_html_e( 'Backups on server', 'mainwp' );
1054 ?>
1055 </label>
1056 <div class="ten wide column">
1057 <input type="text" class="settings-field-value-change-handler" name="mainwp_options_backupOnServer" value="<?php echo false === $backupsOnServer ? 1 : intval( $backupsOnServer ); ?>"/>
1058 </div>
1059 </div>
1060
1061 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-backups" <?php echo $hidden_elems ? 'style="display:none"' : ''; ?> default-indi-value="1">
1062 <label class="six wide column middle aligned">
1063 <?php
1064 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_backupOnExternalSources', (int) $backupOnExternalSources );
1065 esc_html_e( 'Backups on remote storage', 'mainwp' );
1066 ?>
1067 </label>
1068 <div class="ten wide column">
1069 <span data-tooltip="<?php esc_attr_e( 'The number of backups to keep on your external sources. This does not affect backups on the server. 0 sets unlimited.', 'mainwp' ); ?>" data-inverted=""><input type="text" class="settings-field-value-change-handler" name="mainwp_options_backupOnExternalSources" value="<?php echo false === $backupOnExternalSources ? 1 : intval( $backupOnExternalSources ); ?>"/>
1070 </div>
1071 </div>
1072
1073 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-backups" <?php echo $hidden_elems ? 'style="display:none"' : ''; ?> default-indi-value="tar.gz">
1074 <label class="six wide column middle aligned">
1075 <?php
1076 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_archiveFormat', $archiveFormat );
1077 esc_html_e( 'Archive format', 'mainwp' );
1078 ?>
1079 </label>
1080 <div class="ten wide column">
1081 <select class="ui dropdown settings-field-value-change-handler" name="mainwp_archiveFormat" id="mainwp_archiveFormat">
1082 <option value="zip"
1083 <?php
1084 if ( 'zip' === $archiveFormat ) :
1085 ?>
1086 selected<?php endif; ?>>Zip</option>
1087 <option value="tar"
1088 <?php
1089 if ( 'tar' === $archiveFormat ) :
1090 ?>
1091 selected<?php endif; ?>>Tar</option>
1092 <option value="tar.gz"
1093 <?php
1094 if ( ( false === $archiveFormat ) || ( 'tar.gz' === $archiveFormat ) ) :
1095 ?>
1096 selected<?php endif; ?>>Tar GZip</option>
1097 <option value="tar.bz2"
1098 <?php
1099 if ( 'tar.bz2' === $archiveFormat ) :
1100 ?>
1101 selected<?php endif; ?>>Tar BZip2</option>
1102 </select>
1103 </div>
1104 </div>
1105
1106 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-backups" <?php echo $hidden_elems ? 'style="display:none"' : ''; ?> <?php
1107 if ( empty( $hidden_elems ) && 'zip' !== $archiveFormat ) {
1108 echo 'style="display: none;"';
1109 }
1110 ?>
1111 default-indi-value="1"
1112 >
1113 <label class="six wide column middle aligned">
1114 <?php
1115 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_maximumFileDescriptorsAuto', (int) $maximumFileDescriptorsAuto );
1116 esc_html_e( 'Auto detect maximum file descriptors on child sites', 'mainwp' );
1117 ?>
1118 </label>
1119 <div class="ten wide column ui toggle checkbox">
1120 <input type="checkbox" class="settings-field-value-change-handler" name="mainwp_maximumFileDescriptorsAuto" id="mainwp_maximumFileDescriptorsAuto" value="1" <?php echo $maximumFileDescriptorsAuto ? 'checked="checked"' : ''; ?>/>
1121 </div>
1122 </div>
1123
1124 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-backups" <?php echo $hidden_elems ? 'style="display:none"' : ''; ?> <?php
1125 if ( empty( $hidden_elems ) && 'zip' !== $archiveFormat ) {
1126 echo 'style="display: none;"';
1127 }
1128 ?>
1129 default-indi-value="155" >
1130 <label class="six wide column middle aligned">
1131 <?php
1132 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_maximumFileDescriptors', (int) $maximumFileDescriptors );
1133 esc_html_e( 'Maximum file descriptors fallback value', 'mainwp' );
1134 ?>
1135 </label>
1136 <div class="ten wide column">
1137 <input type="text" class="settings-field-value-change-handler" name="mainwp_options_maximumFileDescriptors" id="mainwp_options_maximumFileDescriptors" value="<?php echo false === $maximumFileDescriptors ? 150 : intval( $maximumFileDescriptors ); ?>"/>
1138 </div>
1139 </div>
1140
1141 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-backups" default-indi-value="1" <?php echo $hidden_elems ? 'style="display:none"' : ''; ?> <?php
1142 if ( empty( $hidden_elems ) && 'zip' !== $archiveFormat ) {
1143 echo 'style="display: none;"';
1144 }
1145 ?>
1146 >
1147 <label class="six wide column middle aligned">
1148 <?php
1149 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_options_loadFilesBeforeZip', (int) $loadFilesBeforeZip );
1150 esc_html_e( 'Load files in memory before zipping', 'mainwp' );
1151 ?>
1152 </label>
1153 <div class="ten wide column ui toggle checkbox">
1154 <input type="checkbox" class="settings-field-value-change-handler" inverted-value="1" name="mainwp_options_loadFilesBeforeZip" id="mainwp_options_loadFilesBeforeZip" value="1" <?php echo $loadFilesBeforeZip ? 'checked="checked"' : ''; ?>/>
1155 </div>
1156 </div>
1157
1158 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-backups" <?php echo $hidden_elems ? 'style="display:none"' : ''; ?> default-indi-value="1">
1159 <label class="six wide column middle aligned">
1160 <?php
1161 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_notificationOnBackupFail', (int) $notificationOnBackupFail );
1162 esc_html_e( 'Send email when backup fails', 'mainwp' );
1163 ?>
1164 </label>
1165 <div class="ten wide column ui toggle checkbox">
1166 <input type="checkbox" class="settings-field-value-change-handler" inverted-value="1" name="mainwp_options_notificationOnBackupFail" id="mainwp_options_notificationOnBackupFail" value="1" <?php echo $notificationOnBackupFail ? 'checked="checked"' : ''; ?>/>
1167 </div>
1168 </div>
1169 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-backups" <?php echo $hidden_elems ? 'style="display:none"' : ''; ?> default-indi-value="1">
1170 <label class="six wide column middle aligned">
1171 <?php
1172 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_notificationOnBackupStart', (int) $notificationOnBackupStart );
1173 esc_html_e( 'Send email when backup starts', 'mainwp' );
1174 ?>
1175 </label>
1176 <div class="ten wide column ui toggle checkbox">
1177 <input type="checkbox" class="settings-field-value-change-handler" inverted-value="1" name="mainwp_options_notificationOnBackupStart" id="mainwp_options_notificationOnBackupStart" value="1" <?php echo $notificationOnBackupStart ? 'checked="checked"' : ''; ?>/>
1178 </div>
1179 </div>
1180
1181 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-backups" <?php echo $hidden_elems ? 'style="display:none"' : ''; ?> default-indi-value="1">
1182 <label class="six wide column middle aligned">
1183 <?php
1184 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_chunkedBackupTasks', (int) $chunkedBackupTasks );
1185 esc_html_e( 'Execute backup tasks in chunks', 'mainwp' );
1186 ?>
1187 </label>
1188 <div class="ten wide column ui toggle checkbox">
1189 <input type="checkbox" class="settings-field-value-change-handler" inverted-value="1" name="mainwp_options_chunkedBackupTasks" id="mainwp_options_chunkedBackupTasks" value="1" <?php echo $chunkedBackupTasks ? 'checked="checked"' : ''; ?>/>
1190 </div>
1191 </div>
1192 <?php
1193 }
1194
1195 /**
1196 * Method render_individual_settings()
1197 *
1198 * Render backup settings.
1199 *
1200 * @param mixed $website Website data.
1201 */
1202 public static function render_individual_settings( $website ) { //phpcs:ignore -- NOSONAR - complex.
1203
1204 $primaryBackup = $website && ! empty( $website->primary_backup_method ) ? $website->primary_backup_method : 'global';
1205 $primary_methods = array();
1206 $primary_methods = apply_filters_deprecated( 'mainwp-getprimarybackup-methods', array( $primary_methods ), '4.0.7.2', 'mainwp_getprimarybackup_methods' ); // @deprecated Use 'mainwp_getprimarybackup_methods' instead. NOSONAR - not IP.
1207 $primaryBackupMethods = apply_filters( 'mainwp_getprimarybackup_methods', $primary_methods );
1208
1209 if ( ! is_array( $primaryBackupMethods ) ) {
1210 $primaryBackupMethods = array();
1211 }
1212
1213 ?>
1214 <div class="ui basic accordion mainwp-blank-accordion mainwp-sidebar-accordion" id="mainwp-edit-site-backup-settings-accordion">
1215 <h2 class="ui dividing header title">
1216 <i class="right dropdown icon"></i>
1217 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-backups' ); ?>
1218 <?php esc_html_e( 'Backup Settings', 'mainwp' ); ?>
1219 <div class="sub header"><?php /* translators: 1: opening anchor tag, 2: closing anchor tag */ printf( esc_html__( 'MainWP is actively moving away from further development of the native backups feature. The best long-term solution would be one of the %1$sBackup Extensions%2$s.', 'mainwp' ), '<a href="https://mainwp.com/extensions/extension-category/backups/" target="_blank" ?>', '</a>' ); // NOSONAR - noopener - open safe. ?></div>
1220 </h2>
1221 <div class="content">
1222 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-wrapper settings-field-indicator-backups">
1223 <label class="six wide column middle aligned"><?php esc_html_e( 'Select primary backup system', 'mainwp' ); ?></label>
1224 <div class="ten wide column">
1225 <select class="ui dropdown" name="mainwp_primaryBackup" id="mainwp_primaryBackup">
1226 <?php
1227 echo '<option value="global" ' . ( 'global' === $primaryBackup ? 'selected' : '' ) . '>' . esc_html__( 'Use global setting', 'mainwp' ) . '</option>';
1228 foreach ( $primaryBackupMethods as $method ) {
1229 echo '<option value="' . esc_attr( $method['value'] ) . '" ' . ( ( $primaryBackup === $method['value'] ) ? 'selected' : '' ) . '>' . esc_html( $method['title'] ) . '</option>';
1230 }
1231 ?>
1232
1233 </select>
1234 </div>
1235 </div>
1236 </div>
1237 </div>
1238 <?php
1239 }
1240 }
1241