PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.3 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 All 156 releases
mainwp / class / class-mainwp-manage-sites-backup-view.php

class-mainwp-manage-sites-backup-view.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 6.2.1, at class/class-mainwp-manage-sites-backup-view.php

294 lines 16.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This file manages the view for the MainWP Manage Sites Backup 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_Sites_Backup_View
17 *
18 * @package MainWP\Dashboard
19 */
20 class MainWP_Manage_Sites_Backup_View { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
21
22 /**
23 * Shows the available backups taken.
24 *
25 * @param object $website Child Site info.
26 * @param array $fullBackups Full Backups Array.
27 * @param array $dbBackups DB Backups Array.
28 *
29 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_mainwp_dir()
30 * @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp()
31 * @uses \MainWP\Dashboard\MainWP_Utility::get_timestamp()
32 */
33 public static function show_backups( &$website, $fullBackups, $dbBackups ) {
34 $mwpDir = MainWP_System_Utility::get_mainwp_dir();
35 $mwpDir = $mwpDir[0];
36 // phpcs:disable WordPress.Security.EscapeOutput
37 $output = '';
38 foreach ( $fullBackups as $fullBackup ) {
39 $downloadLink = admin_url( '?sig=' . MainWP_System_Utility::get_download_sig( $fullBackup ) . '&mwpdl=' . rawurlencode( str_replace( $mwpDir, '', $fullBackup ) ) );
40 $output .= '<div class="ui grid field">';
41 $output .= '<label class="six wide column middle aligned">' . MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( filemtime( $fullBackup ) ) ) . ' - ' . MainWP_Utility::human_filesize( filesize( $fullBackup ) ) . '</label>';
42 $output .= '<div class="ten wide column ui toggle checkbox"><a title="' . basename( $fullBackup ) . '" href="' . esc_url( $downloadLink ) . '" class="button">Download</a>';
43 $output .= '<a href="admin.php?page=SiteRestore&websiteid=' . intval( $website->id ) . '&f=' . base64_encode( $downloadLink ) . '&size=' . filesize( $fullBackup ) . '&_opennonce=' . wp_create_nonce( 'mainwp-admin-nonce' ) . '" class="mainwp-upgrade-button button" target="_blank" title="' . basename( $fullBackup ) . '">Restore</a>'; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode() used for http encoding compatible.
44 $output .= '</div>';
45 $output .= '</div>';
46 }
47
48 ?>
49 <h3 class="ui dividing header"><?php esc_html_e( 'Backup Details', 'mainwp' ); ?></h3>
50 <h3 class="header"><?php echo '' === $output ? esc_html__( 'No full backup has been taken yet', 'mainwp' ) : esc_html__( 'Last backups from your files', 'mainwp' ); // phpcs:ignore WordPress.Security.EscapeOutput ?></h3>
51 <?php
52 echo $output;
53
54 $output = '';
55 foreach ( $dbBackups as $dbBackup ) {
56 $downloadLink = admin_url( '?sig=' . MainWP_System_Utility::get_download_sig( $dbBackup ) . '&mwpdl=' . rawurlencode( str_replace( $mwpDir, '', $dbBackup ) ) );
57 $output .= '<div class="ui grid field">';
58 $output .= '<label class="six wide column middle aligned">' . MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( filemtime( $dbBackup ) ) ) . ' - ' . MainWP_Utility::human_filesize( filesize( $dbBackup ) ) . '</label><div class="ten wide column ui toggle checkbox"><a title="' . basename( $dbBackup ) . '" href="' . esc_url( $downloadLink ) . '" download class="button">Download</a></div>';
59 $output .= '</div>';
60 }
61 ?>
62 <h3 class="header"><?php echo '' === $output ? esc_html__( 'No database only backup has been taken yet', 'mainwp' ) : esc_html__( 'Last backups from your database', 'mainwp' ); ?></h3>
63 <?php
64 echo $output;
65 // phpcs:enable
66 }
67
68 /**
69 * Renders the Backup Site Dialog.
70 *
71 * @param mixed $website Child Site info.
72 *
73 * @return string Backup Site html.
74 */
75 public static function render_backup_site( &$website ) {
76 if ( ! \mainwp_current_user_can( 'dashboard', 'execute_backups' ) ) {
77 \mainwp_do_not_have_permissions( esc_html__( 'execute backups', 'mainwp' ) );
78 return;
79 }
80
81 /** This filter is documented in ../pages/page-mainwp-server-information-handler.php */
82 $primary_methods = array();
83 $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.
84 $primaryBackupMethods = apply_filters( 'mainwp_getprimarybackup_methods', $primary_methods );
85
86 if ( ! is_array( $primaryBackupMethods ) ) {
87 $primaryBackupMethods = array();
88 }
89 ?>
90 <div class="error below-h2" style="display: none;" id="ajax-error-zone"></div>
91 <div id="ajax-information-zone" class="updated" style="display: none;"></div>
92
93 <?php if ( empty( $primaryBackupMethods ) ) { ?>
94 <div class="ui blue message"><?php printf( /* translators: 1: Opening anchor tag, 2: Closing anchor tag with icon. */ 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> <i class="external alternate icon"></i>' ); // NOSONAR - noopener - open safe. ?></div>
95 <?php
96 }
97 ?>
98 <div class="ui alt segment">
99 <div class="mainwp-main-content">
100 <div class="ui message" id="mainwp-message-zone" style="display:none"></div>
101 <?php
102 static::render_backup_details( $website->id );
103 static::render_backup_options( $website->id );
104 ?>
105 </div>
106 </div>
107
108 <div class="ui modal" id="managesite-backup-status-box">
109 <div class="header">
110 <?php esc_html_e( 'Backup ', 'mainwp' ); ?><?php echo esc_html( stripslashes( $website->name ) ); ?>
111 </div>
112 <div class="scrolling content mainwp-modal-content">
113 </div>
114 <div class="actions mainwp-modal-actions">
115 <input id="managesite-backup-status-close" type="button" name="Close" value="<?php esc_attr_e( 'Cancel ', 'mainwp' ); ?>" class="button" />
116 </div>
117 </div>
118
119 <?php
120 }
121
122 /**
123 * Render Backup Details.
124 *
125 * @param mixed $websiteid Child Site ID.
126 *
127 * @return string Backup Details.
128 *
129 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
130 * @uses \MainWP\Dashboard\MainWP_Manage_Sites::show_backups()
131 */
132 public static function render_backup_details( $websiteid ) {
133 $website = MainWP_DB::instance()->get_website_by_id( $websiteid );
134 if ( empty( $website ) ) {
135 return;
136 }
137 MainWP_Manage_Sites::show_backups( $website );
138 }
139
140 /**
141 * Render Backup Options.
142 *
143 * @param mixed $websiteid Child Site ID.
144 *
145 * @return string Backup Options.
146 *
147 * @uses \MainWP\Dashboard\MainWP_DB_Backup::get_website_backup_settings()
148 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
149 */
150 public static function render_backup_options( $websiteid ) {
151 $website = MainWP_DB::instance()->get_website_by_id( $websiteid );
152
153 if ( empty( $website ) ) {
154 return;
155 }
156
157 ?>
158 <h3 class="ui dividing header"><?php esc_html_e( 'Backup Options', 'mainwp' ); ?></h3>
159 <form method="POST" action="" class="ui form">
160 <?php MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' ); ?>
161 <input type="hidden" name="site_id" id="backup_site_id" value="<?php echo intval( $website->id ); ?>"/>
162 <input type="hidden" name="backup_site_full_size" id="backup_site_full_size" value="<?php echo esc_attr( $website->totalsize ); ?>"/>
163 <input type="hidden" name="backup_site_db_size" id="backup_site_db_size" value="<?php echo esc_attr( $website->dbsize ); ?>"/>
164
165 <div class="ui grid field">
166 <label class="six wide column middle aligned"><?php esc_html_e( 'Backup file name', 'mainwp' ); ?></label>
167 <div class="ten wide column">
168 <input type="text" name="backup_filename" id="backup_filename" value="" class="" />
169 </div>
170 </div>
171 <div class="ui grid field">
172 <label class="six wide column middle aligned"><?php esc_html_e( 'Backup type', 'mainwp' ); ?></label>
173 <div class="ten wide column">
174 <select name="mainwp-backup-type" id="mainwp-backup-type" class="ui dropdown">
175 <option value="full" selected><?php esc_html_e( 'Full Backup', 'mainwp' ); ?></option>
176 <option value="db"><?php esc_html_e( 'Database Backup', 'mainwp' ); ?></option>
177 </select>
178 </div>
179 </div>
180
181 <?php do_action( 'mainwp_backups_remote_settings', array( 'website' => $website->id ) ); ?>
182
183 <?php
184 $globalArchiveFormat = get_option( 'mainwp_archiveFormat' );
185 if ( false === $globalArchiveFormat ) {
186 $globalArchiveFormat = 'tar.gz';
187 }
188 if ( 'zip' === $globalArchiveFormat ) {
189 $globalArchiveFormatText = 'Zip';
190 } elseif ( 'tar' === $globalArchiveFormat ) {
191 $globalArchiveFormatText = 'Tar';
192 } elseif ( 'tar.gz' === $globalArchiveFormat ) {
193 $globalArchiveFormatText = 'Tar GZip';
194 } elseif ( 'tar.bz2' === $globalArchiveFormat ) {
195 $globalArchiveFormatText = 'Tar BZip2';
196 }
197
198 $backupSettings = MainWP_DB_Backup::instance()->get_website_backup_settings( $website->id );
199 $archiveFormat = $backupSettings->archiveFormat;
200 $useGlobal = ( 'global' === $archiveFormat );
201 ?>
202
203 <div class="ui grid field">
204 <label class="six wide column middle aligned"><?php esc_html_e( 'Archive type', 'mainwp' ); ?></label>
205 <div class="ten wide column">
206 <select name="mainwp_archiveFormat" id="mainwp_archiveFormat" class="ui dropdown">
207 <option value="global"
208 <?php
209 if ( $useGlobal ) :
210 ?>
211 selected<?php endif; ?>>Global setting (<?php echo esc_html( $globalArchiveFormatText ); ?>)</option>
212 <option value="zip"
213 <?php
214 if ( 'zip' === $archiveFormat ) :
215 ?>
216 selected<?php endif; ?>>Zip</option>
217 <option value="tar"
218 <?php
219 if ( 'tar' === $archiveFormat ) :
220 ?>
221 selected<?php endif; ?>>Tar</option>
222 <option value="tar.gz"
223 <?php
224 if ( 'tar.gz' === $archiveFormat ) :
225 ?>
226 selected<?php endif; ?>>Tar GZip</option>
227 <option value="tar.bz2"
228 <?php
229 if ( 'tar.bz2' === $archiveFormat ) :
230 ?>
231 selected<?php endif; ?>>Tar BZip2</option>
232 </select>
233 </div>
234 </div>
235 <div class="mainwp-backup-full-exclude">
236 <h3 class="header"><?php esc_html_e( 'Backup Excludes', 'mainwp' ); ?></h3>
237 <div class="ui grid field">
238 <label class="six wide column middle aligned"><?php esc_html_e( 'Known backup locations', 'mainwp' ); ?></label>
239 <div class="ten wide column ui toggle checkbox">
240 <input type="checkbox" id="mainwp-known-backup-locations">
241 </div>
242 </div>
243 <div class="ui grid field">
244 <label class="six wide column middle aligned"></label>
245 <div class="ten wide column ui toggle checkbox">
246 <textarea id="mainwp-kbl-content" disabled></textarea><br />
247 <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>
248 </div>
249 </div>
250 <div class="ui grid field">
251 <label class="six wide column middle aligned"><?php esc_html_e( 'Known cache locations', 'mainwp' ); ?></label>
252 <div class="ten wide column ui toggle checkbox">
253 <input type="checkbox" id="mainwp-known-cache-locations"><br />
254 </div>
255 </div>
256 <div class="ui grid field">
257 <label class="six wide column middle aligned"></label>
258 <div class="ten wide column ui toggle checkbox">
259 <textarea id="mainwp-kcl-content" disabled></textarea><br />
260 <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>
261 </div>
262 </div>
263 <div class="ui grid field">
264 <label class="six wide column middle aligned"><?php esc_html_e( 'Non-WordPress folders', 'mainwp' ); ?></label>
265 <div class="ten wide column ui toggle checkbox">
266 <input type="checkbox" id="mainwp-non-wordpress-folders"><br />
267 </div>
268 </div>
269 <div class="ui grid field">
270 <label class="six wide column middle aligned"></label>
271 <div class="ten wide column ui toggle checkbox">
272 <textarea id="mainwp-nwl-content" disabled></textarea><br />
273 <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>
274 </div>
275 </div>
276 <div class="ui grid field">
277 <label class="six wide column middle aligned"><?php esc_html_e( 'ZIP archives', 'mainwp' ); ?></label>
278 <div class="ten wide column ui toggle checkbox">
279 <input type="checkbox" id="mainwp-zip-archives">
280 </div>
281 </div>
282 <div class="ui grid field">
283 <label class="six wide column middle aligned"><?php esc_html_e( 'Custom excludes', 'mainwp' ); ?></label>
284 <div class="ten wide column ui toggle checkbox">
285 <textarea id="excluded_folders_list"></textarea>
286 </div>
287 </div>
288 </div>
289 <input type="button" name="backup_btnSubmit" id="backup_btnSubmit" class="ui button green big floated" value="<?php esc_attr_e( 'Backup Now', 'mainwp' ); ?>"/>
290 </form>
291 <?php
292 }
293 }
294