Version Description
- 9-9-20 =
- Fixed: An issue with posting Custom Post Types
- Fixed: Multiple PHP Warnings
- Added: New actions and filters
- Added: phpDocs blocks for code documentation
- Updated: refactored the code to meet WordPress coding standards
- Updated: WordPress 5.5 compatibility
- Preventative: Multiple security improvements
Download this release
Release Info
Developer | mainwp |
Plugin | MainWP Child |
Version | 4.1 |
Comparing to | |
See all releases |
Code changes from version 4.0.7.2 to 4.1
- class/class-mainwp-backup.php +913 -413
- class/class-mainwp-child-back-up-buddy.php +2107 -1311
- class/class-mainwp-child-back-up-wordpress.php +896 -743
- class/class-mainwp-child-back-wp-up.php +1781 -1346
- class/class-mainwp-child-branding-render.php +376 -0
- class/class-mainwp-child-branding.php +803 -654
- class/class-mainwp-child-bulk-settings-manager.php +310 -0
- class/class-mainwp-child-callable.php +865 -0
- class/class-mainwp-child-comments.php +231 -0
- class/class-mainwp-child-db.php +136 -27
- class/class-mainwp-child-install.php +485 -0
- class/class-mainwp-child-ithemes-security.php +766 -393
- class/class-mainwp-child-links-checker.php +375 -209
- class/class-mainwp-child-maintenance.php +349 -0
- class/class-mainwp-child-misc.php +729 -0
- class/class-mainwp-child-pagespeed.php +380 -238
- class/class-mainwp-child-plugins-check.php +181 -114
- class/class-mainwp-child-posts.php +1319 -0
- class/class-mainwp-child-robot.php +0 -34
- class/class-mainwp-child-server-information-base.php +765 -0
- class/class-mainwp-child-server-information.php +827 -1096
- class/class-mainwp-child-skeleton-key.php +0 -242
- class/class-mainwp-child-staging.php +576 -362
- class/class-mainwp-child-stats.php +391 -0
class/class-mainwp-backup.php
CHANGED
@@ -1,41 +1,173 @@
|
|
1 |
<?php
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
class MainWP_Backup {
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
5 |
protected $excludeZip;
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
protected $zip;
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
protected $zipArchiveFileCount;
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
protected $zipArchiveSizeCount;
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
protected $zipArchiveFileName;
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
protected $file_descriptors;
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
protected $loadFilesBeforeZip;
|
12 |
|
|
|
|
|
|
|
|
|
|
|
13 |
protected $timeout;
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
protected $lastRun;
|
15 |
|
16 |
/**
|
17 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
*/
|
19 |
protected $archiver = null;
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
public static function get() {
|
22 |
if ( null === self::$instance ) {
|
23 |
-
self::$instance = new
|
24 |
}
|
25 |
-
|
26 |
return self::$instance;
|
27 |
}
|
28 |
|
29 |
/**
|
30 |
-
* Create full backup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
*/
|
32 |
-
public function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
$this->file_descriptors = $file_descriptors;
|
34 |
$this->loadFilesBeforeZip = $loadFilesBeforeZip;
|
35 |
|
36 |
-
$dirs = MainWP_Helper::
|
37 |
$backupdir = $dirs[0];
|
38 |
if ( ! defined( 'PCLZIP_TEMPORARY_DIR' ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
define( 'PCLZIP_TEMPORARY_DIR', $backupdir );
|
40 |
}
|
41 |
|
@@ -43,7 +175,7 @@ class MainWP_Backup {
|
|
43 |
$pid = trailingslashit( $backupdir ) . 'backup-' . $pid . '.pid';
|
44 |
}
|
45 |
|
46 |
-
//Verify if another backup is running, if so, return an error
|
47 |
$files = glob( $backupdir . '*.pid' );
|
48 |
foreach ( $files as $file ) {
|
49 |
if ( basename( $file ) == basename( $pid ) ) {
|
@@ -65,56 +197,37 @@ class MainWP_Backup {
|
|
65 |
$ext = '.zip';
|
66 |
} else {
|
67 |
$this->archiver = new Tar_Archiver( $this, $ext, $pid );
|
68 |
-
$ext = $this->archiver->
|
69 |
}
|
70 |
|
71 |
-
// throw new Exception('Test 1 2 : ' . print_r($append,1));
|
72 |
if ( ( false !== $fileSuffix ) && ! empty( $fileSuffix ) ) {
|
73 |
-
|
|
|
74 |
} else {
|
75 |
$file = 'backup-' . $filePrefix . $timestamp . $ext;
|
76 |
}
|
77 |
$filepath = $backupdir . $file;
|
78 |
$fileurl = $file;
|
79 |
|
80 |
-
// if (!$append)
|
81 |
-
// {
|
82 |
-
// if ($dh = opendir($backupdir))
|
83 |
-
// {
|
84 |
-
// while (($file = readdir($dh)) !== false)
|
85 |
-
// {
|
86 |
-
// if ($file != '.' && $file != '..' && preg_match('/(.*).(zip|tar|tar.gz|tar.bz2|pid|done)$/', $file))
|
87 |
-
// {
|
88 |
-
// @unlink($backupdir . $file);
|
89 |
-
// }
|
90 |
-
// }
|
91 |
-
// closedir($dh);
|
92 |
-
// }
|
93 |
-
// }
|
94 |
-
|
95 |
if ( ! $addConfig ) {
|
96 |
-
if ( ! in_array( str_replace( ABSPATH, '', WP_CONTENT_DIR ), $excludes ) && ! in_array( 'wp-admin', $excludes ) && ! in_array( WPINC, $excludes ) ) {
|
97 |
$addConfig = true;
|
98 |
$includeCoreFiles = true;
|
99 |
}
|
100 |
}
|
101 |
|
102 |
-
$this->timeout = 20 * 60 * 60;
|
103 |
$mem = '512M';
|
104 |
-
|
105 |
-
@ini_set( 'memory_limit', $mem );
|
106 |
-
@set_time_limit( $this->timeout );
|
107 |
-
@ini_set( 'max_execution_time', $this->timeout );
|
108 |
-
// @codingStandardsIgnoreEnd
|
109 |
|
110 |
if ( null !== $this->archiver ) {
|
111 |
-
$success = $this->archiver->
|
112 |
-
}
|
113 |
-
$success = $this->
|
114 |
-
}
|
115 |
-
$success = $this->
|
116 |
} else {
|
117 |
-
$success = $this->
|
118 |
}
|
119 |
|
120 |
return ( $success ) ? array(
|
@@ -124,41 +237,403 @@ class MainWP_Backup {
|
|
124 |
) : false;
|
125 |
}
|
126 |
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
$mem = '512M';
|
130 |
-
|
131 |
-
@ini_set( 'memory_limit', $mem );
|
132 |
-
@set_time_limit( $this->timeout );
|
133 |
-
@ini_set( 'max_execution_time', $this->timeout );
|
134 |
-
// @codingStandardsIgnoreEnd
|
135 |
|
136 |
-
if ( !is_array( $files ) ) {
|
137 |
-
$files = array
|
138 |
}
|
139 |
|
140 |
if ( null !== $this->archiver ) {
|
141 |
-
$success = $this->archiver->
|
142 |
-
}
|
143 |
-
$success = $this->
|
144 |
-
}
|
145 |
-
$success = $this->
|
146 |
} else {
|
147 |
-
$success = $this->
|
148 |
}
|
149 |
|
150 |
return $success;
|
151 |
}
|
152 |
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
$this->zipArchiveFileCount = 0;
|
156 |
$this->zipArchiveSizeCount = 0;
|
157 |
|
158 |
-
$zipRes = $this->zip->open( $archive, ZipArchive::CREATE );
|
159 |
if ( $zipRes ) {
|
160 |
foreach ( $files as $file ) {
|
161 |
-
$this->
|
162 |
}
|
163 |
|
164 |
return $this->zip->close();
|
@@ -167,175 +642,129 @@ class MainWP_Backup {
|
|
167 |
return false;
|
168 |
}
|
169 |
|
170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
return false;
|
172 |
}
|
173 |
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
$error = false;
|
180 |
foreach ( $files as $file ) {
|
181 |
-
|
|
|
182 |
$error = true;
|
183 |
}
|
184 |
}
|
185 |
|
186 |
-
return
|
187 |
}
|
188 |
|
189 |
/**
|
190 |
-
* Check for default PHP zip support
|
191 |
*
|
192 |
-
* @return bool
|
193 |
*/
|
194 |
-
public function
|
195 |
-
return class_exists( 'ZipArchive' );
|
196 |
}
|
197 |
|
198 |
/**
|
199 |
* Check if we could run zip on console
|
200 |
*
|
201 |
-
* @return bool
|
202 |
*/
|
203 |
-
public function
|
204 |
return false;
|
205 |
-
// return function_exists('system');
|
206 |
}
|
207 |
|
208 |
/**
|
209 |
-
* Create full backup using default PHP zip library
|
210 |
*
|
211 |
-
* @param string $filepath
|
|
|
|
|
|
|
|
|
|
|
212 |
*
|
213 |
-
* @
|
|
|
|
|
|
|
|
|
|
|
214 |
*/
|
215 |
-
public function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
$this->excludeZip = $excludezip;
|
217 |
-
$this->zip = new ZipArchive();
|
218 |
$this->zipArchiveFileCount = 0;
|
219 |
$this->zipArchiveSizeCount = 0;
|
220 |
$this->zipArchiveFileName = $filepath;
|
221 |
-
$zipRes = $this->zip->open( $filepath, ZipArchive::CREATE );
|
222 |
if ( $zipRes ) {
|
223 |
$nodes = glob( ABSPATH . '*' );
|
224 |
if ( ! $includeCoreFiles ) {
|
225 |
-
$
|
226 |
-
'favicon.ico',
|
227 |
-
'index.php',
|
228 |
-
'license.txt',
|
229 |
-
'readme.html',
|
230 |
-
'wp-activate.php',
|
231 |
-
'wp-app.php',
|
232 |
-
'wp-blog-header.php',
|
233 |
-
'wp-comments-post.php',
|
234 |
-
'wp-config.php',
|
235 |
-
'wp-config-sample.php',
|
236 |
-
'wp-cron.php',
|
237 |
-
'wp-links-opml.php',
|
238 |
-
'wp-load.php',
|
239 |
-
'wp-login.php',
|
240 |
-
'wp-mail.php',
|
241 |
-
'wp-pass.php',
|
242 |
-
'wp-register.php',
|
243 |
-
'wp-settings.php',
|
244 |
-
'wp-signup.php',
|
245 |
-
'wp-trackback.php',
|
246 |
-
'xmlrpc.php',
|
247 |
-
);
|
248 |
-
foreach ( $nodes as $key => $node ) {
|
249 |
-
if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) {
|
250 |
-
unset( $nodes[ $key ] );
|
251 |
-
} else if ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
|
252 |
-
unset( $nodes[ $key ] );
|
253 |
-
} else {
|
254 |
-
foreach ( $coreFiles as $coreFile ) {
|
255 |
-
if ( ABSPATH . $coreFile === $node ) {
|
256 |
-
unset( $nodes[ $key ] );
|
257 |
-
}
|
258 |
-
}
|
259 |
-
}
|
260 |
-
}
|
261 |
-
unset( $coreFiles );
|
262 |
}
|
263 |
|
264 |
-
$db_files = $this->
|
265 |
foreach ( $db_files as $db_file ) {
|
266 |
-
$this->
|
267 |
}
|
268 |
|
269 |
if ( file_exists( ABSPATH . '.htaccess' ) ) {
|
270 |
-
$this->
|
271 |
}
|
272 |
|
273 |
foreach ( $nodes as $node ) {
|
274 |
if ( $excludenonwp && is_dir( $node ) ) {
|
275 |
-
if ( ! MainWP_Helper::
|
276 |
continue;
|
277 |
}
|
278 |
}
|
279 |
|
280 |
-
if ( ! MainWP_Helper::
|
281 |
if ( is_dir( $node ) ) {
|
282 |
-
$this->
|
283 |
-
}
|
284 |
-
$this->
|
285 |
}
|
286 |
}
|
287 |
}
|
288 |
|
289 |
if ( $addConfig ) {
|
290 |
-
|
291 |
-
$plugins = array();
|
292 |
-
$dir = WP_CONTENT_DIR . '/plugins/';
|
293 |
-
// @codingStandardsIgnoreStart
|
294 |
-
$fh = @opendir( $dir );
|
295 |
-
while ( $entry = @readdir( $fh ) ) {
|
296 |
-
if ( ! @is_dir( $dir . $entry ) ) {
|
297 |
-
continue;
|
298 |
-
}
|
299 |
-
if ( ( $entry == '.' ) || ( $entry == '..' ) ) {
|
300 |
-
continue;
|
301 |
-
}
|
302 |
-
$plugins[] = $entry;
|
303 |
-
}
|
304 |
-
@closedir( $fh );
|
305 |
-
// @codingStandardsIgnoreEnd
|
306 |
-
|
307 |
-
$themes = array();
|
308 |
-
$dir = WP_CONTENT_DIR . '/themes/';
|
309 |
-
// @codingStandardsIgnoreStart
|
310 |
-
$fh = @opendir( $dir );
|
311 |
-
while ( $entry = @readdir( $fh ) ) {
|
312 |
-
if ( ! @is_dir( $dir . $entry ) ) {
|
313 |
-
continue;
|
314 |
-
}
|
315 |
-
if ( ( $entry == '.' ) || ( $entry == '..' ) ) {
|
316 |
-
continue;
|
317 |
-
}
|
318 |
-
$themes[] = $entry;
|
319 |
-
}
|
320 |
-
@closedir( $fh );
|
321 |
-
// @codingStandardsIgnoreEnd
|
322 |
-
|
323 |
-
$string = base64_encode( serialize( array(
|
324 |
-
'siteurl' => get_option( 'siteurl' ),
|
325 |
-
'home' => get_option( 'home' ),
|
326 |
-
'abspath' => ABSPATH,
|
327 |
-
'prefix' => $wpdb->prefix,
|
328 |
-
'lang' => defined( 'WPLANG' ) ? WPLANG : '',
|
329 |
-
'plugins' => $plugins,
|
330 |
-
'themes' => $themes,
|
331 |
-
) ) );
|
332 |
-
|
333 |
-
$this->addFileFromStringToZip( 'clone/config.txt', $string );
|
334 |
}
|
335 |
|
336 |
$return = $this->zip->close();
|
337 |
foreach ( $db_files as $db_file ) {
|
338 |
-
|
339 |
}
|
340 |
|
341 |
return true;
|
@@ -345,156 +774,206 @@ class MainWP_Backup {
|
|
345 |
}
|
346 |
|
347 |
/**
|
348 |
-
*
|
349 |
*
|
350 |
-
* @param
|
351 |
*
|
352 |
-
* @
|
353 |
*/
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
)
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
} else {
|
388 |
-
foreach ( $coreFiles as $coreFile ) {
|
389 |
-
if ( ABSPATH . $coreFile === $node ) {
|
390 |
-
unset( $nodes[ $key ] );
|
391 |
-
}
|
392 |
}
|
393 |
}
|
394 |
}
|
395 |
-
unset( $coreFiles );
|
396 |
}
|
|
|
|
|
397 |
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
|
|
|
|
|
|
405 |
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
}
|
423 |
-
}
|
424 |
}
|
|
|
425 |
}
|
|
|
426 |
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
$
|
438 |
}
|
|
|
439 |
|
440 |
-
if (
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
}
|
447 |
|
448 |
-
|
449 |
}
|
450 |
|
451 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
452 |
if ( ! is_array( $nodes ) ) {
|
453 |
return;
|
454 |
}
|
455 |
|
456 |
foreach ( $nodes as $node ) {
|
457 |
if ( $excludenonwp && is_dir( $node ) ) {
|
458 |
-
if ( ! MainWP_Helper::
|
459 |
continue;
|
460 |
}
|
461 |
}
|
462 |
|
463 |
-
if ( ! MainWP_Helper::
|
464 |
if ( is_dir( $node ) ) {
|
465 |
if ( ! file_exists( str_replace( ABSPATH, $backupfolder, $node ) ) ) {
|
466 |
-
//
|
467 |
-
@mkdir( str_replace( ABSPATH, $backupfolder, $node ) );
|
468 |
-
// @codingStandardsIgnoreEnd
|
469 |
}
|
470 |
|
471 |
$newnodes = glob( $node . DIRECTORY_SEPARATOR . '*' );
|
472 |
$this->copy_dir( $newnodes, $excludes, $backupfolder, $excludenonwp, false );
|
473 |
unset( $newnodes );
|
474 |
-
}
|
475 |
-
if ( $this->excludeZip && MainWP_Helper::
|
476 |
continue;
|
477 |
}
|
478 |
|
479 |
-
//
|
480 |
-
@copy( $node, str_replace( ABSPATH, $backupfolder, $node ) );
|
481 |
-
// @codingStandardsIgnoreEnd
|
482 |
}
|
483 |
}
|
484 |
}
|
485 |
}
|
486 |
|
487 |
-
|
488 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
489 |
$backupFolder = dirname( $filepath ) . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR;
|
490 |
-
// @codingStandardsIgnoreStart
|
491 |
-
@mkdir( $backupFolder );
|
492 |
-
// @codingStandardsIgnoreEnd
|
493 |
|
494 |
-
//
|
495 |
-
$db_files = $this->createBackupDB( $backupFolder . 'dbBackup' );
|
496 |
|
497 |
-
//
|
|
|
|
|
|
|
498 |
$nodes = glob( ABSPATH . '*' );
|
499 |
if ( ! $includeCoreFiles ) {
|
500 |
$coreFiles = array(
|
@@ -521,9 +1000,9 @@ class MainWP_Backup {
|
|
521 |
'xmlrpc.php',
|
522 |
);
|
523 |
foreach ( $nodes as $key => $node ) {
|
524 |
-
if ( MainWP_Helper::
|
525 |
unset( $nodes[ $key ] );
|
526 |
-
}
|
527 |
unset( $nodes[ $key ] );
|
528 |
} else {
|
529 |
foreach ( $coreFiles as $coreFile ) {
|
@@ -536,49 +1015,75 @@ class MainWP_Backup {
|
|
536 |
unset( $coreFiles );
|
537 |
}
|
538 |
$this->copy_dir( $nodes, $excludes, $backupFolder, $excludenonwp, true );
|
539 |
-
// to fix bug wrong folder
|
540 |
-
// @codingStandardsIgnoreStart
|
541 |
|
542 |
foreach ( $db_files as $db_file ) {
|
543 |
-
|
544 |
-
|
545 |
}
|
546 |
-
|
547 |
unset( $nodes );
|
548 |
|
549 |
-
//Zip this backup folder
|
550 |
-
require_once
|
551 |
-
$this->zip = new PclZip( $filepath );
|
552 |
$this->zip->create( $backupFolder, PCLZIP_OPT_REMOVE_PATH, $backupFolder );
|
553 |
if ( $addConfig ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
554 |
global $wpdb;
|
555 |
-
$string = base64_encode( serialize( array(
|
556 |
-
'siteurl' => get_option( 'siteurl' ),
|
557 |
-
'home' => get_option( 'home' ),
|
558 |
-
'abspath' => ABSPATH,
|
559 |
-
'prefix' => $wpdb->prefix,
|
560 |
-
'lang' => WPLANG,
|
561 |
-
) ) );
|
562 |
|
563 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
564 |
}
|
565 |
-
//Remove backup folder
|
566 |
MainWP_Helper::delete_dir( $backupFolder );
|
567 |
|
568 |
return true;
|
569 |
}
|
570 |
|
571 |
/**
|
572 |
-
*
|
|
|
|
|
|
|
|
|
|
|
573 |
*/
|
574 |
-
public function
|
575 |
-
$this->zip->
|
576 |
|
577 |
if ( file_exists( rtrim( $path, '/' ) . '/.htaccess' ) ) {
|
578 |
-
$this->
|
579 |
}
|
580 |
|
581 |
-
$iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path ), RecursiveIteratorIterator::SELF_FIRST );
|
582 |
|
583 |
foreach ( $iterator as $path ) {
|
584 |
$name = $path->__toString();
|
@@ -586,11 +1091,11 @@ class MainWP_Backup {
|
|
586 |
continue;
|
587 |
}
|
588 |
|
589 |
-
if ( ! MainWP_Helper::
|
590 |
if ( $path->isDir() ) {
|
591 |
-
$this->
|
592 |
} else {
|
593 |
-
$this->
|
594 |
}
|
595 |
}
|
596 |
$name = null;
|
@@ -599,65 +1104,42 @@ class MainWP_Backup {
|
|
599 |
|
600 |
$iterator = null;
|
601 |
unset( $iterator );
|
602 |
-
|
603 |
-
// $nodes = glob(rtrim($path, '/') . '/*');
|
604 |
-
// if (empty($nodes)) return true;
|
605 |
-
//
|
606 |
-
// foreach ($nodes as $node)
|
607 |
-
// {
|
608 |
-
// if (!MainWP_Helper::inExcludes($excludes, str_replace(ABSPATH, '', $node)))
|
609 |
-
// {
|
610 |
-
// if (is_dir($node))
|
611 |
-
// {
|
612 |
-
// $this->zipAddDir($node, $excludes);
|
613 |
-
// }
|
614 |
-
// else if (is_file($node))
|
615 |
-
// {
|
616 |
-
// $this->addFileToZip($node, str_replace(ABSPATH, '', $node));
|
617 |
-
// }
|
618 |
-
// }
|
619 |
-
// }
|
620 |
}
|
621 |
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
if ( is_dir( $node ) ) {
|
632 |
-
if ( ! $this->pclZipAddDir( $node, $excludes ) ) {
|
633 |
-
$error = true;
|
634 |
-
break;
|
635 |
-
}
|
636 |
-
} else if ( is_file( $node ) ) {
|
637 |
-
if ( 0 === ( $rslt = $this->zip->add( $node, PCLZIP_OPT_REMOVE_PATH, ABSPATH ) ) ) {
|
638 |
-
$error = true;
|
639 |
-
break;
|
640 |
-
}
|
641 |
-
}
|
642 |
-
}
|
643 |
-
}
|
644 |
-
|
645 |
-
return ! $error;
|
646 |
-
}
|
647 |
-
|
648 |
-
function addFileFromStringToZip( $file, $string ) {
|
649 |
return $this->zip->addFromString( $file, $string );
|
650 |
}
|
651 |
|
652 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
653 |
$file = preg_replace( '/(?:\.|\/)*(.*)/', '$1', $file );
|
654 |
$localpath = dirname( $file );
|
655 |
$tmpfilename = dirname( $filepath ) . '/' . basename( $file );
|
656 |
if ( false !== file_put_contents( $tmpfilename, $string ) ) {
|
657 |
$this->zip->delete( PCLZIP_OPT_BY_NAME, $file );
|
658 |
-
$add = $this->zip->add(
|
659 |
-
|
660 |
-
|
|
|
|
|
|
|
|
|
661 |
unlink( $tmpfilename );
|
662 |
if ( ! empty( $add ) ) {
|
663 |
return true;
|
@@ -667,72 +1149,61 @@ class MainWP_Backup {
|
|
667 |
return false;
|
668 |
}
|
669 |
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
|
|
|
|
|
|
|
|
|
|
674 |
if ( time() - $this->lastRun > 20 ) {
|
675 |
-
//
|
676 |
-
@set_time_limit( $this->timeout );
|
677 |
-
// @codingStandardsIgnoreEnd
|
678 |
$this->lastRun = time();
|
679 |
}
|
680 |
|
681 |
-
if ( $this->excludeZip && MainWP_Helper::
|
682 |
return false;
|
683 |
}
|
684 |
|
685 |
-
// this would fail with status ZIPARCHIVE::ER_OPEN
|
686 |
-
// after certain number of files is added since
|
687 |
-
// ZipArchive internally stores the file descriptors of all the
|
688 |
-
// added files and only on close writes the contents to the ZIP file
|
689 |
-
// see: http://bugs.php.net/bug.php?id=40494
|
690 |
-
// and: http://pecl.php.net/bugs/bug.php?id=9443
|
691 |
-
// return $zip->addFile( $path, $zipEntryName );
|
692 |
-
|
693 |
$this->zipArchiveSizeCount += filesize( $path );
|
694 |
$this->gcCnt ++;
|
695 |
|
696 |
-
//5 mb limit!
|
697 |
if ( ! $this->loadFilesBeforeZip || ( filesize( $path ) > 5 * 1024 * 1024 ) ) {
|
698 |
$this->zipArchiveFileCount ++;
|
699 |
-
$added = $this->zip->
|
700 |
} else {
|
701 |
$this->zipArchiveFileCount ++;
|
702 |
|
703 |
$this->testContent = file_get_contents( $path );
|
704 |
-
if ( $this->testContent
|
705 |
return false;
|
706 |
}
|
707 |
$added = $this->zip->addFromString( $zipEntryName, $this->testContent );
|
708 |
}
|
709 |
|
710 |
if ( $this->gcCnt > 20 ) {
|
711 |
-
// @codingStandardsIgnoreStart
|
712 |
if ( function_exists( 'gc_enable' ) ) {
|
713 |
-
|
714 |
}
|
715 |
if ( function_exists( 'gc_collect_cycles' ) ) {
|
716 |
-
|
717 |
}
|
718 |
-
// @codingStandardsIgnoreEnd
|
719 |
$this->gcCnt = 0;
|
720 |
}
|
721 |
|
722 |
-
|
723 |
-
if ( ( ( $this->file_descriptors > 0 ) && ( $this->zipArchiveFileCount > $this->file_descriptors ) ) ) { // || $this->zipArchiveSizeCount >= (31457280 * 2))
|
724 |
$this->zip->close();
|
725 |
$this->zip = null;
|
726 |
unset( $this->zip );
|
727 |
-
// @codingStandardsIgnoreStart
|
728 |
if ( function_exists( 'gc_enable' ) ) {
|
729 |
-
|
730 |
}
|
731 |
if ( function_exists( 'gc_collect_cycles' ) ) {
|
732 |
-
|
733 |
}
|
734 |
-
|
735 |
-
$this->zip = new ZipArchive();
|
736 |
$this->zip->open( $this->zipArchiveFileName );
|
737 |
$this->zipArchiveFileCount = 0;
|
738 |
$this->zipArchiveSizeCount = 0;
|
@@ -741,61 +1212,93 @@ class MainWP_Backup {
|
|
741 |
return $added;
|
742 |
}
|
743 |
|
744 |
-
|
745 |
-
|
746 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
747 |
return false;
|
748 |
}
|
749 |
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
758 |
|
759 |
-
/**
|
|
|
|
|
|
|
|
|
760 |
global $wpdb;
|
761 |
|
762 |
-
$db_files
|
763 |
-
//
|
764 |
-
$tables_db = $wpdb->get_results( 'SHOW TABLES FROM `' . DB_NAME . '`', ARRAY_N );
|
765 |
foreach ( $tables_db as $curr_table ) {
|
766 |
if ( null !== $archiver ) {
|
767 |
-
$archiver->
|
768 |
}
|
769 |
|
770 |
$table = $curr_table[0];
|
771 |
|
772 |
$currentfile = $filepath_prefix . '-' . MainWP_Helper::sanitize_filename( $table ) . '.sql';
|
773 |
-
$db_files[]
|
774 |
if ( file_exists( $currentfile ) ) {
|
775 |
continue;
|
776 |
}
|
777 |
-
$fh = fopen( $currentfile . '.tmp', 'w' );
|
778 |
|
779 |
fwrite( $fh, "\n\n" . 'DROP TABLE IF EXISTS ' . $table . ';' );
|
780 |
-
//
|
781 |
-
//$table_create = $wpdb->get_row( $wpdb->prepare( 'SHOW CREATE TABLE %s', $table ), ARRAY_N );
|
782 |
-
$table_create = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N );
|
783 |
fwrite( $fh, "\n" . $table_create[1] . ";\n\n" );
|
784 |
|
785 |
-
//
|
786 |
-
$rows = @MainWP_Child_DB::_query( 'SELECT * FROM ' . $table, $wpdb->dbh );
|
787 |
-
// @codingStandardsIgnoreEnd
|
788 |
|
789 |
if ( $rows ) {
|
790 |
$i = 0;
|
791 |
$table_insert = 'INSERT INTO `' . $table . '` VALUES (';
|
792 |
|
793 |
// @codingStandardsIgnoreStart
|
794 |
-
while ( $row =
|
795 |
// @codingStandardsIgnoreEnd
|
796 |
$query = $table_insert;
|
797 |
foreach ( $row as $value ) {
|
798 |
-
if (
|
799 |
$query .= 'NULL, ';
|
800 |
} else {
|
801 |
$query .= '"' . MainWP_Child_DB::real_escape_string( $value ) . '", ';
|
@@ -803,7 +1306,7 @@ class MainWP_Backup {
|
|
803 |
}
|
804 |
$query = trim( $query, ', ' ) . ');';
|
805 |
|
806 |
-
fwrite( $fh, "\n" . $query );
|
807 |
$i ++;
|
808 |
|
809 |
if ( $i >= 50 ) {
|
@@ -817,11 +1320,11 @@ class MainWP_Backup {
|
|
817 |
}
|
818 |
$rows = null;
|
819 |
fflush( $fh );
|
820 |
-
fclose( $fh );
|
821 |
rename( $currentfile . '.tmp', $currentfile );
|
822 |
}
|
823 |
|
824 |
-
fclose( fopen( $filepath_prefix . '.sql', 'w' ) );
|
825 |
$db_files[] = $filepath_prefix . '.sql';
|
826 |
|
827 |
$archivefilePath = null;
|
@@ -834,16 +1337,13 @@ class MainWP_Backup {
|
|
834 |
$this->archiver = new Tar_Archiver( $this, $archiveExt );
|
835 |
}
|
836 |
|
837 |
-
if ( $this->
|
838 |
foreach ( $db_files as $db_file ) {
|
839 |
-
|
840 |
}
|
841 |
-
} else {
|
842 |
-
//todo: throw exception!
|
843 |
}
|
844 |
}
|
845 |
|
846 |
-
|
847 |
return ( false !== $archiveExt ? array( 'filepath' => $archivefilePath ) : $db_files );
|
848 |
}
|
849 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Backup
|
4 |
+
*
|
5 |
+
* This file handles all Child Site backup functions.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
//phpcs:disable WordPress.WP.AlternativeFunctions, Generic.Metrics.CyclomaticComplexity -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class MainWP_Backup
|
16 |
+
*
|
17 |
+
* Handle all Child Site backup functions.
|
18 |
+
*/
|
19 |
class MainWP_Backup {
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Whether to exclude zip archives.
|
23 |
+
*
|
24 |
+
* @var bool true|false
|
25 |
+
*/
|
26 |
protected $excludeZip;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Container for zip file.
|
30 |
+
*
|
31 |
+
* @var resource ZIP file
|
32 |
+
*/
|
33 |
protected $zip;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Backup files count.
|
37 |
+
*
|
38 |
+
* @var int Files count.
|
39 |
+
*/
|
40 |
protected $zipArchiveFileCount;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Backup archive file size.
|
44 |
+
*
|
45 |
+
* @var float File size.
|
46 |
+
*/
|
47 |
protected $zipArchiveSizeCount;
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Backup archive file name.
|
51 |
+
*
|
52 |
+
* @var string File name.
|
53 |
+
*/
|
54 |
protected $zipArchiveFileName;
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Backup file descriptors.
|
58 |
+
*
|
59 |
+
* @var int File descriptors.
|
60 |
+
*/
|
61 |
protected $file_descriptors;
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Whether to load file before zip.
|
65 |
+
*
|
66 |
+
* @var bool true|false
|
67 |
+
*/
|
68 |
protected $loadFilesBeforeZip;
|
69 |
|
70 |
+
/**
|
71 |
+
* Hold the current timeout length.
|
72 |
+
*
|
73 |
+
* @var int Timeout length.
|
74 |
+
*/
|
75 |
protected $timeout;
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Last time a backup has been run.
|
79 |
+
*
|
80 |
+
* @var string Last backup run.
|
81 |
+
*/
|
82 |
protected $lastRun;
|
83 |
|
84 |
/**
|
85 |
+
* Garbage collection count.
|
86 |
+
*
|
87 |
+
* @var int Garbage collection count.
|
88 |
+
*/
|
89 |
+
protected $gcCnt = 0;
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Archive test content.
|
93 |
+
*
|
94 |
+
* @var bool Test backup content.
|
95 |
+
*/
|
96 |
+
protected $testContent;
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Backup process archiver.
|
100 |
+
*
|
101 |
+
* @var object Backup process archiver.
|
102 |
*/
|
103 |
protected $archiver = null;
|
104 |
|
105 |
+
/**
|
106 |
+
* Protected static variable to hold the single instance of the class.
|
107 |
+
*
|
108 |
+
* @var mixed Default null
|
109 |
+
*/
|
110 |
+
protected static $instance = null;
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Create a public static instance.
|
114 |
+
*
|
115 |
+
* @return mixed Class instance.
|
116 |
+
*/
|
117 |
public static function get() {
|
118 |
if ( null === self::$instance ) {
|
119 |
+
self::$instance = new self();
|
120 |
}
|
|
|
121 |
return self::$instance;
|
122 |
}
|
123 |
|
124 |
/**
|
125 |
+
* Create full backup.
|
126 |
+
*
|
127 |
+
* @param array $excludes Files to exclude from the backup.
|
128 |
+
* @param string $filePrefix Backup archive file prefix.
|
129 |
+
* @param bool $addConfig Add config file to backup.
|
130 |
+
* @param bool $includeCoreFiles Include WordPress core files.
|
131 |
+
* @param int $file_descriptors Number of backup archive file descriptors.
|
132 |
+
* @param bool $fileSuffix Backup archive file suffix.
|
133 |
+
* @param bool $excludezip Exclude zip files from the backup.
|
134 |
+
* @param bool $excludenonwp Exclude non-WordPress directories in site root.
|
135 |
+
* @param bool $loadFilesBeforeZip Load files before zip.
|
136 |
+
* @param string $ext Backup file extension.
|
137 |
+
* @param bool $pid PID true|false.
|
138 |
+
* @param bool $append Append to backup file name.
|
139 |
+
*
|
140 |
+
* @used-by MainWP_Backup::backup_full()
|
141 |
+
*
|
142 |
+
* @return array|bool Action results on success, false on failure.
|
143 |
*/
|
144 |
+
public function create_full_backup(
|
145 |
+
$excludes,
|
146 |
+
$filePrefix = '',
|
147 |
+
$addConfig = false,
|
148 |
+
$includeCoreFiles = false,
|
149 |
+
$file_descriptors = 0,
|
150 |
+
$fileSuffix = false,
|
151 |
+
$excludezip = false,
|
152 |
+
$excludenonwp = false,
|
153 |
+
$loadFilesBeforeZip = true,
|
154 |
+
$ext = 'zip',
|
155 |
+
$pid = false,
|
156 |
+
$append = false ) {
|
157 |
+
|
158 |
$this->file_descriptors = $file_descriptors;
|
159 |
$this->loadFilesBeforeZip = $loadFilesBeforeZip;
|
160 |
|
161 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
162 |
$backupdir = $dirs[0];
|
163 |
if ( ! defined( 'PCLZIP_TEMPORARY_DIR' ) ) {
|
164 |
+
|
165 |
+
/**
|
166 |
+
* Defines PCLZIP temporary directory.
|
167 |
+
*
|
168 |
+
* @const ( string ) Temporary backup directory.
|
169 |
+
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Backup.html
|
170 |
+
*/
|
171 |
define( 'PCLZIP_TEMPORARY_DIR', $backupdir );
|
172 |
}
|
173 |
|
175 |
$pid = trailingslashit( $backupdir ) . 'backup-' . $pid . '.pid';
|
176 |
}
|
177 |
|
178 |
+
// Verify if another backup is running, if so, return an error.
|
179 |
$files = glob( $backupdir . '*.pid' );
|
180 |
foreach ( $files as $file ) {
|
181 |
if ( basename( $file ) == basename( $pid ) ) {
|
197 |
$ext = '.zip';
|
198 |
} else {
|
199 |
$this->archiver = new Tar_Archiver( $this, $ext, $pid );
|
200 |
+
$ext = $this->archiver->get_extension();
|
201 |
}
|
202 |
|
|
|
203 |
if ( ( false !== $fileSuffix ) && ! empty( $fileSuffix ) ) {
|
204 |
+
// Append already contains extension!
|
205 |
+
$file = $fileSuffix . ( true === $append ? '' : $ext );
|
206 |
} else {
|
207 |
$file = 'backup-' . $filePrefix . $timestamp . $ext;
|
208 |
}
|
209 |
$filepath = $backupdir . $file;
|
210 |
$fileurl = $file;
|
211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
if ( ! $addConfig ) {
|
213 |
+
if ( ! in_array( str_replace( ABSPATH, '', WP_CONTENT_DIR ), $excludes, true ) && ! in_array( 'wp-admin', $excludes, true ) && ! in_array( WPINC, $excludes, true ) ) {
|
214 |
$addConfig = true;
|
215 |
$includeCoreFiles = true;
|
216 |
}
|
217 |
}
|
218 |
|
219 |
+
$this->timeout = 20 * 60 * 60;
|
220 |
$mem = '512M';
|
221 |
+
MainWP_Helper::set_limit( $this->timeout, $mem );
|
|
|
|
|
|
|
|
|
222 |
|
223 |
if ( null !== $this->archiver ) {
|
224 |
+
$success = $this->archiver->create_full_backup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append );
|
225 |
+
} elseif ( $this->check_zip_support() ) {
|
226 |
+
$success = $this->create_zip_full_backup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp );
|
227 |
+
} elseif ( $this->check_zip_console() ) {
|
228 |
+
$success = $this->create_zip_console_full_backup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp );
|
229 |
} else {
|
230 |
+
$success = $this->create_zip_pcl_full_backup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp );
|
231 |
}
|
232 |
|
233 |
return ( $success ) ? array(
|
237 |
) : false;
|
238 |
}
|
239 |
|
240 |
+
/**
|
241 |
+
* Check whether the file is an archive or not & create a json_encoded, serialized, base64_encoded string.
|
242 |
+
*
|
243 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
244 |
+
* @uses MainWP_Helper::get_mainwp_dir() Get the MainWP directory.
|
245 |
+
*/
|
246 |
+
public function backup_poll() {
|
247 |
+
$fileNameUID = ( isset( $_POST['fileNameUID'] ) ? sanitize_text_field( wp_unslash( $_POST['fileNameUID'] ) ) : '' );
|
248 |
+
$fileName = ( isset( $_POST['fileName'] ) ? wp_unslash( $_POST['fileName'] ) : '' );
|
249 |
+
$type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
|
250 |
+
|
251 |
+
if ( 'full' === $type ) {
|
252 |
+
if ( '' !== $fileName ) {
|
253 |
+
$backupFile = $fileName;
|
254 |
+
} else {
|
255 |
+
$backupFile = 'backup-' . $fileNameUID . '-';
|
256 |
+
}
|
257 |
+
|
258 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
259 |
+
$backupdir = $dirs[0];
|
260 |
+
$result = glob( $backupdir . $backupFile . '*' );
|
261 |
+
|
262 |
+
// Check if archive, set $archiveFile = $file & break.
|
263 |
+
$archiveFile = false;
|
264 |
+
foreach ( $result as $file ) {
|
265 |
+
if ( MainWP_Clone::is_archive( $file, $backupFile, '(.*)' ) ) {
|
266 |
+
$archiveFile = $file;
|
267 |
+
break;
|
268 |
+
}
|
269 |
+
}
|
270 |
+
|
271 |
+
// When not an archive.
|
272 |
+
if ( false === $archiveFile ) {
|
273 |
+
MainWP_Helper::write( array() );
|
274 |
+
}
|
275 |
+
|
276 |
+
// When archive found.
|
277 |
+
MainWP_Helper::write( array( 'size' => filesize( $archiveFile ) ) );
|
278 |
+
} else {
|
279 |
+
// When not an archive.
|
280 |
+
$backupFile = 'dbBackup-' . $fileNameUID . '-*.sql';
|
281 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
282 |
+
$backupdir = $dirs[0];
|
283 |
+
$result = glob( $backupdir . $backupFile . '*' );
|
284 |
+
|
285 |
+
if ( 0 === count( $result ) ) {
|
286 |
+
MainWP_Helper::write( array() );
|
287 |
+
}
|
288 |
+
|
289 |
+
$size = 0;
|
290 |
+
foreach ( $result as $f ) {
|
291 |
+
$size += filesize( $f );
|
292 |
+
}
|
293 |
+
MainWP_Helper::write( array( 'size' => $size ) );
|
294 |
+
exit();
|
295 |
+
}
|
296 |
+
}
|
297 |
+
|
298 |
+
/**
|
299 |
+
* Check if backup already exists or is in the process of backing up.
|
300 |
+
*
|
301 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
302 |
+
* @uses MainWP_Helper::get_mainwp_dir() Get the MainWP directory.
|
303 |
+
* @uses MainWP_Helper::get_wp_filesystem() Get the WordPress filesystem.
|
304 |
+
*
|
305 |
+
* @uses WP_Filesystem_Base::is_file() Checks if resource is a file.
|
306 |
+
* @see https://developer.wordpress.org/reference/classes/wp_filesystem_base/is_file/
|
307 |
+
*
|
308 |
+
* @uses WP_Filesystem_Base::mtime() Gets the file modification time.
|
309 |
+
* @see https://developer.wordpress.org/reference/classes/wp_filesystem_base/mtime/
|
310 |
+
*
|
311 |
+
* @uses WP_Filesystem_Base::get_contents() Reads entire file into a string.
|
312 |
+
* @see https://developer.wordpress.org/reference/classes/wp_filesystem_base/get_contents/
|
313 |
+
*/
|
314 |
+
public function backup_checkpid() {
|
315 |
+
$pid = isset( $_POST['pid'] ) ? sanitize_text_field( wp_unslash( $_POST['pid'] ) ) : 0;
|
316 |
+
|
317 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
318 |
+
$backupdir = $dirs[0];
|
319 |
+
|
320 |
+
$information = array();
|
321 |
+
|
322 |
+
/**
|
323 |
+
* WordPress files system object.
|
324 |
+
*
|
325 |
+
* @global object
|
326 |
+
*/
|
327 |
+
global $wp_filesystem;
|
328 |
+
|
329 |
+
MainWP_Helper::get_wp_filesystem();
|
330 |
+
|
331 |
+
$pidFile = trailingslashit( $backupdir ) . 'backup-' . $pid . '.pid';
|
332 |
+
$doneFile = trailingslashit( $backupdir ) . 'backup-' . $pid . '.done';
|
333 |
+
if ( $wp_filesystem->is_file( $pidFile ) ) {
|
334 |
+
$time = $wp_filesystem->mtime( $pidFile );
|
335 |
+
|
336 |
+
$minutes = date( 'i', time() ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
337 |
+
$seconds = date( 's', time() ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
338 |
+
|
339 |
+
$file_minutes = date( 'i', $time ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
340 |
+
$file_seconds = date( 's', $time ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
341 |
+
|
342 |
+
$minuteDiff = $minutes - $file_minutes;
|
343 |
+
if ( 59 === $minuteDiff ) {
|
344 |
+
$minuteDiff = 1;
|
345 |
+
}
|
346 |
+
$secondsdiff = ( $minuteDiff * 60 ) + $seconds - $file_seconds;
|
347 |
+
|
348 |
+
$file = $wp_filesystem->get_contents( $pidFile );
|
349 |
+
$information['file'] = basename( $file );
|
350 |
+
if ( $secondsdiff < 80 ) {
|
351 |
+
$information['status'] = 'busy';
|
352 |
+
} else {
|
353 |
+
$information['status'] = 'stalled';
|
354 |
+
}
|
355 |
+
} elseif ( $wp_filesystem->is_file( $doneFile ) ) {
|
356 |
+
$file = $wp_filesystem->get_contents( $doneFile );
|
357 |
+
$information['status'] = 'done';
|
358 |
+
$information['file'] = basename( $file );
|
359 |
+
$information['size'] = filesize( $file );
|
360 |
+
} else {
|
361 |
+
$information['status'] = 'invalid';
|
362 |
+
}
|
363 |
+
|
364 |
+
MainWP_Helper::write( $information );
|
365 |
+
}
|
366 |
+
|
367 |
+
/**
|
368 |
+
* Perform a backup.
|
369 |
+
*
|
370 |
+
* @param bool $write Whether or not to execute MainWP_Helper::write(), Default: true.
|
371 |
+
*
|
372 |
+
* @uses MainWP_Helper::set_limit() Set PHP Memory Limit and PHP Max Execution time values.
|
373 |
+
* @uses MainWP_Helper::end_session() End session and flush the output buffer.
|
374 |
+
* @uses MainWP_Helper::get_wp_filesystem() Get the WordPress filesystem.
|
375 |
+
* @uses MainWP_Helper::ends_with() Check if the String 1 ends with the String 2.
|
376 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
377 |
+
* @uses MainWP_Backup::backup_full() Perform a full backup.
|
378 |
+
*
|
379 |
+
* @return array Array of information on the backup containing the type of backup performed, full, or DB & whether or not it was successful.
|
380 |
+
*/
|
381 |
+
public function backup( $write = true ) {
|
382 |
+
|
383 |
+
$timeout = 20 * 60 * 60;
|
384 |
+
MainWP_Helper::set_limit( $timeout );
|
385 |
+
|
386 |
+
MainWP_Helper::end_session();
|
387 |
+
|
388 |
+
// Cleanup pid files!
|
389 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
390 |
+
$backupdir = trailingslashit( $dirs[0] );
|
391 |
+
|
392 |
+
/**
|
393 |
+
* WordPress files system object.
|
394 |
+
*
|
395 |
+
* @global object
|
396 |
+
*/
|
397 |
+
global $wp_filesystem;
|
398 |
+
|
399 |
+
MainWP_Helper::get_wp_filesystem();
|
400 |
+
|
401 |
+
$files = glob( $backupdir . '*' );
|
402 |
+
foreach ( $files as $file ) {
|
403 |
+
if ( MainWP_Helper::ends_with( $file, '/index.php' ) | MainWP_Helper::ends_with( $file, '/.htaccess' ) ) {
|
404 |
+
continue;
|
405 |
+
}
|
406 |
+
|
407 |
+
if ( ( time() - filemtime( $file ) ) > ( 60 * 60 * 3 ) ) {
|
408 |
+
unlink( $file );
|
409 |
+
}
|
410 |
+
}
|
411 |
+
|
412 |
+
$fileName = isset( $_POST['fileUID'] ) ? sanitize_text_field( wp_unslash( $_POST['fileUID'] ) ) : '';
|
413 |
+
$type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
|
414 |
+
|
415 |
+
if ( 'full' === $type ) {
|
416 |
+
|
417 |
+
$res = $this->backup_full( $fileName );
|
418 |
+
|
419 |
+
if ( ! $res ) {
|
420 |
+
$information['full'] = false;
|
421 |
+
} else {
|
422 |
+
$information['full'] = $res['file'];
|
423 |
+
$information['size'] = $res['filesize'];
|
424 |
+
}
|
425 |
+
$information['db'] = false;
|
426 |
+
} elseif ( 'db' == $type ) {
|
427 |
+
$ext = isset( $_POST['ext'] ) ? sanitize_text_field( wp_unslash( $_POST['ext'] ) ) : 'zip';
|
428 |
+
$res = $this->backup_db( $fileName, $ext );
|
429 |
+
if ( ! $res ) {
|
430 |
+
$information['db'] = false;
|
431 |
+
} else {
|
432 |
+
$information['db'] = $res['file'];
|
433 |
+
$information['size'] = $res['filesize'];
|
434 |
+
}
|
435 |
+
$information['full'] = false;
|
436 |
+
} else {
|
437 |
+
$information['full'] = false;
|
438 |
+
$information['db'] = false;
|
439 |
+
}
|
440 |
+
|
441 |
+
if ( $write ) {
|
442 |
+
MainWP_Helper::write( $information );
|
443 |
+
}
|
444 |
+
|
445 |
+
return $information;
|
446 |
+
}
|
447 |
+
|
448 |
+
/**
|
449 |
+
* Perform a full backup.
|
450 |
+
*
|
451 |
+
* @param string $fileName Backup archive file name.
|
452 |
+
*
|
453 |
+
* @uses MainWP_Backup::create_full_backup() Create full backup.
|
454 |
+
*
|
455 |
+
* @return array|bool Returns an array containing the Backup location & file size. Return FALSE on failure.
|
456 |
+
*/
|
457 |
+
public function backup_full( $fileName ) {
|
458 |
+
$excludes = ( isset( $_POST['exclude'] ) ? explode( ',', wp_unslash( $_POST['exclude'] ) ) : array() );
|
459 |
+
$excludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/uploads/mainwp';
|
460 |
+
$uploadDir = MainWP_Helper::get_mainwp_dir();
|
461 |
+
$uploadDir = $uploadDir[0];
|
462 |
+
$excludes[] = str_replace( ABSPATH, '', $uploadDir );
|
463 |
+
$excludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/object-cache.php';
|
464 |
+
|
465 |
+
if ( function_exists( 'posix_uname' ) ) {
|
466 |
+
$uname = posix_uname();
|
467 |
+
if ( is_array( $uname ) && isset( $uname['nodename'] ) ) {
|
468 |
+
if ( stristr( $uname['nodename'], 'hostgator' ) ) {
|
469 |
+
if ( ! isset( $_POST['file_descriptors'] ) || '0' == $_POST['file_descriptors'] || $_POST['file_descriptors'] > 1000 ) {
|
470 |
+
$_POST['file_descriptors'] = 1000;
|
471 |
+
}
|
472 |
+
$_POST['file_descriptors_auto'] = 0;
|
473 |
+
$_POST['loadFilesBeforeZip'] = false;
|
474 |
+
}
|
475 |
+
}
|
476 |
+
}
|
477 |
+
|
478 |
+
$file_descriptors = ( isset( $_POST['file_descriptors'] ) ? intval( wp_unslash( $_POST['file_descriptors'] ) ) : 0 );
|
479 |
+
$file_descriptors_auto = ( isset( $_POST['file_descriptors_auto'] ) ? intval( wp_unslash( $_POST['file_descriptors_auto'] ) ) : 0 );
|
480 |
+
if ( 1 === (int) $file_descriptors_auto ) {
|
481 |
+
if ( function_exists( 'posix_getrlimit' ) ) {
|
482 |
+
$result = posix_getrlimit();
|
483 |
+
if ( isset( $result['soft openfiles'] ) ) {
|
484 |
+
$file_descriptors = $result['soft openfiles'];
|
485 |
+
}
|
486 |
+
}
|
487 |
+
}
|
488 |
+
|
489 |
+
$loadFilesBeforeZip = ( isset( $_POST['loadFilesBeforeZip'] ) ? sanitize_text_field( wp_unslash( $_POST['loadFilesBeforeZip'] ) ) : true );
|
490 |
+
|
491 |
+
$newExcludes = array();
|
492 |
+
foreach ( $excludes as $exclude ) {
|
493 |
+
$newExcludes[] = rtrim( $exclude, '/' );
|
494 |
+
}
|
495 |
+
|
496 |
+
$excludebackup = ( isset( $_POST['excludebackup'] ) && '1' == $_POST['excludebackup'] );
|
497 |
+
$excludecache = ( isset( $_POST['excludecache'] ) && '1' == $_POST['excludecache'] );
|
498 |
+
$excludezip = ( isset( $_POST['excludezip'] ) && '1' == $_POST['excludezip'] );
|
499 |
+
$excludenonwp = ( isset( $_POST['excludenonwp'] ) && '1' == $_POST['excludenonwp'] );
|
500 |
+
|
501 |
+
if ( $excludebackup ) {
|
502 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/uploads/backupbuddy_backups';
|
503 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/uploads/backupbuddy_temp';
|
504 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/uploads/pb_backupbuddy';
|
505 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/managewp';
|
506 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/infinitewp';
|
507 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/backups';
|
508 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/backups';
|
509 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/uploads/backwpup*';
|
510 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/plugins/wp-complete-backup/storage';
|
511 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/backups';
|
512 |
+
$newExcludes[] = '/administrator/backups';
|
513 |
+
}
|
514 |
+
|
515 |
+
if ( $excludecache ) {
|
516 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/w3tc-cache';
|
517 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/w3tc';
|
518 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/config';
|
519 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/minify';
|
520 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/page_enhanced';
|
521 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/tmp';
|
522 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/supercache';
|
523 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/quick-cache';
|
524 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/hyper-cache/cache';
|
525 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/all';
|
526 |
+
$newExcludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/cache/wp-rocket';
|
527 |
+
}
|
528 |
+
|
529 |
+
$file = false;
|
530 |
+
if ( isset( $_POST['f'] ) ) {
|
531 |
+
$file = ! empty( $_POST['f'] ) ? wp_unslash( $_POST['f'] ) : false;
|
532 |
+
} elseif ( isset( $_POST['file'] ) ) {
|
533 |
+
$file = ! empty( $_POST['file'] ) ? wp_unslash( $_POST['file'] ) : false;
|
534 |
+
}
|
535 |
+
|
536 |
+
$ext = isset( $_POST['ext'] ) ? sanitize_text_field( wp_unslash( $_POST['ext'] ) ) : 'zip';
|
537 |
+
$pid = isset( $_POST['pid'] ) ? sanitize_text_field( wp_unslash( $_POST['pid'] ) ) : false;
|
538 |
+
|
539 |
+
$append = ( isset( $_POST['append'] ) && ( '1' == $_POST['append'] ) );
|
540 |
+
return $this->create_full_backup( $newExcludes, $fileName, true, true, $file_descriptors, $file, $excludezip, $excludenonwp, $loadFilesBeforeZip, $ext, $pid, $append );
|
541 |
+
}
|
542 |
+
|
543 |
+
/**
|
544 |
+
* Backup site database.
|
545 |
+
*
|
546 |
+
* @param string $fileName Backup arhive file name.
|
547 |
+
* @param string $ext Backup achive extension.
|
548 |
+
*
|
549 |
+
* @uses MainWP_Helper::update_option() Update database option by option name.
|
550 |
+
* @uses MainWP_Helper::get_mainwp_dir() Get the MainWP directory.
|
551 |
+
* @uses MainWP_Backup::create_backup_db() Create database backup.
|
552 |
+
*
|
553 |
+
* @return array|bool $success Returns an array containing the Backup location & file size. Return FALSE on failure.
|
554 |
+
*/
|
555 |
+
public function backup_db( $fileName = '', $ext = 'zip' ) {
|
556 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
557 |
+
$dir = $dirs[0];
|
558 |
+
$timestamp = time();
|
559 |
+
|
560 |
+
if ( '' !== $fileName ) {
|
561 |
+
$fileName .= '-';
|
562 |
+
}
|
563 |
+
|
564 |
+
$filepath_prefix = $dir . 'dbBackup-' . $fileName . $timestamp;
|
565 |
+
|
566 |
+
$dh = opendir( $dir );
|
567 |
+
|
568 |
+
if ( $dh ) {
|
569 |
+
while ( ( $file = readdir( $dh ) ) !== false ) {
|
570 |
+
if ( '.' !== $file && '..' !== $file && ( preg_match( '/dbBackup-(.*).sql(\.zip|\.tar|\.tar\.gz|\.tar\.bz2|\.tmp)?$/', $file ) ) ) {
|
571 |
+
unlink( $dir . $file );
|
572 |
+
}
|
573 |
+
}
|
574 |
+
closedir( $dh );
|
575 |
+
}
|
576 |
+
|
577 |
+
$result = $this->create_backup_db( $filepath_prefix, $ext );
|
578 |
+
|
579 |
+
MainWP_Helper::update_option( 'mainwp_child_last_db_backup_size', filesize( $result['filepath'] ) );
|
580 |
+
|
581 |
+
return ( ! $result ) ? false : array(
|
582 |
+
'timestamp' => $timestamp,
|
583 |
+
'file' => basename( $result['filepath'] ),
|
584 |
+
'filesize' => filesize( $result['filepath'] ),
|
585 |
+
);
|
586 |
+
}
|
587 |
+
|
588 |
+
/**
|
589 |
+
* Create the ZIP file.
|
590 |
+
*
|
591 |
+
* @param array $files Files to zip.
|
592 |
+
* @param string $archive Type of archive to create.
|
593 |
+
*
|
594 |
+
* @uses MainWP_Helper::set_limit() Set PHP memory limit.
|
595 |
+
*
|
596 |
+
* @return bool Return FALSE on failure, TRUE on success.
|
597 |
+
*/
|
598 |
+
public function zip_file( $files, $archive ) {
|
599 |
+
$this->timeout = 20 * 60 * 60;
|
600 |
$mem = '512M';
|
601 |
+
MainWP_Helper::set_limit( $this->timeout, $mem );
|
|
|
|
|
|
|
|
|
602 |
|
603 |
+
if ( ! is_array( $files ) ) {
|
604 |
+
$files = array( $files );
|
605 |
}
|
606 |
|
607 |
if ( null !== $this->archiver ) {
|
608 |
+
$success = $this->archiver->zip_file( $files, $archive );
|
609 |
+
} elseif ( $this->check_zip_support() ) {
|
610 |
+
$success = $this->m_zip_file( $files, $archive );
|
611 |
+
} elseif ( $this->check_zip_console() ) {
|
612 |
+
$success = $this->m_zip_file_console( $files, $archive );
|
613 |
} else {
|
614 |
+
$success = $this->m_zip_file_pcl( $files, $archive );
|
615 |
}
|
616 |
|
617 |
return $success;
|
618 |
}
|
619 |
|
620 |
+
/**
|
621 |
+
* Create m_zip_file.
|
622 |
+
*
|
623 |
+
* @param array $files Files to zip.
|
624 |
+
* @param string $archive Type of archive to create.
|
625 |
+
*
|
626 |
+
* @return bool Return false on failure.
|
627 |
+
*/
|
628 |
+
public function m_zip_file( $files, $archive ) {
|
629 |
+
$this->zip = new \ZipArchive();
|
630 |
$this->zipArchiveFileCount = 0;
|
631 |
$this->zipArchiveSizeCount = 0;
|
632 |
|
633 |
+
$zipRes = $this->zip->open( $archive, \ZipArchive::CREATE );
|
634 |
if ( $zipRes ) {
|
635 |
foreach ( $files as $file ) {
|
636 |
+
$this->add_fileToZip( $file, basename( $file ) );
|
637 |
}
|
638 |
|
639 |
return $this->zip->close();
|
642 |
return false;
|
643 |
}
|
644 |
|
645 |
+
/**
|
646 |
+
* Method m_zip_file_console().
|
647 |
+
*
|
648 |
+
* @param array $files Files to zip.
|
649 |
+
* @param string $archive Type of archive to create.
|
650 |
+
*
|
651 |
+
* @return bool Return false.
|
652 |
+
*/
|
653 |
+
public function m_zip_file_console( $files, $archive ) {
|
654 |
return false;
|
655 |
}
|
656 |
|
657 |
+
/**
|
658 |
+
* Use pclzip to add files to the zip archive.
|
659 |
+
*
|
660 |
+
* @param array $files Files to zip.
|
661 |
+
* @param string $archive Type of archive to create.
|
662 |
+
*
|
663 |
+
* @return array $rslt Return array of results.
|
664 |
+
*/
|
665 |
+
public function m_zip_file_pcl( $files, $archive ) {
|
666 |
+
// Zip this backup folder.
|
667 |
+
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
|
668 |
+
$this->zip = new \PclZip( $archive );
|
669 |
|
670 |
$error = false;
|
671 |
foreach ( $files as $file ) {
|
672 |
+
$rslt = $this->zip->add( $file, PCLZIP_OPT_REMOVE_PATH, dirname( $file ) );
|
673 |
+
if ( 0 === $rslt ) {
|
674 |
$error = true;
|
675 |
}
|
676 |
}
|
677 |
|
678 |
+
return ! $error;
|
679 |
}
|
680 |
|
681 |
/**
|
682 |
+
* Check for default PHP zip support.
|
683 |
*
|
684 |
+
* @return bool Returns true if class_name is a defined class, false otherwise.
|
685 |
*/
|
686 |
+
public function check_zip_support() {
|
687 |
+
return class_exists( '\ZipArchive' );
|
688 |
}
|
689 |
|
690 |
/**
|
691 |
* Check if we could run zip on console
|
692 |
*
|
693 |
+
* @return bool Return false.
|
694 |
*/
|
695 |
+
public function check_zip_console() {
|
696 |
return false;
|
|
|
697 |
}
|
698 |
|
699 |
/**
|
700 |
+
* Create full backup using default PHP zip library.
|
701 |
*
|
702 |
+
* @param string $filepath File path to create.
|
703 |
+
* @param array $excludes Files to exclude from the backup.
|
704 |
+
* @param bool $addConfig Add config file to backup.
|
705 |
+
* @param bool $includeCoreFiles Include WordPress core files.
|
706 |
+
* @param bool $excludezip Exclude zip files from the backup.
|
707 |
+
* @param bool $excludenonwp Exclude non-WordPress directories in site root.
|
708 |
*
|
709 |
+
* @uses MainWP_Helper::starts_with() Check if the String 1 starts with the String 2.
|
710 |
+
* @uses MainWP_Helper::in_excludes() Check if the value is in the excludes list.
|
711 |
+
* @uses MainWP_Backup::include_core_files() Include core files in backup.
|
712 |
+
* @uses MainWP_Backup::add_config() Add config file to backup.
|
713 |
+
*
|
714 |
+
* @return bool Return true on success & false on failure.
|
715 |
*/
|
716 |
+
public function create_zip_full_backup(
|
717 |
+
$filepath,
|
718 |
+
$excludes,
|
719 |
+
$addConfig,
|
720 |
+
$includeCoreFiles,
|
721 |
+
$excludezip,
|
722 |
+
$excludenonwp ) {
|
723 |
+
|
724 |
$this->excludeZip = $excludezip;
|
725 |
+
$this->zip = new \ZipArchive();
|
726 |
$this->zipArchiveFileCount = 0;
|
727 |
$this->zipArchiveSizeCount = 0;
|
728 |
$this->zipArchiveFileName = $filepath;
|
729 |
+
$zipRes = $this->zip->open( $filepath, \ZipArchive::CREATE );
|
730 |
if ( $zipRes ) {
|
731 |
$nodes = glob( ABSPATH . '*' );
|
732 |
if ( ! $includeCoreFiles ) {
|
733 |
+
$this->include_core_files( $nodes );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
734 |
}
|
735 |
|
736 |
+
$db_files = $this->create_backup_db( dirname( $filepath ) . DIRECTORY_SEPARATOR . 'dbBackup' );
|
737 |
foreach ( $db_files as $db_file ) {
|
738 |
+
$this->add_file_to_zipp( $db_file, basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) );
|
739 |
}
|
740 |
|
741 |
if ( file_exists( ABSPATH . '.htaccess' ) ) {
|
742 |
+
$this->add_file_to_zipp( ABSPATH . '.htaccess', 'mainwp-htaccess' );
|
743 |
}
|
744 |
|
745 |
foreach ( $nodes as $node ) {
|
746 |
if ( $excludenonwp && is_dir( $node ) ) {
|
747 |
+
if ( ! MainWP_Helper::starts_with( $node, WP_CONTENT_DIR ) && ! MainWP_Helper::starts_with( $node, ABSPATH . 'wp-admin' ) && ! MainWP_Helper::starts_with( $node, ABSPATH . WPINC ) ) {
|
748 |
continue;
|
749 |
}
|
750 |
}
|
751 |
|
752 |
+
if ( ! MainWP_Helper::in_excludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) {
|
753 |
if ( is_dir( $node ) ) {
|
754 |
+
$this->zip_add_dir( $node, $excludes );
|
755 |
+
} elseif ( is_file( $node ) ) {
|
756 |
+
$this->add_file_to_zipp( $node, str_replace( ABSPATH, '', $node ) );
|
757 |
}
|
758 |
}
|
759 |
}
|
760 |
|
761 |
if ( $addConfig ) {
|
762 |
+
$this->add_config();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
763 |
}
|
764 |
|
765 |
$return = $this->zip->close();
|
766 |
foreach ( $db_files as $db_file ) {
|
767 |
+
unlink( $db_file );
|
768 |
}
|
769 |
|
770 |
return true;
|
774 |
}
|
775 |
|
776 |
/**
|
777 |
+
* Exclude certain core files from the backup.
|
778 |
*
|
779 |
+
* @param array $nodes Default nodes.
|
780 |
*
|
781 |
+
* @uses MainWP_Helper::starts_with() Check if the String 1 starts with the String 2.
|
782 |
*/
|
783 |
+
private function include_core_files( &$nodes ) {
|
784 |
+
$coreFiles = array(
|
785 |
+
'favicon.ico',
|
786 |
+
'index.php',
|
787 |
+
'license.txt',
|
788 |
+
'readme.html',
|
789 |
+
'wp-activate.php',
|
790 |
+
'wp-app.php',
|
791 |
+
'wp-blog-header.php',
|
792 |
+
'wp-comments-post.php',
|
793 |
+
'wp-config.php',
|
794 |
+
'wp-config-sample.php',
|
795 |
+
'wp-cron.php',
|
796 |
+
'wp-links-opml.php',
|
797 |
+
'wp-load.php',
|
798 |
+
'wp-login.php',
|
799 |
+
'wp-mail.php',
|
800 |
+
'wp-pass.php',
|
801 |
+
'wp-register.php',
|
802 |
+
'wp-settings.php',
|
803 |
+
'wp-signup.php',
|
804 |
+
'wp-trackback.php',
|
805 |
+
'xmlrpc.php',
|
806 |
+
);
|
807 |
+
foreach ( $nodes as $key => $node ) {
|
808 |
+
if ( MainWP_Helper::starts_with( $node, ABSPATH . WPINC ) ) {
|
809 |
+
unset( $nodes[ $key ] );
|
810 |
+
} elseif ( MainWP_Helper::starts_with( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
|
811 |
+
unset( $nodes[ $key ] );
|
812 |
+
} else {
|
813 |
+
foreach ( $coreFiles as $coreFile ) {
|
814 |
+
if ( ABSPATH . $coreFile === $node ) {
|
815 |
+
unset( $nodes[ $key ] );
|
|
|
|
|
|
|
|
|
|
|
816 |
}
|
817 |
}
|
818 |
}
|
|
|
819 |
}
|
820 |
+
unset( $coreFiles );
|
821 |
+
}
|
822 |
|
823 |
+
/**
|
824 |
+
* Add config file to backup.
|
825 |
+
*
|
826 |
+
* @uses wp_json_encode() Encode a variable into JSON, with some sanity checks.
|
827 |
+
* @see https://developer.wordpress.org/reference/functions/wp_json_encode/
|
828 |
+
*
|
829 |
+
* @uses get_option() Get option by name.
|
830 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
831 |
+
*/
|
832 |
+
public function add_config() {
|
833 |
|
834 |
+
/**
|
835 |
+
* WordPress Database instance.
|
836 |
+
*
|
837 |
+
* @global object $wpdb
|
838 |
+
*/
|
839 |
+
global $wpdb;
|
840 |
+
|
841 |
+
$plugins = array();
|
842 |
+
$dir = WP_CONTENT_DIR . '/plugins/';
|
843 |
+
$fh = opendir( $dir );
|
844 |
+
while ( $entry = readdir( $fh ) ) {
|
845 |
+
if ( ! is_dir( $dir . $entry ) ) {
|
846 |
+
continue;
|
847 |
+
}
|
848 |
+
if ( ( '.' == $entry ) || ( '..' == $entry ) ) {
|
849 |
+
continue;
|
|
|
|
|
850 |
}
|
851 |
+
$plugins[] = $entry;
|
852 |
}
|
853 |
+
closedir( $fh );
|
854 |
|
855 |
+
$themes = array();
|
856 |
+
$dir = WP_CONTENT_DIR . '/themes/';
|
857 |
+
$fh = opendir( $dir );
|
858 |
+
while ( $entry = readdir( $fh ) ) {
|
859 |
+
if ( ! is_dir( $dir . $entry ) ) {
|
860 |
+
continue;
|
861 |
+
}
|
862 |
+
if ( ( '.' == $entry ) || ( '..' == $entry ) ) {
|
863 |
+
continue;
|
864 |
+
}
|
865 |
+
$themes[] = $entry;
|
866 |
}
|
867 |
+
closedir( $fh );
|
868 |
|
869 |
+
if ( defined( 'MAINWP_CHILD_DEBUG' ) && MAINWP_CHILD_DEBUG ) {
|
870 |
+
$string = wp_json_encode(
|
871 |
+
array(
|
872 |
+
'siteurl' => get_option( 'siteurl' ),
|
873 |
+
'home' => get_option( 'home' ),
|
874 |
+
'abspath' => ABSPATH,
|
875 |
+
'prefix' => $wpdb->prefix,
|
876 |
+
'lang' => defined( 'WPLANG' ) ? WPLANG : '',
|
877 |
+
'plugins' => $plugins,
|
878 |
+
'themes' => $themes,
|
879 |
+
)
|
880 |
+
);
|
881 |
+
} else {
|
882 |
+
$string = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- Safe requst, required for backwards compatibility.
|
883 |
+
serialize( // phpcs:ignore -- Safe requst, required for backwards compatibility.
|
884 |
+
array(
|
885 |
+
'siteurl' => get_option( 'siteurl' ),
|
886 |
+
'home' => get_option( 'home' ),
|
887 |
+
'abspath' => ABSPATH,
|
888 |
+
'prefix' => $wpdb->prefix,
|
889 |
+
'lang' => defined( 'WPLANG' ) ? WPLANG : '',
|
890 |
+
'plugins' => $plugins,
|
891 |
+
'themes' => $themes,
|
892 |
+
)
|
893 |
+
)
|
894 |
+
);
|
895 |
}
|
896 |
|
897 |
+
$this->add_file_from_string_to_zip( 'clone/config.txt', $string );
|
898 |
}
|
899 |
|
900 |
+
/**
|
901 |
+
* Copy directory.
|
902 |
+
*
|
903 |
+
* @param array $nodes Default nodes.
|
904 |
+
* @param array $excludes Files & directories to exclude.
|
905 |
+
* @param string $backupfolder Backup folder.
|
906 |
+
* @param bool $excludenonwp Whether or not to exclude any wp core files.
|
907 |
+
*
|
908 |
+
* @uses MainWP_Helper::starts_with() Check if the String 1 starts with the String 2.
|
909 |
+
* @uses MainWP_Helper::in_excludes() Check if the value is in the excludes list.
|
910 |
+
* @uses MainWP_Helper::ends_with() Check if the String 1 ends with the String 2.
|
911 |
+
*/
|
912 |
+
public function copy_dir( $nodes, $excludes, $backupfolder, $excludenonwp ) {
|
913 |
if ( ! is_array( $nodes ) ) {
|
914 |
return;
|
915 |
}
|
916 |
|
917 |
foreach ( $nodes as $node ) {
|
918 |
if ( $excludenonwp && is_dir( $node ) ) {
|
919 |
+
if ( ! MainWP_Helper::starts_with( $node, WP_CONTENT_DIR ) && ! MainWP_Helper::starts_with( $node, ABSPATH . 'wp-admin' ) && ! MainWP_Helper::starts_with( $node, ABSPATH . WPINC ) ) {
|
920 |
continue;
|
921 |
}
|
922 |
}
|
923 |
|
924 |
+
if ( ! MainWP_Helper::in_excludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) {
|
925 |
if ( is_dir( $node ) ) {
|
926 |
if ( ! file_exists( str_replace( ABSPATH, $backupfolder, $node ) ) ) {
|
927 |
+
mkdir( str_replace( ABSPATH, $backupfolder, $node ) ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
|
|
|
|
928 |
}
|
929 |
|
930 |
$newnodes = glob( $node . DIRECTORY_SEPARATOR . '*' );
|
931 |
$this->copy_dir( $newnodes, $excludes, $backupfolder, $excludenonwp, false );
|
932 |
unset( $newnodes );
|
933 |
+
} elseif ( is_file( $node ) ) {
|
934 |
+
if ( $this->excludeZip && MainWP_Helper::ends_with( $node, '.zip' ) ) {
|
935 |
continue;
|
936 |
}
|
937 |
|
938 |
+
copy( $node, str_replace( ABSPATH, $backupfolder, $node ) ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
|
|
|
|
939 |
}
|
940 |
}
|
941 |
}
|
942 |
}
|
943 |
|
944 |
+
/**
|
945 |
+
* Create PCL zip full backup 2.
|
946 |
+
*
|
947 |
+
* @param string $filepath Path to file.
|
948 |
+
* @param array $excludes Files & directories to exclude.
|
949 |
+
* @param bool $addConfig Add config file to backup.
|
950 |
+
* @param bool $includeCoreFiles Whether to include core files.
|
951 |
+
* @param bool $excludezip Whether to exclude zip archives.
|
952 |
+
* @param bool $excludenonwp Whether or not to exclude any wp core files.
|
953 |
+
*
|
954 |
+
* @uses MainWP_Helper::delete_dir() Delete wanted directory.
|
955 |
+
* @uses MainWP_Helper::starts_with() Check if the String 1 starts with the String 2.
|
956 |
+
* @uses MainWP_Backup::create_backup_db() Create database backup.
|
957 |
+
* @uses MainWP_Backup::add_file_from_string_to_pcl_zip() Add file from a string to pclzip file.
|
958 |
+
*
|
959 |
+
* @uses wp_json_encode() Encode a variable into JSON, with some sanity checks.
|
960 |
+
* @see https://developer.wordpress.org/reference/functions/wp_json_encode/
|
961 |
+
*
|
962 |
+
* @uses get_option() Get option by name.
|
963 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
964 |
+
*
|
965 |
+
* @return bool Return true on success.
|
966 |
+
*/
|
967 |
+
public function create_zip_pcl_full_backup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) {
|
968 |
+
// Create backup folder.
|
969 |
$backupFolder = dirname( $filepath ) . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR;
|
|
|
|
|
|
|
970 |
|
971 |
+
mkdir( $backupFolder ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
|
|
972 |
|
973 |
+
// Create DB backup.
|
974 |
+
$db_files = $this->create_backup_db( $backupFolder . 'dbBackup' );
|
975 |
+
|
976 |
+
// Copy installation to backup folder.
|
977 |
$nodes = glob( ABSPATH . '*' );
|
978 |
if ( ! $includeCoreFiles ) {
|
979 |
$coreFiles = array(
|
1000 |
'xmlrpc.php',
|
1001 |
);
|
1002 |
foreach ( $nodes as $key => $node ) {
|
1003 |
+
if ( MainWP_Helper::starts_with( $node, ABSPATH . WPINC ) ) {
|
1004 |
unset( $nodes[ $key ] );
|
1005 |
+
} elseif ( MainWP_Helper::starts_with( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
|
1006 |
unset( $nodes[ $key ] );
|
1007 |
} else {
|
1008 |
foreach ( $coreFiles as $coreFile ) {
|
1015 |
unset( $coreFiles );
|
1016 |
}
|
1017 |
$this->copy_dir( $nodes, $excludes, $backupFolder, $excludenonwp, true );
|
|
|
|
|
1018 |
|
1019 |
foreach ( $db_files as $db_file ) {
|
1020 |
+
copy( $db_file, $backupFolder . basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
1021 |
+
unlink( $db_file ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
1022 |
}
|
1023 |
+
|
1024 |
unset( $nodes );
|
1025 |
|
1026 |
+
// Zip this backup folder.
|
1027 |
+
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
|
1028 |
+
$this->zip = new \PclZip( $filepath );
|
1029 |
$this->zip->create( $backupFolder, PCLZIP_OPT_REMOVE_PATH, $backupFolder );
|
1030 |
if ( $addConfig ) {
|
1031 |
+
|
1032 |
+
/**
|
1033 |
+
* WordPress Database instance.
|
1034 |
+
*
|
1035 |
+
* @global object $wpdb
|
1036 |
+
*/
|
1037 |
global $wpdb;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1038 |
|
1039 |
+
if ( defined( 'MAINWP_CHILD_DEBUG' ) && MAINWP_CHILD_DEBUG ) {
|
1040 |
+
$string = wp_json_encode(
|
1041 |
+
array(
|
1042 |
+
'siteurl' => get_option( 'siteurl' ),
|
1043 |
+
'home' => get_option( 'home' ),
|
1044 |
+
'abspath' => ABSPATH,
|
1045 |
+
'prefix' => $wpdb->prefix,
|
1046 |
+
'lang' => WPLANG,
|
1047 |
+
)
|
1048 |
+
);
|
1049 |
+
} else {
|
1050 |
+
$string = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- Safe requst, required for backwards compatibility.
|
1051 |
+
serialize( // phpcs:ignore -- Safe requst, required for backwards compatibility.
|
1052 |
+
array(
|
1053 |
+
'siteurl' => get_option( 'siteurl' ),
|
1054 |
+
'home' => get_option( 'home' ),
|
1055 |
+
'abspath' => ABSPATH,
|
1056 |
+
'prefix' => $wpdb->prefix,
|
1057 |
+
'lang' => WPLANG,
|
1058 |
+
)
|
1059 |
+
)
|
1060 |
+
);
|
1061 |
+
}
|
1062 |
+
|
1063 |
+
$this->add_file_from_string_to_pcl_zip( 'clone/config.txt', $string, $filepath );
|
1064 |
}
|
1065 |
+
// Remove backup folder.
|
1066 |
MainWP_Helper::delete_dir( $backupFolder );
|
1067 |
|
1068 |
return true;
|
1069 |
}
|
1070 |
|
1071 |
/**
|
1072 |
+
* Recursively add directory to default PHP zip library.
|
1073 |
+
*
|
1074 |
+
* @param string $path Path to directory.
|
1075 |
+
* @param array $excludes Files or directories to exclude.
|
1076 |
+
*
|
1077 |
+
* @uses MainWP_Helper::in_excludes() Check if the value is in the excludes list.
|
1078 |
*/
|
1079 |
+
public function zip_add_dir( $path, $excludes ) {
|
1080 |
+
$this->zip->add_empty_dir( str_replace( ABSPATH, '', $path ) );
|
1081 |
|
1082 |
if ( file_exists( rtrim( $path, '/' ) . '/.htaccess' ) ) {
|
1083 |
+
$this->add_file_to_zipp( rtrim( $path, '/' ) . '/.htaccess', rtrim( str_replace( ABSPATH, '', $path ), '/' ) . '/mainwp-htaccess' );
|
1084 |
}
|
1085 |
|
1086 |
+
$iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $path ), \RecursiveIteratorIterator::SELF_FIRST );
|
1087 |
|
1088 |
foreach ( $iterator as $path ) {
|
1089 |
$name = $path->__toString();
|
1091 |
continue;
|
1092 |
}
|
1093 |
|
1094 |
+
if ( ! MainWP_Helper::in_excludes( $excludes, str_replace( ABSPATH, '', $name ) ) ) {
|
1095 |
if ( $path->isDir() ) {
|
1096 |
+
$this->zip_add_dir( $name, $excludes );
|
1097 |
} else {
|
1098 |
+
$this->add_file_to_zipp( $name, str_replace( ABSPATH, '', $name ) );
|
1099 |
}
|
1100 |
}
|
1101 |
$name = null;
|
1104 |
|
1105 |
$iterator = null;
|
1106 |
unset( $iterator );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1107 |
}
|
1108 |
|
1109 |
+
/**
|
1110 |
+
* Add file from a string to zip file.
|
1111 |
+
*
|
1112 |
+
* @param resource $file File to add to zip.
|
1113 |
+
* @param string $string String to add.
|
1114 |
+
*
|
1115 |
+
* @return bool true|false.
|
1116 |
+
*/
|
1117 |
+
public function add_file_from_string_to_zip( $file, $string ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1118 |
return $this->zip->addFromString( $file, $string );
|
1119 |
}
|
1120 |
|
1121 |
+
/**
|
1122 |
+
* Add file from a string to pclzip file.
|
1123 |
+
*
|
1124 |
+
* @param resource $file File to add to zip.
|
1125 |
+
* @param string $string String to add.
|
1126 |
+
* @param string $filepath Path to file.
|
1127 |
+
*
|
1128 |
+
* @return bool true|false.
|
1129 |
+
*/
|
1130 |
+
public function add_file_from_string_to_pcl_zip( $file, $string, $filepath ) {
|
1131 |
$file = preg_replace( '/(?:\.|\/)*(.*)/', '$1', $file );
|
1132 |
$localpath = dirname( $file );
|
1133 |
$tmpfilename = dirname( $filepath ) . '/' . basename( $file );
|
1134 |
if ( false !== file_put_contents( $tmpfilename, $string ) ) {
|
1135 |
$this->zip->delete( PCLZIP_OPT_BY_NAME, $file );
|
1136 |
+
$add = $this->zip->add(
|
1137 |
+
$tmpfilename,
|
1138 |
+
PCLZIP_OPT_REMOVE_PATH,
|
1139 |
+
dirname( $filepath ),
|
1140 |
+
PCLZIP_OPT_ADD_PATH,
|
1141 |
+
$localpath
|
1142 |
+
);
|
1143 |
unlink( $tmpfilename );
|
1144 |
if ( ! empty( $add ) ) {
|
1145 |
return true;
|
1149 |
return false;
|
1150 |
}
|
1151 |
|
1152 |
+
/**
|
1153 |
+
* Add file to zip.
|
1154 |
+
*
|
1155 |
+
* @param string $path Path to zip file.
|
1156 |
+
* @param string $zipEntryName File to add to zip.
|
1157 |
+
*
|
1158 |
+
* @return bool True|false.
|
1159 |
+
*/
|
1160 |
+
public function add_file_to_zipp( $path, $zipEntryName ) {
|
1161 |
if ( time() - $this->lastRun > 20 ) {
|
1162 |
+
set_time_limit( $this->timeout ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
|
|
|
|
1163 |
$this->lastRun = time();
|
1164 |
}
|
1165 |
|
1166 |
+
if ( $this->excludeZip && MainWP_Helper::ends_with( $path, '.zip' ) ) {
|
1167 |
return false;
|
1168 |
}
|
1169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1170 |
$this->zipArchiveSizeCount += filesize( $path );
|
1171 |
$this->gcCnt ++;
|
1172 |
|
|
|
1173 |
if ( ! $this->loadFilesBeforeZip || ( filesize( $path ) > 5 * 1024 * 1024 ) ) {
|
1174 |
$this->zipArchiveFileCount ++;
|
1175 |
+
$added = $this->zip->add_file( $path, $zipEntryName );
|
1176 |
} else {
|
1177 |
$this->zipArchiveFileCount ++;
|
1178 |
|
1179 |
$this->testContent = file_get_contents( $path );
|
1180 |
+
if ( false === $this->testContent ) {
|
1181 |
return false;
|
1182 |
}
|
1183 |
$added = $this->zip->addFromString( $zipEntryName, $this->testContent );
|
1184 |
}
|
1185 |
|
1186 |
if ( $this->gcCnt > 20 ) {
|
|
|
1187 |
if ( function_exists( 'gc_enable' ) ) {
|
1188 |
+
gc_enable();
|
1189 |
}
|
1190 |
if ( function_exists( 'gc_collect_cycles' ) ) {
|
1191 |
+
gc_collect_cycles();
|
1192 |
}
|
|
|
1193 |
$this->gcCnt = 0;
|
1194 |
}
|
1195 |
|
1196 |
+
if ( ( ( $this->file_descriptors > 0 ) && ( $this->zipArchiveFileCount > $this->file_descriptors ) ) ) {
|
|
|
1197 |
$this->zip->close();
|
1198 |
$this->zip = null;
|
1199 |
unset( $this->zip );
|
|
|
1200 |
if ( function_exists( 'gc_enable' ) ) {
|
1201 |
+
gc_enable();
|
1202 |
}
|
1203 |
if ( function_exists( 'gc_collect_cycles' ) ) {
|
1204 |
+
gc_collect_cycles();
|
1205 |
}
|
1206 |
+
$this->zip = new \ZipArchive();
|
|
|
1207 |
$this->zip->open( $this->zipArchiveFileName );
|
1208 |
$this->zipArchiveFileCount = 0;
|
1209 |
$this->zipArchiveSizeCount = 0;
|
1212 |
return $added;
|
1213 |
}
|
1214 |
|
1215 |
+
/**
|
1216 |
+
* Create full backup via console.
|
1217 |
+
*
|
1218 |
+
* @param string $filepath Path to file.
|
1219 |
+
* @param array $excludes Files & directories to exclude.
|
1220 |
+
* @param bool $addConfig Add config file to backup.
|
1221 |
+
* @param bool $includeCoreFiles Whether to include core files.
|
1222 |
+
* @param bool $excludezip Whether to exclude zip archives.
|
1223 |
+
* @param bool $excludenonwp Whether or not to exclude any wp core files.
|
1224 |
+
*
|
1225 |
+
* @return bool Return false.
|
1226 |
+
*/
|
1227 |
+
public function create_zip_console_full_backup(
|
1228 |
+
$filepath,
|
1229 |
+
$excludes,
|
1230 |
+
$addConfig,
|
1231 |
+
$includeCoreFiles,
|
1232 |
+
$excludezip,
|
1233 |
+
$excludenonwp ) {
|
1234 |
+
|
1235 |
return false;
|
1236 |
}
|
1237 |
|
1238 |
+
/**
|
1239 |
+
* Create DB backup.
|
1240 |
+
*
|
1241 |
+
* @param string $filepath_prefix File path prefix.
|
1242 |
+
* @param string $archiveExt Archive extension.
|
1243 |
+
* @param object $archiver Archiver.
|
1244 |
+
*
|
1245 |
+
* @uses MainWP_Helper::sanitize_filename() Sanitize filename.
|
1246 |
+
* @uses MainWP_Helper::set_limit() Set PHP memory limit.
|
1247 |
+
* @uses MainWP_Child_DB::to_query() Run a mysqli query & get a result.
|
1248 |
+
*
|
1249 |
+
* @uses wpdb::get_results() Retrieve an entire SQL result set from the database (i.e., many rows).
|
1250 |
+
* @see https://developer.wordpress.org/reference/classes/wpdb/get_results/
|
1251 |
+
*
|
1252 |
+
* @uses wpdb::get_row() Retrieve one row from the database.
|
1253 |
+
* @see https://developer.wordpress.org/reference/classes/wpdb/get_row/
|
1254 |
+
*
|
1255 |
+
* @return array Action response.
|
1256 |
+
*/
|
1257 |
+
public function create_backup_db( $filepath_prefix, $archiveExt = false, &$archiver = null ) {
|
1258 |
+
|
1259 |
+
$timeout = 20 * 60 * 60;
|
1260 |
+
$mem = '512M';
|
1261 |
+
MainWP_Helper::set_limit( $timeout, $mem );
|
1262 |
|
1263 |
+
/**
|
1264 |
+
* WordPress Database instance.
|
1265 |
+
*
|
1266 |
+
* @global object $wpdb
|
1267 |
+
*/
|
1268 |
global $wpdb;
|
1269 |
|
1270 |
+
$db_files = array();
|
1271 |
+
$tables_db = $wpdb->get_results( 'SHOW TABLES FROM `' . DB_NAME . '`', ARRAY_N ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
|
|
1272 |
foreach ( $tables_db as $curr_table ) {
|
1273 |
if ( null !== $archiver ) {
|
1274 |
+
$archiver->update_pid_file();
|
1275 |
}
|
1276 |
|
1277 |
$table = $curr_table[0];
|
1278 |
|
1279 |
$currentfile = $filepath_prefix . '-' . MainWP_Helper::sanitize_filename( $table ) . '.sql';
|
1280 |
+
$db_files[] = $currentfile;
|
1281 |
if ( file_exists( $currentfile ) ) {
|
1282 |
continue;
|
1283 |
}
|
1284 |
+
$fh = fopen( $currentfile . '.tmp', 'w' );
|
1285 |
|
1286 |
fwrite( $fh, "\n\n" . 'DROP TABLE IF EXISTS ' . $table . ';' );
|
1287 |
+
$table_create = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
|
|
|
|
1288 |
fwrite( $fh, "\n" . $table_create[1] . ";\n\n" );
|
1289 |
|
1290 |
+
$rows = MainWP_Child_DB::to_query( 'SELECT * FROM ' . $table, $wpdb->dbh ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated.
|
|
|
|
|
1291 |
|
1292 |
if ( $rows ) {
|
1293 |
$i = 0;
|
1294 |
$table_insert = 'INSERT INTO `' . $table . '` VALUES (';
|
1295 |
|
1296 |
// @codingStandardsIgnoreStart
|
1297 |
+
while ( $row = MainWP_Child_DB::fetch_array( $rows ) ) {
|
1298 |
// @codingStandardsIgnoreEnd
|
1299 |
$query = $table_insert;
|
1300 |
foreach ( $row as $value ) {
|
1301 |
+
if ( null === $value ) {
|
1302 |
$query .= 'NULL, ';
|
1303 |
} else {
|
1304 |
$query .= '"' . MainWP_Child_DB::real_escape_string( $value ) . '", ';
|
1306 |
}
|
1307 |
$query = trim( $query, ', ' ) . ');';
|
1308 |
|
1309 |
+
fwrite( $fh, "\n" . $query ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
1310 |
$i ++;
|
1311 |
|
1312 |
if ( $i >= 50 ) {
|
1320 |
}
|
1321 |
$rows = null;
|
1322 |
fflush( $fh );
|
1323 |
+
fclose( $fh ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
1324 |
rename( $currentfile . '.tmp', $currentfile );
|
1325 |
}
|
1326 |
|
1327 |
+
fclose( fopen( $filepath_prefix . '.sql', 'w' ) ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
1328 |
$db_files[] = $filepath_prefix . '.sql';
|
1329 |
|
1330 |
$archivefilePath = null;
|
1337 |
$this->archiver = new Tar_Archiver( $this, $archiveExt );
|
1338 |
}
|
1339 |
|
1340 |
+
if ( $this->zip_file( $db_files, $archivefilePath ) && file_exists( $archivefilePath ) ) {
|
1341 |
foreach ( $db_files as $db_file ) {
|
1342 |
+
unlink( $db_file );
|
1343 |
}
|
|
|
|
|
1344 |
}
|
1345 |
}
|
1346 |
|
|
|
1347 |
return ( false !== $archiveExt ? array( 'filepath' => $archivefilePath ) : $db_files );
|
1348 |
}
|
1349 |
}
|
class/class-mainwp-child-back-up-buddy.php
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
|
|
|
|
4 |
*
|
5 |
* Credits
|
6 |
*
|
@@ -13,32 +15,59 @@
|
|
13 |
* The code is used for the MainWP Buddy Extension
|
14 |
* Extension URL: https://mainwp.com/extension/mainwpbuddy/
|
15 |
*
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
|
|
|
|
|
|
18 |
class MainWP_Child_Back_Up_Buddy {
|
19 |
-
public static $instance = null;
|
20 |
-
public $plugin_translate = 'mainwp-child';
|
21 |
-
public $is_backupbuddy_installed = false;
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
27 |
-
return
|
28 |
}
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
34 |
$this->is_backupbuddy_installed = true;
|
35 |
}
|
36 |
|
37 |
-
if (
|
38 |
return;
|
39 |
}
|
40 |
|
41 |
-
|
42 |
|
43 |
add_action( 'wp_ajax_mainwp_backupbuddy_download_archive', array( $this, 'download_archive' ) );
|
44 |
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
|
@@ -47,23 +76,37 @@ class MainWP_Child_Back_Up_Buddy {
|
|
47 |
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
48 |
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
49 |
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
50 |
-
|
51 |
}
|
52 |
}
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
if ( isset( $_POST['mainwpsignature'] ) ) {
|
61 |
return $value;
|
62 |
}
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
|
68 |
if ( isset( $value->response['backupbuddy/backupbuddy.php'] ) ) {
|
69 |
unset( $value->response['backupbuddy/backupbuddy.php'] );
|
@@ -73,8 +116,13 @@ class MainWP_Child_Back_Up_Buddy {
|
|
73 |
}
|
74 |
|
75 |
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
78 |
foreach ( $plugins as $key => $value ) {
|
79 |
$plugin_slug = basename( $key, '.php' );
|
80 |
if ( 'backupbuddy' === $plugin_slug ) {
|
@@ -85,148 +133,237 @@ class MainWP_Child_Back_Up_Buddy {
|
|
85 |
return $plugins;
|
86 |
}
|
87 |
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
global $submenu;
|
|
|
90 |
remove_menu_page( 'pb_backupbuddy_backup' );
|
91 |
|
92 |
-
if ( false !== stripos( $_SERVER['REQUEST_URI'], 'admin.php?page=pb_backupbuddy_' ) ) {
|
93 |
-
|
94 |
exit();
|
95 |
}
|
96 |
}
|
97 |
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
102 |
} else {
|
103 |
-
$this->do_reports_log('backupbuddy');
|
104 |
}
|
105 |
}
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
return;
|
|
|
110 |
|
111 |
-
if (
|
112 |
return;
|
113 |
}
|
114 |
|
115 |
-
|
116 |
|
117 |
-
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
$information = array();
|
216 |
if ( ! $this->is_backupbuddy_installed ) {
|
217 |
MainWP_Helper::write( array( 'error' => __( 'Please install the BackupBuddy plugin on the child site.', $this->plugin_translate ) ) );
|
218 |
}
|
219 |
|
220 |
-
if ( ! class_exists( 'backupbuddy_core' ) ) {
|
221 |
-
require_once
|
222 |
}
|
223 |
|
224 |
-
if ( !isset( pb_backupbuddy::$options ) ) {
|
225 |
-
pb_backupbuddy::load();
|
226 |
}
|
227 |
-
|
|
|
228 |
if ( isset( $_POST['mwp_action'] ) ) {
|
229 |
-
switch ( $
|
230 |
case 'set_showhide':
|
231 |
$information = $this->set_showhide();
|
232 |
break;
|
@@ -370,20 +507,32 @@ class MainWP_Child_Back_Up_Buddy {
|
|
370 |
MainWP_Helper::write( $information );
|
371 |
}
|
372 |
|
373 |
-
|
374 |
-
|
|
|
|
|
|
|
|
|
375 |
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
376 |
MainWP_Helper::update_option( 'mainwp_backupbuddy_hide_plugin', $hide );
|
377 |
$information['result'] = 'SUCCESS';
|
378 |
return $information;
|
379 |
}
|
380 |
|
381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
382 |
|
383 |
-
$type = isset($_POST['type']) ? $_POST['type'] : '';
|
384 |
|
385 |
-
if (
|
386 |
-
return array('error' => __('Invalid data. Please check and try again.') );
|
387 |
}
|
388 |
|
389 |
$filter_advanced_settings = array(
|
@@ -414,14 +563,14 @@ class MainWP_Child_Back_Up_Buddy {
|
|
414 |
'disable_https_local_ssl_verify',
|
415 |
'prevent_flush',
|
416 |
'save_comment_meta',
|
417 |
-
'integrity_check',
|
418 |
'backup_cron_rescheduling',
|
419 |
'skip_spawn_cron_call',
|
420 |
'backup_cron_passed_force_time',
|
421 |
'php_runtime_test_minimum_interval',
|
422 |
'php_memory_test_minimum_interval',
|
423 |
'database_method_strategy',
|
424 |
-
'skip_database_dump',
|
425 |
'breakout_tables',
|
426 |
'force_single_db_file',
|
427 |
'phpmysqldump_maxrows',
|
@@ -439,7 +588,6 @@ class MainWP_Child_Back_Up_Buddy {
|
|
439 |
'ignore_zip_symlinks',
|
440 |
);
|
441 |
|
442 |
-
|
443 |
$filter_general_settings = array(
|
444 |
'importbuddy_pass_hash',
|
445 |
'importbuddy_pass_length',
|
@@ -453,10 +601,10 @@ class MainWP_Child_Back_Up_Buddy {
|
|
453 |
'archive_limit_files',
|
454 |
'title_multisite',
|
455 |
'multisite_export',
|
456 |
-
'backup_nonwp_tables',
|
457 |
-
'mysqldump_additional_includes',
|
458 |
-
'mysqldump_additional_excludes',
|
459 |
-
'excludes',
|
460 |
'email_notify_scheduled_start',
|
461 |
'email_notify_scheduled_start_subject',
|
462 |
'email_notify_scheduled_start_body',
|
@@ -470,7 +618,7 @@ class MainWP_Child_Back_Up_Buddy {
|
|
470 |
'email_notify_error',
|
471 |
'email_notify_error_subject',
|
472 |
'email_notify_error_body',
|
473 |
-
'email_return'
|
474 |
);
|
475 |
|
476 |
$filter_profile0_values = array(
|
@@ -479,141 +627,182 @@ class MainWP_Child_Back_Up_Buddy {
|
|
479 |
'excludes',
|
480 |
'integrity_check',
|
481 |
'skip_database_dump',
|
482 |
-
'backup_nonwp_tables'
|
483 |
);
|
484 |
|
485 |
-
$settings = unserialize(base64_decode($_POST['options']));
|
486 |
|
487 |
$save_settings = array();
|
488 |
|
489 |
-
if (is_array($settings)) {
|
490 |
-
if (
|
491 |
-
foreach($filter_general_settings as $field) {
|
492 |
-
if(isset($settings[$field])) {
|
493 |
-
$save_settings[$field] = $settings[$field];
|
494 |
}
|
495 |
}
|
496 |
}
|
497 |
|
498 |
-
if (
|
499 |
-
foreach($filter_advanced_settings as $field) {
|
500 |
-
if(isset($settings[$field])) {
|
501 |
-
$save_settings[$field] = $settings[$field];
|
502 |
}
|
503 |
}
|
504 |
}
|
505 |
}
|
506 |
|
507 |
-
if (!empty($save_settings)) {
|
508 |
-
$newOptions = pb_backupbuddy::$options;
|
509 |
|
510 |
-
foreach($newOptions as $key => $val) {
|
511 |
-
if (isset($save_settings[$key])) {
|
512 |
-
$newOptions[$key] = $save_settings[$key];
|
513 |
}
|
514 |
}
|
515 |
|
516 |
-
if (isset($newOptions['profiles']) && isset($newOptions['profiles'][0])) {
|
517 |
-
foreach ($filter_profile0_values as $field) {
|
518 |
-
if (isset($settings[$field])) {
|
519 |
-
$newOptions['profiles'][0][$field] = $settings[$field];
|
520 |
}
|
521 |
}
|
522 |
}
|
523 |
|
524 |
-
if ('general_settings' === $type || 'all' === $type ) {
|
525 |
$newOptions['importbuddy_pass_hash_confirm'] = '';
|
526 |
}
|
527 |
|
|
|
528 |
global $wpdb;
|
529 |
-
|
|
|
530 |
$newOptions = sanitize_option( $option, $newOptions );
|
531 |
-
$newOptions = maybe_serialize( $newOptions );
|
532 |
|
533 |
-
add_site_option( $option, $newOptions, '', 'no'); // 'No' prevents autoload if we wont always need the data loaded.
|
534 |
$wpdb->update( $wpdb->options, array( 'option_value' => $newOptions ), array( 'option_name' => $option ) );
|
535 |
|
536 |
-
$information['backupDirectoryDefault'] = backupbuddy_core::_getBackupDirectoryDefault();
|
537 |
-
$information['result']
|
538 |
}
|
539 |
|
540 |
return $information;
|
541 |
}
|
542 |
|
543 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
544 |
// Keep log serial.
|
545 |
-
$old_log_serial = pb_backupbuddy::$options['log_serial'];
|
546 |
|
547 |
-
$keepDestNote
|
548 |
-
$remote_destinations
|
549 |
-
pb_backupbuddy::$options = pb_backupbuddy::settings( 'default_options' );
|
550 |
if ( '1' == $_POST['keep_destinations'] ) {
|
551 |
-
pb_backupbuddy::$options['remote_destinations'] = $remote_destinations;
|
552 |
-
$keepDestNote
|
553 |
}
|
554 |
|
555 |
// Replace log serial.
|
556 |
-
pb_backupbuddy::$options['log_serial'] = $old_log_serial;
|
557 |
|
558 |
-
pb_backupbuddy::save();
|
559 |
-
|
560 |
-
backupbuddy_core::verify_directories( $skipTempGeneration
|
561 |
$resetNote = __( 'Plugin settings have been reset to defaults.', 'mainwp-child' );
|
562 |
-
backupbuddy_core::addNotification( 'settings_reset', 'Plugin settings reset', $resetNote . $keepDestNote );
|
563 |
|
564 |
$information['message'] = $resetNote . $keepDestNote;
|
565 |
-
$information['result']
|
566 |
return $information;
|
567 |
}
|
568 |
|
569 |
-
|
570 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
571 |
}
|
572 |
|
573 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
574 |
$schedules_run_time = array();
|
575 |
-
foreach ( pb_backupbuddy::$options['schedules'] as $schedule_id => $schedule ) {
|
576 |
// Determine first run.
|
577 |
-
$first_run = pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $schedule['first_run'] ) );
|
578 |
// Determine last run.
|
579 |
if ( isset( $schedule['last_run'] ) ) { // backward compatibility before last run tracking added. Pre v2.2.11. Eventually remove this.
|
580 |
-
if ( $schedule['last_run']
|
581 |
-
$last_run = '<i>' . __( 'Never', '
|
582 |
} else {
|
583 |
-
$last_run = pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $schedule['last_run'] ) );
|
584 |
}
|
585 |
} else { // backward compatibility for before last run tracking was added.
|
586 |
-
$last_run = '<i> ' . __( 'Unknown', '
|
587 |
}
|
588 |
|
589 |
// Determine next run.
|
590 |
-
$next_run = wp_next_scheduled( 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int)$schedule_id ) ) );
|
591 |
if ( false === $next_run ) {
|
592 |
$next_run = '<font color=red>Error: Cron event not found</font>';
|
593 |
} else {
|
594 |
-
$next_run = pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $next_run ) );
|
595 |
}
|
596 |
|
597 |
$run_time = 'First run: ' . $first_run . '<br>' .
|
598 |
-
|
599 |
-
|
600 |
|
601 |
-
$schedules_run_time[$schedule_id] = $run_time;
|
602 |
|
603 |
}
|
604 |
|
605 |
return $schedules_run_time;
|
606 |
}
|
607 |
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
617 |
}
|
618 |
|
619 |
$information['result'] = 'SUCCESS';
|
@@ -621,20 +810,28 @@ class MainWP_Child_Back_Up_Buddy {
|
|
621 |
}
|
622 |
|
623 |
|
624 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
625 |
if ( ! is_main_site() ) { // Only run for main site or standalone. Multisite subsites do not allow schedules.
|
626 |
-
return array('error' => __('Only run for main site or standalone. Multisite subsites do not allow schedules', 'mainwp-child') );
|
627 |
}
|
628 |
|
629 |
$schedule_id = (int) $_POST['schedule_id'];
|
630 |
|
631 |
-
if ( !isset( pb_backupbuddy::$options['schedules'][$schedule_id] ) || ! is_array( pb_backupbuddy::$options['schedules'][$schedule_id] ) ) {
|
632 |
-
return array('error' => __( 'Error: not found the backup schedule or invalid data', 'mainwp-child' ));
|
633 |
}
|
634 |
|
635 |
-
pb_backupbuddy::alert( 'Manually running scheduled backup "' . pb_backupbuddy::$options['schedules'][$schedule_id]['title'] . '" in the background.' . '
|
636 |
-
|
637 |
-
pb_backupbuddy_cron::_run_scheduled_backup( $schedule_id );
|
638 |
|
639 |
$information['result'] = 'SUCCESS';
|
640 |
|
@@ -642,169 +839,235 @@ class MainWP_Child_Back_Up_Buddy {
|
|
642 |
}
|
643 |
|
644 |
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
651 |
}
|
652 |
$information = array();
|
653 |
-
|
654 |
-
if (!isset(pb_backupbuddy::$options['schedules'][$schedule_id])) {
|
655 |
-
$next_index = pb_backupbuddy::$options['next_schedule_index'];
|
656 |
-
pb_backupbuddy::$options['next_schedule_index']++; // This change will be saved in savesettings function below.
|
657 |
-
pb_backupbuddy::$options['schedules'][$schedule_id] = $schedule;
|
658 |
-
$result = backupbuddy_core::schedule_event( $schedule['first_run'], $schedule['interval'], 'run_scheduled_backup', array( $schedule_id ) );
|
659 |
-
if (
|
660 |
-
return array('error' => 'Error scheduling event with WordPress. Your schedule may not work properly. Please try again. Error #3488439b. Check your BackupBuddy error log for details.');
|
661 |
}
|
662 |
} else {
|
663 |
-
$first_run
|
664 |
-
$next_scheduled_time = wp_next_scheduled( 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int)$schedule_id ) ) );
|
665 |
-
backupbuddy_core::unschedule_event( $next_scheduled_time, 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int)$schedule_id ) ) );
|
666 |
-
backupbuddy_core::schedule_event( $first_run, $schedule['interval'], 'run_scheduled_backup', array( (int)$schedule_id ) ); // Add new schedule.
|
667 |
-
pb_backupbuddy::$options['schedules'][$schedule_id] = $schedule;
|
668 |
-
}
|
669 |
-
pb_backupbuddy::save();
|
670 |
-
$information['result']
|
671 |
-
$information['schedules']
|
672 |
-
$information['next_schedule_index'] = pb_backupbuddy::$options['next_schedule_index'];
|
673 |
-
$information['schedules_run_time']
|
674 |
return $information;
|
675 |
}
|
676 |
|
677 |
|
678 |
-
|
679 |
-
|
680 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
681 |
|
682 |
-
if (!is_array($profile)) {
|
683 |
-
return array('error' => __( 'Invalid profile data', 'mainwp-child' ));
|
684 |
}
|
685 |
|
686 |
-
pb_backupbuddy::$options['profiles'][$profile_id] = $profile;
|
687 |
-
pb_backupbuddy::save();
|
688 |
|
689 |
$information['result'] = 'SUCCESS';
|
690 |
return $information;
|
691 |
}
|
692 |
|
693 |
|
694 |
-
|
695 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
696 |
|
697 |
-
if (isset(pb_backupbuddy::$options['profiles'][$profile_id]))
|
698 |
-
unset(pb_backupbuddy::$options['profiles'][$profile_id]);
|
|
|
699 |
|
700 |
-
pb_backupbuddy::save();
|
701 |
$information['result'] = 'SUCCESS';
|
702 |
return $information;
|
703 |
}
|
704 |
|
705 |
-
|
706 |
-
|
707 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
708 |
$information = array();
|
709 |
if ( is_array( $item_ids ) && count( $item_ids ) > 0 ) {
|
710 |
-
$needs_save
|
711 |
$deleted_files = array();
|
712 |
-
foreach( $item_ids as $item ) {
|
713 |
-
if ( file_exists( backupbuddy_core::getBackupDirectory() . $item ) ) {
|
714 |
-
if (
|
715 |
$deleted_files[] = $item;
|
716 |
|
717 |
// Cleanup any related fileoptions files.
|
718 |
-
$serial = backupbuddy_core::get_serial_from_file( $item );
|
719 |
|
720 |
-
$backup_files = glob( backupbuddy_core::getBackupDirectory() . '*.zip' );
|
721 |
if ( ! is_array( $backup_files ) ) {
|
722 |
$backup_files = array();
|
723 |
}
|
724 |
if ( count( $backup_files ) > 5 ) { // Keep a minimum number of backups in array for stats.
|
725 |
-
$this_serial
|
726 |
-
$fileoptions_file = backupbuddy_core::getLogDirectory() . 'fileoptions/' . $this_serial . '.txt';
|
727 |
if ( file_exists( $fileoptions_file ) ) {
|
728 |
-
|
729 |
}
|
730 |
if ( file_exists( $fileoptions_file . '.lock' ) ) {
|
731 |
-
|
732 |
}
|
733 |
$needs_save = true;
|
734 |
}
|
735 |
}
|
736 |
-
}
|
737 |
-
}
|
738 |
-
if (
|
739 |
-
pb_backupbuddy::save();
|
740 |
}
|
741 |
|
742 |
$information['result'] = 'SUCCESS';
|
743 |
|
744 |
-
}
|
745 |
return $information;
|
746 |
}
|
747 |
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
757 |
return $information;
|
758 |
}
|
759 |
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
777 |
|
|
|
|
|
|
|
778 |
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
|
786 |
-
|
787 |
-
|
788 |
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
|
804 |
return false;
|
805 |
}
|
806 |
|
807 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
808 |
if ( function_exists( 'get_option' ) ) {
|
809 |
$gmt_offset = get_option( 'gmt_offset' );
|
810 |
} else {
|
@@ -813,208 +1076,222 @@ class MainWP_Child_Back_Up_Buddy {
|
|
813 |
return $timestamp + ( $gmt_offset * 3600 );
|
814 |
}
|
815 |
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
827 |
return $information;
|
828 |
}
|
829 |
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
841 |
|
842 |
// Returns true on success, else the error message.
|
843 |
-
$old_comment
|
844 |
-
$comment
|
845 |
$comment['note'] = $note;
|
846 |
|
847 |
-
|
848 |
-
|
849 |
-
$comment_result = pb_backupbuddy::$classes['zipbuddy']->set_comment( $backup_file, $comment );
|
850 |
|
851 |
$information = array();
|
852 |
-
if (
|
853 |
$information['result'] = 'SUCCESS';
|
854 |
}
|
855 |
|
856 |
// Even if we cannot save the note into the archive file, store it in internal settings.
|
857 |
-
$serial = backupbuddy_core::get_serial_from_file( $backup_file );
|
858 |
|
859 |
-
require_once
|
860 |
-
pb_backupbuddy::status( 'details', 'Fileoptions instance #24.' );
|
861 |
-
$backup_options = new pb_backupbuddy_fileoptions( backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt' );
|
862 |
-
|
|
|
863 |
$backup_options->options['integrity']['comment'] = $note;
|
864 |
$backup_options->save();
|
865 |
}
|
866 |
return $information;
|
867 |
}
|
868 |
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
876 |
}
|
877 |
|
878 |
-
|
879 |
-
|
880 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
881 |
$max_cache_time = 86400;
|
882 |
|
883 |
-
// This is the root directory we want the listing for
|
884 |
-
$root
|
885 |
$root_len = strlen( $root );
|
886 |
|
887 |
-
// This will identify the backup zip file we want to list
|
888 |
-
$serial = $_POST[ 'serial'
|
889 |
$alerts = array();
|
890 |
-
// The fileoptions file that contains the file tree information
|
891 |
-
require_once
|
892 |
-
$fileoptions_file = backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '-filetree.txt';
|
893 |
|
894 |
// Purge cache if too old.
|
895 |
if ( file_exists( $fileoptions_file ) && ( ( time() - filemtime( $fileoptions_file ) ) > $max_cache_time ) ) {
|
896 |
if ( false === unlink( $fileoptions_file ) ) {
|
897 |
-
$alerts[] = 'Error #456765545. Unable to wipe cached fileoptions file `' . $fileoptions_file . '`.'
|
898 |
}
|
899 |
}
|
900 |
|
901 |
-
pb_backupbuddy::status( 'details', 'Fileoptions instance #28.' );
|
902 |
-
$fileoptions = new pb_backupbuddy_fileoptions( $fileoptions_file );
|
903 |
-
$zip_viewer
|
904 |
-
// Either we are getting cached file tree information or we need to create afresh
|
905 |
-
|
|
|
906 |
// Get file listing.
|
907 |
-
require_once
|
908 |
-
pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy( ABSPATH, array(), 'unzip' );
|
909 |
-
$files
|
910 |
-
$fileoptions->options
|
911 |
$fileoptions->save();
|
912 |
} else {
|
913 |
$files = &$fileoptions->options;
|
914 |
}
|
915 |
|
916 |
-
// Just make sure we have a sensible files listing
|
917 |
if ( ! is_array( $files ) ) {
|
918 |
return array( 'error' => 'Error #548484. Unable to retrieve file listing from backup file `' . htmlentities( $zip_viewer ) . '`.' );
|
919 |
}
|
920 |
-
|
921 |
-
// To record subdirs of this root
|
922 |
$subdirs = array();
|
923 |
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
// If shorter than root length then certainly is not within this (root) directory.
|
928 |
-
// It's a quick test that is more effective the longer the root (the deeper you go
|
929 |
-
// into the tree)
|
930 |
-
if ( strlen( $file[ 0 ] ) < $root_len ) {
|
931 |
-
|
932 |
unset( $files[ $key ] );
|
933 |
continue;
|
934 |
-
|
935 |
}
|
936 |
|
937 |
-
|
938 |
-
// e.g., with root=this/dir/path/
|
939 |
-
// these will fail: file=this/dir/file; file=this/dir/otherpath/; file=that/dir/path/file
|
940 |
-
// and these would succeed: file=this/dir/path/; file=this/dir/path/file; file=this/dir/path/otherpath/
|
941 |
-
if ( substr( $file[ 0 ], 0, $root_len ) != $root ) {
|
942 |
-
|
943 |
unset( $files[ $key ] );
|
944 |
continue;
|
945 |
-
|
946 |
}
|
947 |
|
948 |
-
|
949 |
-
// Don't want to do this on _every_ file as very specific so do it here after we have
|
950 |
-
// weeded out files for more common reasons
|
951 |
-
if ( 0 == strcmp( $file[ 0 ], $root ) ) {
|
952 |
-
|
953 |
unset( $files[ $key ] );
|
954 |
continue;
|
955 |
-
|
956 |
}
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
$unrooted_file = substr( $file[ 0 ], $root_len );
|
961 |
-
|
962 |
-
// We must ensure that we list the subdir/ even if subdir/ does not appear
|
963 |
-
// as a distinct entry in the list but only subdir/file or subdir/subsubdir/ or
|
964 |
-
// subdir/subsubdir/file. Find if we have any directory separator(s) in the filename
|
965 |
-
// and if so remember where the first is
|
966 |
-
if ( false !== ( $pos = strpos( $unrooted_file, '/' ) ) ) {
|
967 |
-
|
968 |
-
// Get the subdir/ prefix part, discarding everything after the first /
|
969 |
$subdir = substr( $unrooted_file, 0, ( $pos + 1 ) );
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
// Not already seen so record we have seen it and modify this entry to be
|
975 |
-
// specific for the subdir/
|
976 |
-
$subdirs[] = $subdir;
|
977 |
-
|
978 |
-
// Replace the original (rooted) file name
|
979 |
-
$files[ $key ][ 0 ] = $subdir;
|
980 |
-
|
981 |
} else {
|
982 |
-
|
983 |
-
// We already know about the subdir/ so remove this entry
|
984 |
unset( $files[ $key ] );
|
985 |
continue;
|
986 |
|
987 |
}
|
988 |
-
|
989 |
} else {
|
990 |
-
|
991 |
-
// This is just like file within the root
|
992 |
-
// Replace the original (rooted) file name
|
993 |
-
$files[ $key ][ 0 ] = $unrooted_file;
|
994 |
-
|
995 |
}
|
996 |
-
|
997 |
}
|
998 |
|
999 |
-
return array(
|
1000 |
-
|
|
|
|
|
|
|
1001 |
}
|
1002 |
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
|
|
|
|
|
|
|
|
|
|
1006 |
$files = scandir( $root );
|
1007 |
|
1008 |
natcasesort( $files );
|
1009 |
|
1010 |
// Sort with directories first.
|
1011 |
-
$sorted_files
|
1012 |
$sorted_directories = array(); // Temporary holder for sorting directories.
|
1013 |
-
foreach( $files as $file ) {
|
1014 |
-
if ( (
|
1015 |
continue;
|
1016 |
}
|
1017 |
-
if( is_file( str_replace( '//', '/', $root . $file ) ) ) {
|
1018 |
array_push( $sorted_files, $file );
|
1019 |
} else {
|
1020 |
array_unshift( $sorted_directories, $file );
|
@@ -1027,25 +1304,25 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1027 |
|
1028 |
ob_start();
|
1029 |
|
1030 |
-
if( count( $files ) > 0 ) { // Files found.
|
1031 |
echo '<ul class="jqueryFileTree" style="display: none;">';
|
1032 |
-
foreach( $files as $file ) {
|
1033 |
-
if( file_exists( str_replace( '//', '/', $root . $file ) ) ) {
|
1034 |
if ( is_dir( str_replace( '//', '/', $root . $file ) ) ) { // Directory.
|
1035 |
echo '<li class="directory collapsed">';
|
1036 |
-
$return
|
1037 |
$return .= '<div class="pb_backupbuddy_treeselect_control">';
|
1038 |
-
$return .= '<img src="' . pb_backupbuddy::plugin_url() . '/images/redminus.png" style="vertical-align: -3px;" title="Add to exclusions..." class="pb_backupbuddy_filetree_exclude">';
|
1039 |
$return .= '</div>';
|
1040 |
-
echo '<a href="#" rel="' . htmlentities( str_replace( ABSPATH, '', $root ) . $file) . '/" title="Toggle expand...">' . htmlentities($file) . $return . '</a>';
|
1041 |
echo '</li>';
|
1042 |
} else { // File.
|
1043 |
echo '<li class="file collapsed">';
|
1044 |
-
$return
|
1045 |
$return .= '<div class="pb_backupbuddy_treeselect_control">';
|
1046 |
-
$return .= '<img src="' . pb_backupbuddy::plugin_url() . '/images/redminus.png" style="vertical-align: -3px;" title="Add to exclusions..." class="pb_backupbuddy_filetree_exclude">';
|
1047 |
$return .= '</div>';
|
1048 |
-
echo '<a href="#" rel="' . htmlentities( str_replace( ABSPATH, '', $root ) . $file) . '">' . htmlentities($file) . $return . '</a>';
|
1049 |
echo '</li>';
|
1050 |
}
|
1051 |
}
|
@@ -1053,58 +1330,75 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1053 |
echo '</ul>';
|
1054 |
} else {
|
1055 |
echo '<ul class="jqueryFileTree" style="display: none;">';
|
1056 |
-
echo '<li><a href="#" rel="' . htmlentities( pb_backupbuddy::_POST( 'dir' ) . 'NONE' ) . '"><i>Empty Directory ...</i></a></li>';
|
1057 |
echo '</ul>';
|
1058 |
}
|
1059 |
|
1060 |
$html = ob_get_clean();
|
1061 |
-
return array('result' => $html)
|
1062 |
} else {
|
1063 |
-
return array('error' => 'Error #1127555. Unable to read child site root.')
|
1064 |
}
|
1065 |
-
|
1066 |
}
|
1067 |
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1078 |
$size_string = '';
|
1079 |
|
|
|
1080 |
global $wpdb;
|
|
|
1081 |
if ( true === $display_size ) {
|
1082 |
-
$results = $wpdb->get_results(
|
1083 |
} else {
|
1084 |
-
$results = $wpdb->get_results(
|
1085 |
}
|
1086 |
-
foreach( $results as $result ) {
|
1087 |
|
1088 |
if ( true === $display_size ) {
|
1089 |
// Fix up row count and average row length for InnoDB engine which returns inaccurate (and changing) values for these.
|
1090 |
-
if ( 'InnoDB' === $result[
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
|
|
|
|
1094 |
}
|
1095 |
}
|
1096 |
unset( $rowCount );
|
1097 |
}
|
1098 |
|
1099 |
// Table size.
|
1100 |
-
$size_string = ' (' . pb_backupbuddy::$format->file_size( ( $result['Data_length'] + $result['Index_length'] ) ) . ') ';
|
1101 |
|
1102 |
} // end if display size enabled.
|
1103 |
|
1104 |
$return .= '<li class="file ext_sql collapsed">';
|
1105 |
$return .= '<a rel="/" alt="' . $result['table_name'] . '">' . $result['table_name'] . $size_string;
|
1106 |
$return .= '<div class="pb_backupbuddy_treeselect_control">';
|
1107 |
-
$return .= '<img src="' . pb_backupbuddy::plugin_url() . '/images/redminus.png" style="vertical-align: -3px;" title="Add to exclusions..." class="pb_backupbuddy_table_addexclude"> <img src="' . pb_backupbuddy::plugin_url() . '/images/greenplus.png" style="vertical-align: -3px;" title="Add to inclusions..." class="pb_backupbuddy_table_addinclude">';
|
1108 |
$return .= '</div>';
|
1109 |
$return .= '</a>';
|
1110 |
$return .= '</li>';
|
@@ -1113,46 +1407,57 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1113 |
return '<div class="jQueryOuterTree" style="position: absolute; height: 160px;"><ul class="jqueryFileTree">' . $return . '</ul></div>';
|
1114 |
}
|
1115 |
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1125 |
|
1126 |
// Calculate temp directory & lock it down.
|
1127 |
-
$temp_dir
|
1128 |
$destination = $temp_dir . 'backupbuddy-' . $serial;
|
1129 |
if ( ( ( ! file_exists( $destination ) ) && ( false === mkdir( $destination ) ) ) ) {
|
1130 |
$error = 'Error #458485945b: Unable to create temporary location.';
|
1131 |
-
pb_backupbuddy::status( 'error', $error );
|
1132 |
-
return array('error' => $error);
|
1133 |
}
|
1134 |
|
1135 |
// If temp directory is within webroot then lock it down.
|
1136 |
$temp_dir = str_replace( '\\', '/', $temp_dir ); // Normalize for Windows.
|
1137 |
$temp_dir = rtrim( $temp_dir, '/\\' ) . '/'; // Enforce single trailing slash.
|
1138 |
-
if (
|
1139 |
-
pb_backupbuddy::anti_directory_browsing( $destination );
|
1140 |
}
|
1141 |
unset( $temp_dir );
|
1142 |
|
1143 |
$message = 'Extracting "' . $file . '" from archive "' . $archive_file . '" into temporary file "' . $destination . '". ';
|
1144 |
-
|
1145 |
-
pb_backupbuddy::status( 'details', $message );
|
1146 |
-
//echo $message;
|
1147 |
|
1148 |
$file_content = '';
|
1149 |
|
1150 |
-
$extractions
|
1151 |
-
$extract_result = $zipbuddy->extract( backupbuddy_core::getBackupDirectory() . $archive_file, $destination, $extractions );
|
1152 |
if ( false === $extract_result ) { // failed.
|
1153 |
-
//echo ' -->';
|
1154 |
$error = 'Error #584984458. Unable to extract.';
|
1155 |
-
pb_backupbuddy::status( 'error', $error );
|
1156 |
return array( 'error' => $error );
|
1157 |
} else { // success.
|
1158 |
$file_content = file_get_contents( $destination . '/' . $temp_file );
|
@@ -1160,127 +1465,174 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1160 |
|
1161 |
// Try to cleanup.
|
1162 |
if ( file_exists( $destination ) ) {
|
1163 |
-
if ( false === pb_backupbuddy::$filesystem->unlink_recursive( $destination ) ) {
|
1164 |
-
pb_backupbuddy::status( 'details', 'Unable to delete temporary holding directory `' . $destination . '`.' );
|
1165 |
} else {
|
1166 |
-
pb_backupbuddy::status( 'details', 'Cleaned up temporary files.' );
|
1167 |
}
|
1168 |
}
|
1169 |
|
1170 |
-
return array(
|
|
|
|
|
|
|
1171 |
}
|
1172 |
|
1173 |
|
1174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1175 |
|
1176 |
-
$files
|
1177 |
-
$archive_file = $_POST[ 'archive'
|
1178 |
|
1179 |
$files_array = explode( ',', $files );
|
1180 |
-
$files
|
1181 |
-
foreach( $files_array as $file ) {
|
1182 |
if ( substr( $file, -1 ) == '/' ) { // If directory then add wildcard.
|
1183 |
$file = $file . '*';
|
1184 |
}
|
1185 |
-
$files[$file] = $file;
|
1186 |
}
|
1187 |
unset( $files_array );
|
1188 |
|
1189 |
$success = false;
|
1190 |
|
|
|
1191 |
global $pb_backupbuddy_js_status;
|
|
|
1192 |
$pb_backupbuddy_js_status = true;
|
1193 |
-
|
|
|
|
|
|
|
1194 |
global $wp_version;
|
1195 |
-
pb_backupbuddy::status( 'details', 'BackupBuddy v' . pb_backupbuddy::settings( 'version' ) . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.' );
|
1196 |
|
1197 |
-
|
|
|
|
|
1198 |
|
1199 |
ob_start();
|
1200 |
-
$result
|
1201 |
$restore_result = ob_get_clean();
|
1202 |
-
pb_backupbuddy::flush();
|
1203 |
-
return array('restore_result' => $restore_result);
|
1204 |
}
|
1205 |
|
1206 |
-
|
1207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1208 |
$backup_sort_dates = array();
|
1209 |
|
1210 |
-
$files = glob( backupbuddy_core::getBackupDirectory() . 'backup*.zip' );
|
1211 |
if ( ! is_array( $files ) ) {
|
1212 |
$files = array();
|
1213 |
}
|
1214 |
|
1215 |
-
$files2 = glob( backupbuddy_core::getBackupDirectory() . 'snapshot*.zip' );
|
1216 |
if ( ! is_array( $files2 ) ) {
|
1217 |
$files2 = array();
|
1218 |
}
|
1219 |
|
1220 |
$files = array_merge( $files, $files2 );
|
1221 |
|
1222 |
-
if ( is_array( $files ) && !empty( $files ) ) { // For robustness. Without open_basedir the glob() function returns an empty array for no match. With open_basedir in effect the glob() function returns a boolean false for no match.
|
1223 |
|
1224 |
-
$backup_prefix = backupbuddy_core::backup_prefix(); //
|
1225 |
-
foreach( $files as $file_id => $file ) {
|
1226 |
|
1227 |
-
if ( (
|
1228 |
|
1229 |
// Only allow viewing of their own backups.
|
1230 |
if ( ! strstr( $file, $backup_prefix ) ) {
|
1231 |
-
unset( $files[$file_id] ); // Remove this backup from the list. This user does not have access to it.
|
1232 |
continue; // Skip processing to next file.
|
1233 |
}
|
1234 |
}
|
1235 |
|
1236 |
-
$serial = backupbuddy_core::get_serial_from_file( $file );
|
1237 |
|
1238 |
$options = array();
|
1239 |
-
if ( file_exists( backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt' ) ) {
|
1240 |
-
require_once
|
1241 |
-
pb_backupbuddy::status( 'details', 'Fileoptions instance #33.' );
|
1242 |
-
$backup_options = new pb_backupbuddy_fileoptions( backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt', $read_only = false, $ignore_lock = false, $create_file = true ); // Will create file to hold integrity data if nothing exists.
|
1243 |
} else {
|
1244 |
$backup_options = '';
|
1245 |
}
|
1246 |
-
$backup_integrity = backupbuddy_core::backup_integrity_check( $file, $backup_options, $options );
|
1247 |
|
1248 |
// Backup status.
|
1249 |
$pretty_status = array(
|
1250 |
-
true
|
1251 |
-
'pass'
|
1252 |
-
false
|
1253 |
-
'fail'
|
1254 |
);
|
1255 |
|
1256 |
// Backup type.
|
1257 |
$pretty_type = array(
|
1258 |
-
'full'
|
1259 |
-
'db'
|
1260 |
-
'files'
|
1261 |
-
'themes'
|
1262 |
-
'plugins'
|
1263 |
);
|
1264 |
|
1265 |
-
|
1266 |
-
// Defaults...
|
1267 |
$detected_type = '';
|
1268 |
-
$file_size
|
1269 |
-
$modified
|
1270 |
$modified_time = 0;
|
1271 |
-
$integrity
|
1272 |
|
1273 |
$main_string = 'Warn#284.';
|
1274 |
if ( is_array( $backup_integrity ) ) { // Data intact... put it all together.
|
1275 |
// Calculate time ago.
|
1276 |
$time_ago = '';
|
1277 |
if ( isset( $backup_integrity['modified'] ) ) {
|
1278 |
-
$time_ago = pb_backupbuddy::$format->time_ago( $backup_integrity['modified'] ) . ' ago';
|
1279 |
}
|
1280 |
|
1281 |
-
$detected_type = pb_backupbuddy::$format->prettify( $backup_integrity['detected_type'], $pretty_type );
|
1282 |
-
if (
|
1283 |
-
$detected_type = backupbuddy_core::pretty_backup_type( backupbuddy_core::getBackupTypeFromFile( $file ) );
|
1284 |
if ( '' == $detected_type ) {
|
1285 |
$detected_type = '<span class="description">Unknown</span>';
|
1286 |
}
|
@@ -1292,87 +1644,98 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1292 |
<span style="display: inline-block; float: left; height: 15px; border-right: 1px solid #EBEBEB; margin-left: 6px; margin-right: 6px;"></span>
|
1293 |
' . htmlentities( $backup_options->options['profile']['title'] ) . '
|
1294 |
</div>
|
1295 |
-
'
|
1296 |
-
;
|
1297 |
}
|
1298 |
}
|
1299 |
|
1300 |
-
$file_size
|
1301 |
-
$modified
|
1302 |
$modified_time = $backup_integrity['modified'];
|
1303 |
if ( isset( $backup_integrity['status'] ) ) { // Pre-v4.0.
|
1304 |
$status = $backup_integrity['status'];
|
1305 |
-
} else { // v4.0
|
1306 |
$status = $backup_integrity['is_ok'];
|
1307 |
}
|
1308 |
|
1309 |
-
|
1310 |
// Calculate main row string.
|
1311 |
-
if (
|
1312 |
-
$download_url = '/wp-admin/admin-ajax.php?action=mainwp_backupbuddy_download_archive&backupbuddy_backup=' . basename( $file ) . '&_wpnonce=' .
|
1313 |
-
$main_string
|
1314 |
-
} elseif (
|
1315 |
-
$main_string = '<a class="pb_backupbuddy_hoveraction_migrate backupbuddyFileTitle" rel="' . basename( $file ) . '" href="' . pb_backupbuddy::page_url() . '&migrate=' . basename( $file ) . '&value=' . basename( $file ) . '" title="' . basename( $file ) . '">' . $modified . ' (' . $time_ago . ')</a>';
|
1316 |
} else {
|
1317 |
$main_string = '{Unknown type.}';
|
1318 |
}
|
1319 |
// Add comment to main row string if applicable.
|
1320 |
-
if ( isset( $backup_integrity['comment'] ) && ( $backup_integrity['comment']
|
1321 |
$main_string .= '<br><span class="description">Note: <span class="pb_backupbuddy_notetext">' . htmlentities( $backup_integrity['comment'] ) . '</span></span>';
|
1322 |
}
|
1323 |
|
1324 |
-
|
1325 |
-
|
1326 |
-
|
1327 |
-
foreach( (array)$backup_integrity['scan_notes'] as $scan_note ) {
|
1328 |
$integrity .= $scan_note . ' ';
|
1329 |
}
|
1330 |
}
|
1331 |
-
$integrity .= '<a href="#" serial="' . $serial
|
1332 |
$integrity .= '<div class="row-actions"><a title="' . __( 'Backup Status', 'mainwp-child' ) . '" href="#" serial="' . $serial . '" class="mainwp_bb_view_details_lnk thickbox">' . __( 'View Details', 'mainwp-child' ) . '</a></div>';
|
1333 |
|
1334 |
-
$sumLogFile = backupbuddy_core::getLogDirectory() . 'status-' . $serial . '_' . pb_backupbuddy::$options['log_serial'] . '.txt';
|
1335 |
if ( file_exists( $sumLogFile ) ) {
|
1336 |
$integrity .= '<div class="row-actions"><a title="' . __( 'View Backup Log', 'mainwp-child' ) . '" href="#" serial="' . $serial . '" class="mainwp_bb_view_log_lnk thickbox">' . __( 'View Log', 'mainwp-child' ) . '</a></div>';
|
1337 |
}
|
1338 |
-
|
1339 |
-
} // end if is_array( $backup_options ).
|
1340 |
|
1341 |
// No integrity check for themes or plugins types.
|
1342 |
-
$raw_type = backupbuddy_core::getBackupTypeFromFile( $file );
|
1343 |
if ( ( 'themes' == $raw_type ) || ( 'plugins' == $raw_type ) ) {
|
1344 |
$integrity = 'n/a';
|
1345 |
}
|
1346 |
|
1347 |
-
$backups[basename( $file )] = array(
|
1348 |
array( basename( $file ), $main_string . '<br><span class="description" style="color: #AAA; display: inline-block; margin-top: 5px;">' . basename( $file ) . '</span>' ),
|
1349 |
$detected_type,
|
1350 |
$file_size,
|
1351 |
$integrity,
|
1352 |
);
|
1353 |
|
|
|
1354 |
|
1355 |
-
|
1356 |
-
|
1357 |
-
} // End foreach().
|
1358 |
-
|
1359 |
-
} // End if.
|
1360 |
|
1361 |
// Sort backup by date.
|
1362 |
arsort( $backup_sort_dates );
|
1363 |
// Re-arrange backups based on sort dates.
|
1364 |
$sorted_backups = array();
|
1365 |
-
foreach( $backup_sort_dates as $backup_file => $backup_sort_date ) {
|
1366 |
-
$sorted_backups[$backup_file] = $backups[$backup_file];
|
1367 |
-
unset( $backups[$backup_file] );
|
1368 |
}
|
1369 |
unset( $backups );
|
1370 |
return $sorted_backups;
|
|
|
1371 |
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1376 |
if ( ! is_array( $recentBackups_list ) ) {
|
1377 |
$recentBackups_list = array();
|
1378 |
}
|
@@ -1382,44 +1745,44 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1382 |
|
1383 |
// Backup type.
|
1384 |
$pretty_type = array(
|
1385 |
-
'full'
|
1386 |
-
'db'
|
1387 |
-
'files' =>
|
1388 |
);
|
1389 |
|
1390 |
-
foreach( $recentBackups_list as $backup_fileoptions ) {
|
1391 |
|
1392 |
-
require_once
|
1393 |
-
pb_backupbuddy::status( 'details', 'Fileoptions instance #1.' );
|
1394 |
-
$backup = new pb_backupbuddy_fileoptions( $backup_fileoptions, $read_only = true );
|
1395 |
-
|
1396 |
-
|
|
|
1397 |
continue;
|
1398 |
}
|
1399 |
$backup = &$backup->options;
|
1400 |
|
1401 |
-
if ( !isset( $backup['serial'] ) || ( $backup['serial']
|
1402 |
continue;
|
1403 |
}
|
1404 |
if ( ( $backup['finish_time'] >= $backup['start_time'] ) && ( 0 != $backup['start_time'] ) ) {
|
1405 |
$status = '<span class="pb_label pb_label-success">Completed</span>';
|
1406 |
-
} elseif ( $backup['finish_time']
|
1407 |
$status = '<span class="pb_label pb_label-warning">Cancelled</span>';
|
1408 |
-
} elseif (
|
1409 |
$status = '<span class="pb_label pb_label-error">Failed (timeout?)</span>';
|
1410 |
-
} elseif ( ( time() - $backup['updated_time'] ) > backupbuddy_constants::TIME_BEFORE_CONSIDERED_TIMEOUT ) {
|
1411 |
$status = '<span class="pb_label pb_label-error">Failed (likely timeout)</span>';
|
1412 |
} else {
|
1413 |
$status = '<span class="pb_label pb_label-warning">In progress or timed out</span>';
|
1414 |
}
|
1415 |
$status .= '<br>';
|
1416 |
|
1417 |
-
|
1418 |
// Technical details link.
|
1419 |
$status .= '<div class="row-actions">';
|
1420 |
$status .= '<a title="' . __( 'Backup Process Technical Details', 'mainwp-child' ) . '" href="#" serial="' . $backup['serial'] . '" class="mainwp_bb_view_details_lnk thickbox">View Details</a>';
|
1421 |
|
1422 |
-
$sumLogFile = backupbuddy_core::getLogDirectory() . 'status-' . $backup['serial'] . '_' . pb_backupbuddy::$options['log_serial'] . '.txt';
|
1423 |
if ( file_exists( $sumLogFile ) ) {
|
1424 |
$status .= '<div class="row-actions"><a title="' . __( 'View Backup Log', 'mainwp-child' ) . '" href="#" serial="' . $backup['serial'] . '" class="mainwp_bb_view_log_lnk thickbox">' . __( 'View Log', 'mainwp-child' ) . '</a></div>';
|
1425 |
}
|
@@ -1428,34 +1791,30 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1428 |
|
1429 |
// Calculate finish time (if finished).
|
1430 |
if ( $backup['finish_time'] > 0 ) {
|
1431 |
-
$finish_time = pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $backup['finish_time'] ) ) . '<br><span class="description">' . pb_backupbuddy::$format->time_ago( $backup['finish_time'] ) . ' ago</span>';
|
1432 |
} else { // unfinished.
|
1433 |
$finish_time = '<i>Unfinished</i>';
|
1434 |
}
|
1435 |
|
1436 |
-
$backupTitle = '<span class="backupbuddyFileTitle" style="color: #000;" title="' . basename( $backup['archive_file'] ) . '">' . pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $backup['start_time'] ), 'l, F j, Y - g:i:s a' ) . ' (' . pb_backupbuddy::$format->time_ago( $backup['start_time'] ) . ' ago)</span><br><span class="description">' . basename( $backup['archive_file'] ) . '</span>';
|
1437 |
|
1438 |
if ( isset( $backup['profile'] ) && isset( $backup['profile']['type'] ) ) {
|
1439 |
-
$backupType = '<div>
|
1440 |
-
<span style="color: #AAA; float: left;">' . pb_backupbuddy::$format->prettify( $backup['profile']['type'], $pretty_type ) . '</span>
|
1441 |
-
<span style="display: inline-block; float: left; height: 15px; border-right: 1px solid #EBEBEB; margin-left: 6px; margin-right: 6px;"></span>'
|
1442 |
-
. $backup['profile']['title'] .
|
1443 |
-
'</div>';
|
1444 |
} else {
|
1445 |
-
$backupType = backupbuddy_core::pretty_backup_type( backupbuddy_core::getBackupTypeFromFile( $backup['archive_file'] ) );
|
1446 |
if ( '' == $backupType ) {
|
1447 |
$backupType = '<span class="description">Unknown</span>';
|
1448 |
}
|
1449 |
}
|
1450 |
|
1451 |
if ( isset( $backup['archive_size'] ) && ( $backup['archive_size'] > 0 ) ) {
|
1452 |
-
$archive_size = pb_backupbuddy::$format->file_size( $backup['archive_size'] );
|
1453 |
} else {
|
1454 |
$archive_size = 'n/a';
|
1455 |
}
|
1456 |
|
1457 |
// No integrity check for themes or plugins types.
|
1458 |
-
$raw_type = backupbuddy_core::getBackupTypeFromFile( $backup['archive_file'] );
|
1459 |
if ( ( 'themes' == $raw_type ) || ( 'plugins' == $raw_type ) ) {
|
1460 |
$status = 'n/a';
|
1461 |
}
|
@@ -1473,57 +1832,83 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1473 |
}
|
1474 |
|
1475 |
$columns = array(
|
1476 |
-
__('Recently Made Backups (Start Time)', 'mainwp-child' ),
|
1477 |
-
__('Type | Profile', 'mainwp-child' ),
|
1478 |
-
__('File Size', 'mainwp-child' ),
|
1479 |
-
__('Trigger', 'mainwp-child' ),
|
1480 |
-
__('Status', 'mainwp-child' ) . ' <span class="description">(hover for options)</span>',
|
1481 |
);
|
1482 |
|
1483 |
-
|
1484 |
-
|
1485 |
-
|
1486 |
-
|
1487 |
-
|
1488 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1489 |
}
|
1490 |
-
asort($sorter);
|
1491 |
-
foreach ($sorter as $ii => $va) {
|
1492 |
-
$ret[$ii]
|
1493 |
}
|
1494 |
-
$array
|
1495 |
}
|
1496 |
|
1497 |
-
pb_backupbuddy_aasort( $recentBackups, 'start_timestamp' ); // Sort by multidimensional array with key start_timestamp.
|
1498 |
$recentBackups = array_reverse( $recentBackups ); // Reverse array order to show newest first.
|
1499 |
}
|
1500 |
|
1501 |
return $recentBackups;
|
1502 |
}
|
1503 |
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1507 |
|
1508 |
-
if (empty($schedule_ids)) {
|
1509 |
-
return array('error' => __( 'Empty schedule ids', 'mainwp-child' ));
|
1510 |
}
|
1511 |
-
foreach ($schedule_ids as $sch_id) {
|
1512 |
-
if ( isset( pb_backupbuddy::$options['schedules'][$sch_id] ) ) {
|
1513 |
-
unset( pb_backupbuddy::$options['schedules'][$sch_id] );
|
1514 |
}
|
1515 |
}
|
1516 |
-
pb_backupbuddy::save();
|
1517 |
$information['result'] = 'SUCCESS';
|
1518 |
return $information;
|
1519 |
}
|
1520 |
|
1521 |
-
|
1522 |
-
|
1523 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1524 |
|
1525 |
if ( ! file_exists( $logFile ) ) {
|
1526 |
-
return array('error' => 'Error #858733: Log file `' . $logFile . '` not found or access denied.' );
|
1527 |
}
|
1528 |
|
1529 |
$lines = file_get_contents( $logFile );
|
@@ -1531,104 +1916,137 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1531 |
ob_start();
|
1532 |
?>
|
1533 |
|
1534 |
-
<textarea readonly="readonly" id="backupbuddy_messages" wrap="off" style="width: 100%; min-height: 400px; height: 500px; height: 80%; background: #FFF;"
|
1535 |
-
|
1536 |
-
|
1537 |
-
|
1538 |
-
|
1539 |
-
|
1540 |
-
|
1541 |
-
|
1542 |
-
}
|
1543 |
-
echo pb_backupbuddy::$format->date( $line['time'], 'G:i:s' ) . $u . "\t\t";
|
1544 |
-
echo $line['run'] . "sec\t";
|
1545 |
-
echo $line['mem'] . "MB\t";
|
1546 |
-
echo $line['event'] . "\t";
|
1547 |
-
echo $line['data'] . "\n";
|
1548 |
-
} else {
|
1549 |
-
echo $rawline . "\n";
|
1550 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1551 |
}
|
1552 |
-
|
|
|
|
|
1553 |
<small>Log file: <?php echo $logFile; ?></small>
|
1554 |
<br>
|
1555 |
<?php
|
1556 |
-
echo '<small>Last modified: ' . pb_backupbuddy::$format->date( filemtime( $logFile ) ) . ' (' . pb_backupbuddy::$format->time_ago( filemtime( $logFile ) ) . ' ago)';
|
1557 |
?>
|
1558 |
<br><br>
|
1559 |
<?php
|
1560 |
$html = ob_get_clean();
|
1561 |
-
pb_backupbuddy::flush();
|
1562 |
-
return array(
|
|
|
|
|
|
|
1563 |
}
|
1564 |
-
|
1565 |
-
|
1566 |
-
|
1567 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1568 |
$serial = str_replace( '/\\', '', $serial );
|
1569 |
-
pb_backupbuddy::load();
|
1570 |
|
1571 |
-
require_once
|
1572 |
-
pb_backupbuddy::status( 'details', 'Fileoptions instance #27.' );
|
1573 |
-
$optionsFile
|
1574 |
-
$backup_options = new pb_backupbuddy_fileoptions( $optionsFile, $read_only = true );
|
1575 |
-
|
1576 |
-
|
|
|
1577 |
}
|
1578 |
ob_start();
|
1579 |
$integrity = $backup_options->options['integrity'];
|
1580 |
|
1581 |
-
$start_time
|
1582 |
$finish_time = 'Unknown';
|
1583 |
if ( isset( $backup_options->options['start_time'] ) ) {
|
1584 |
-
$start_time = pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $backup_options->options['start_time'] ) ) . ' <span class="description">(' . pb_backupbuddy::$format->time_ago( $backup_options->options['start_time'] ) . ' ago)</span>';
|
1585 |
if ( $backup_options->options['finish_time'] > 0 ) {
|
1586 |
-
$finish_time = pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $backup_options->options['finish_time'] ) ) . ' <span class="description">(' . pb_backupbuddy::$format->time_ago( $backup_options->options['finish_time'] ) . ' ago)</span>';
|
1587 |
} else { // unfinished.
|
1588 |
$finish_time = '<i>Unfinished</i>';
|
1589 |
}
|
1590 |
}
|
1591 |
|
1592 |
-
|
1593 |
-
|
1594 |
-
if ( isset( $integrity['status_details'] ) ) { // $integrity['status_details'] is NOT array (old, pre-3.1.9).
|
1595 |
echo '<h3>Integrity Technical Details</h3>';
|
1596 |
echo '<textarea style="width: 100%; height: 175px;" wrap="off">';
|
1597 |
-
foreach( $integrity as $item_name => $item_value ) {
|
1598 |
$item_value = str_replace( '<br />', '<br>', $item_value );
|
1599 |
$item_value = str_replace( '<br><br>', '<br>', $item_value );
|
1600 |
$item_value = str_replace( '<br>', "\n ", $item_value );
|
1601 |
echo $item_name . ' => ' . $item_value . "\n";
|
1602 |
}
|
1603 |
echo '</textarea><br><br><b>Note:</b> It is normal to see several "file not found" entries as BackupBuddy checks for expected files in multiple locations, expecting to only find each file once in one of those locations.';
|
1604 |
-
} else {
|
1605 |
|
1606 |
echo '<br>';
|
1607 |
|
1608 |
if ( isset( $integrity['status_details'] ) ) { // PRE-v4.0 Tests.
|
1609 |
-
function pb_pretty_results( $value ) {
|
1610 |
-
if ( $value === true ) {
|
1611 |
-
return '<span class="pb_label pb_label-success">Pass</span>';
|
1612 |
-
} else {
|
1613 |
-
return '<span class="pb_label pb_label-important">Fail</span>';
|
1614 |
-
}
|
1615 |
-
}
|
1616 |
|
1617 |
-
|
1618 |
-
|
1619 |
-
$tests
|
1620 |
-
$tests[] = array( '
|
1621 |
-
|
1622 |
-
|
1623 |
-
|
1624 |
-
|
|
|
1625 |
} else { // DB only.
|
1626 |
$tests[] = array( 'WordPress wp-config.php exists (full/files backups only)', '<span class="pb_label pb_label-success">N/A</span>' );
|
1627 |
}
|
1628 |
} else { // 4.0+ Tests.
|
1629 |
$tests = array();
|
1630 |
if ( isset( $integrity['tests'] ) ) {
|
1631 |
-
foreach( (array)$integrity['tests'] as $test ) {
|
1632 |
if ( true === $test['pass'] ) {
|
1633 |
$status_text = '<span class="pb_label pb_label-success">Pass</span>';
|
1634 |
} else {
|
@@ -1644,50 +2062,49 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1644 |
__( 'Status', 'mainwp-child' ),
|
1645 |
);
|
1646 |
|
1647 |
-
pb_backupbuddy::$ui->list_table(
|
1648 |
$tests,
|
1649 |
array(
|
1650 |
-
'columns'
|
1651 |
-
'css'
|
1652 |
)
|
1653 |
);
|
1654 |
|
1655 |
-
}
|
1656 |
echo '<br><br>';
|
1657 |
-
|
1658 |
-
|
1659 |
|
1660 |
// Output meta info table (if any).
|
1661 |
$metaInfo = array();
|
1662 |
-
|
|
|
1663 |
echo '<i>No meta data found in zip comment. Skipping meta information display.</i>';
|
1664 |
} else {
|
1665 |
-
pb_backupbuddy::$ui->list_table(
|
1666 |
$metaInfo,
|
1667 |
array(
|
1668 |
-
'columns'
|
1669 |
-
'css'
|
1670 |
)
|
1671 |
);
|
1672 |
}
|
1673 |
echo '<br><br>';
|
1674 |
|
1675 |
-
|
1676 |
-
|
1677 |
-
$steps = array();
|
1678 |
$steps[] = array( 'Start Time', $start_time, '' );
|
1679 |
if ( isset( $backup_options->options['steps'] ) ) {
|
1680 |
-
foreach( $backup_options->options['steps'] as $step ) {
|
1681 |
-
if ( isset( $step['finish_time'] ) && ( $step['finish_time']
|
1682 |
|
1683 |
// Step name.
|
1684 |
-
if ( $step['function']
|
1685 |
if ( count( $step['args'][0] ) == 1 ) {
|
1686 |
$step_name = 'Database dump (breakout: ' . $step['args'][0][0] . ')';
|
1687 |
} else {
|
1688 |
$step_name = 'Database dump';
|
1689 |
}
|
1690 |
-
} elseif ( $step['function']
|
1691 |
if ( isset( $backup_options->options['steps']['backup_zip_files'] ) ) {
|
1692 |
$zip_time = $backup_options->options['steps']['backup_zip_files'];
|
1693 |
} else {
|
@@ -1695,33 +2112,32 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1695 |
}
|
1696 |
|
1697 |
// Calculate write speed in MB/sec for this backup.
|
1698 |
-
if (
|
1699 |
-
$write_speed = '> ' . pb_backupbuddy::$format->file_size( $backup_options->options['integrity']['size'] );
|
1700 |
} else {
|
1701 |
-
if (
|
1702 |
$write_speed = '';
|
1703 |
} else {
|
1704 |
-
$write_speed = pb_backupbuddy::$format->file_size( $backup_options->options['integrity']['size'] / $zip_time ) . '/sec';
|
1705 |
}
|
1706 |
}
|
1707 |
$step_name = 'Zip archive creation (Write speed: ' . $write_speed . ')';
|
1708 |
-
} elseif ( $step['function']
|
1709 |
$step_name = 'Post-backup cleanup';
|
1710 |
-
} elseif( $step['function']
|
1711 |
$step_name = 'Integrity Check';
|
1712 |
} else {
|
1713 |
$step_name = $step['function'];
|
1714 |
}
|
1715 |
|
1716 |
// Step time taken.
|
1717 |
-
$seconds = (int)( $step['finish_time'] - $step['start_time'] );
|
1718 |
if ( $seconds < 1 ) {
|
1719 |
$step_time = '< 1 second';
|
1720 |
} else {
|
1721 |
$step_time = $seconds . ' seconds';
|
1722 |
}
|
1723 |
|
1724 |
-
|
1725 |
// Compile details for this step into array.
|
1726 |
$steps[] = array(
|
1727 |
$step_name,
|
@@ -1730,14 +2146,13 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1730 |
);
|
1731 |
|
1732 |
}
|
1733 |
-
}
|
1734 |
-
} else {
|
1735 |
$step_times[] = 'unknown';
|
1736 |
-
}
|
1737 |
-
|
1738 |
|
1739 |
// Total overall time from initiation to end.
|
1740 |
-
if ( isset( $backup_options->options['finish_time'] ) && isset( $backup_options->options['start_time'] ) && ( $backup_options->options['finish_time']
|
1741 |
$seconds = ( $backup_options->options['finish_time'] - $backup_options->options['start_time'] );
|
1742 |
if ( $seconds < 1 ) {
|
1743 |
$total_time = '< 1 second';
|
@@ -1763,16 +2178,16 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1763 |
if ( count( $steps ) == 0 ) {
|
1764 |
_e( 'No step statistics were found for this backup.', 'mainwp-child' );
|
1765 |
} else {
|
1766 |
-
pb_backupbuddy::$ui->list_table(
|
1767 |
$steps,
|
1768 |
array(
|
1769 |
-
'columns'
|
1770 |
-
'css'
|
1771 |
)
|
1772 |
);
|
1773 |
}
|
1774 |
echo '<br><br>';
|
1775 |
-
|
1776 |
|
1777 |
if ( isset( $backup_options->options['trigger'] ) ) {
|
1778 |
$trigger = $backup_options->options['trigger'];
|
@@ -1780,7 +2195,7 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1780 |
$trigger = 'Unknown trigger';
|
1781 |
}
|
1782 |
if ( isset( $integrity['scan_time'] ) ) {
|
1783 |
-
$scanned = pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $integrity['scan_time'] ) );
|
1784 |
echo ucfirst( $trigger ) . " backup {$integrity['file']} last scanned {$scanned}.";
|
1785 |
}
|
1786 |
echo '<br><br><br>';
|
@@ -1788,60 +2203,78 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1788 |
echo '<a class="button secondary-button" onclick="jQuery(\'#pb_backupbuddy_advanced_debug\').slideToggle();">Display Advanced Debugging</a>';
|
1789 |
echo '<div id="pb_backupbuddy_advanced_debug" style="display: none;">From options file: `' . $optionsFile . '`.<br>';
|
1790 |
echo '<textarea style="width: 100%; height: 400px;" wrap="on">';
|
1791 |
-
echo print_r( $backup_options->options, true );
|
1792 |
echo '</textarea><br><br>';
|
1793 |
echo '</div><br><br>';
|
1794 |
|
1795 |
$html = ob_get_clean();
|
1796 |
-
pb_backupbuddy::flush();
|
1797 |
-
return array(
|
|
|
|
|
|
|
1798 |
}
|
1799 |
|
1800 |
-
|
1801 |
-
|
|
|
|
|
|
|
|
|
|
|
1802 |
$information['backup_list'] = $this->get_backup_list();
|
1803 |
-
$information['result']
|
1804 |
return $information;
|
1805 |
}
|
1806 |
|
1807 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1808 |
|
1809 |
if ( ! isset( $_GET['_wpnonce'] ) || empty( $_GET['_wpnonce'] ) ) {
|
1810 |
die( '-1' );
|
1811 |
}
|
1812 |
|
1813 |
-
if ( !
|
1814 |
die( '-2' );
|
1815 |
}
|
1816 |
|
1817 |
-
backupbuddy_core::verifyAjaxAccess();
|
1818 |
|
1819 |
-
if ( is_multisite() && !current_user_can( 'manage_network' ) ) { // If a Network and NOT the superadmin must make sure they can only download the specific subsite backups for security purposes.
|
1820 |
|
1821 |
-
if ( !strstr( pb_backupbuddy::_GET( 'backupbuddy_backup' ), backupbuddy_core::backup_prefix() ) ) {
|
1822 |
die( 'Access Denied. You may only download backups specific to your Multisite Subsite. Only Network Admins may download backups for another subsite in the network.' );
|
1823 |
}
|
1824 |
}
|
1825 |
|
1826 |
-
if ( !file_exists( backupbuddy_core::getBackupDirectory() . pb_backupbuddy::_GET( 'backupbuddy_backup' ) ) ) { // Does not exist.
|
1827 |
die( 'Error #548957857584784332. The requested backup file does not exist. It may have already been deleted.' );
|
1828 |
}
|
1829 |
|
1830 |
-
$abspath
|
1831 |
-
$backup_dir = str_replace( '\\', '/', backupbuddy_core::getBackupDirectory() );
|
1832 |
|
1833 |
-
if (
|
1834 |
die( 'Error #5432532. You cannot download backups stored outside of the WordPress web root. Please use FTP or other means.' );
|
1835 |
}
|
1836 |
|
1837 |
-
$sitepath
|
1838 |
-
$download_url = rtrim( site_url(), '/\\' ) . '/' . trim( $sitepath, '/\\' ) . '/' . pb_backupbuddy::_GET( 'backupbuddy_backup' );
|
1839 |
|
1840 |
-
if ( pb_backupbuddy::$options['lock_archives_directory']
|
1841 |
|
1842 |
-
if ( file_exists( backupbuddy_core::getBackupDirectory() . '.htaccess' ) ) {
|
1843 |
-
$unlink_status =
|
1844 |
-
if (
|
1845 |
die( 'Error #844594. Unable to temporarily remove .htaccess security protection on archives directory to allow downloading. Please verify permissions of the BackupBuddy archives directory or manually download via FTP.' );
|
1846 |
}
|
1847 |
}
|
@@ -1851,211 +2284,270 @@ class MainWP_Child_Back_Up_Buddy {
|
|
1851 |
flush();
|
1852 |
sleep( 8 );
|
1853 |
|
1854 |
-
$htaccess_creation_status =
|
1855 |
-
if (
|
1856 |
die( 'Error #344894545. Security Warning! Unable to create security file (.htaccess) in backups archive directory. This file prevents unauthorized downloading of backups should someone be able to guess the backup location and filenames. This is unlikely but for best security should be in place. Please verify permissions on the backups directory.' );
|
1857 |
}
|
1858 |
-
|
1859 |
} else {
|
1860 |
header( 'Location: ' . $download_url );
|
1861 |
}
|
1862 |
die();
|
1863 |
}
|
1864 |
|
1865 |
-
|
1866 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1867 |
|
1868 |
-
if (!isset(pb_backupbuddy::$options['profiles'][ $requested_profile ])) {
|
1869 |
-
return array('error' => 'Invalid Profile. Not found.');
|
1870 |
}
|
1871 |
|
1872 |
-
require_once
|
1873 |
-
$newBackup = new pb_backupbuddy_backup();
|
1874 |
|
1875 |
-
$profile_array
|
1876 |
-
$serial_override = pb_backupbuddy::random_string( 10 );
|
1877 |
|
1878 |
-
if ( $newBackup->start_backup_process(
|
1879 |
-
|
1880 |
-
'manual', // trigger
|
1881 |
-
array(),
|
1882 |
-
isset($_POST['post_backup_steps']) && is_array($_POST['post_backup_steps']) ? $_POST['post_backup_steps'] : array(),
|
1883 |
-
'',
|
1884 |
-
$serial_override,
|
1885 |
-
'', // export_plugins
|
1886 |
-
'', // direction
|
1887 |
-
'' // deployDestination
|
1888 |
-
) !== true ) {
|
1889 |
-
return array('error' => __('Fatal Error #4344443: Backup failure. Please see any errors listed in the Status Log for details.', 'it-l10n-backupbuddy' ));
|
1890 |
}
|
1891 |
-
return array('result' => 'SUCCESS');
|
1892 |
}
|
1893 |
|
1894 |
-
|
1895 |
-
|
1896 |
-
|
1897 |
-
|
1898 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1899 |
if ( $newBackup->start_backup_process(
|
1900 |
-
|
1901 |
-
|
1902 |
-
|
1903 |
-
|
1904 |
-
|
1905 |
-
|
1906 |
-
|
1907 |
-
|
1908 |
-
|
1909 |
-
|
1910 |
-
return array('error' => __('Fatal Error #4344443: Backup failure. Please see any errors listed in the Status Log for details.', '
|
1911 |
}
|
1912 |
} else {
|
1913 |
-
return array('error' => 'Invalid backup request.');
|
1914 |
}
|
1915 |
|
1916 |
-
return array('ok' => 1);
|
1917 |
-
|
1918 |
}
|
1919 |
|
1920 |
-
|
1921 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1922 |
$result = '';
|
1923 |
-
if (is_array($data) && isset($data['serial'])) {
|
1924 |
ob_start();
|
1925 |
-
backupbuddy_api::getBackupStatus( $data['serial'], $data['specialAction'], $data['initwaitretrycount'],
|
1926 |
$result = ob_get_clean();
|
1927 |
} else {
|
1928 |
-
return array('error' => 'Invalid backup request.');
|
1929 |
}
|
1930 |
-
return array(
|
|
|
|
|
|
|
1931 |
}
|
1932 |
|
1933 |
-
|
1934 |
-
|
1935 |
-
|
1936 |
-
|
|
|
|
|
|
|
|
|
|
|
1937 |
}
|
1938 |
|
1939 |
-
|
1940 |
-
|
1941 |
-
|
1942 |
-
|
1943 |
-
|
1944 |
-
|
1945 |
-
|
1946 |
-
|
1947 |
-
|
1948 |
-
|
1949 |
-
|
1950 |
-
|
1951 |
-
|
1952 |
-
|
1953 |
-
|
1954 |
-
|
1955 |
-
|
1956 |
-
|
1957 |
-
|
1958 |
-
|
1959 |
-
|
1960 |
-
|
1961 |
-
|
1962 |
-
|
|
|
|
|
|
|
|
|
|
|
1963 |
|
|
|
|
|
1964 |
|
1965 |
-
if (is_array($data)) {
|
1966 |
-
if (isset(pb_backupbuddy::$options['remote_destinations'][$destination_id])) {
|
1967 |
-
pb_backupbuddy::$options['remote_destinations'][$destination_id] = array_merge( pb_backupbuddy::$options['remote_destinations'][$destination_id], $data );
|
1968 |
-
} else {
|
1969 |
-
$data['token'] = pb_backupbuddy::$options['dropboxtemptoken'];
|
1970 |
-
pb_backupbuddy::$options['remote_destinations'][$destination_id] = $data;
|
1971 |
}
|
1972 |
-
pb_backupbuddy::save();
|
1973 |
-
return array('ok' => 1);
|
1974 |
} else {
|
1975 |
-
return array('error' => 'Invalid request.');
|
1976 |
}
|
1977 |
}
|
1978 |
|
1979 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1980 |
$information = array();
|
1981 |
-
if (isset(pb_backupbuddy::$options['remote_destinations'])) {
|
1982 |
-
$information['remote_destinations'] = pb_backupbuddy::$options['remote_destinations'];
|
1983 |
}
|
1984 |
$information['result'] = 'SUCCESS';
|
1985 |
return $information;
|
1986 |
}
|
1987 |
|
1988 |
-
|
1989 |
-
|
1990 |
-
|
1991 |
-
|
1992 |
-
|
1993 |
-
|
1994 |
-
|
1995 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1996 |
} else {
|
1997 |
-
return array('ok' => 1);
|
1998 |
}
|
1999 |
} else {
|
2000 |
-
return array('error' => 'Invalid request.');
|
2001 |
}
|
2002 |
}
|
2003 |
|
2004 |
-
|
2005 |
-
|
2006 |
-
|
2007 |
-
|
2008 |
-
|
2009 |
-
|
2010 |
-
|
2011 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012 |
if ( ! file_exists( $backup_file ) ) { // Error if file to send did not exist!
|
2013 |
$error_message = 'Unable to find file `' . $backup_file . '` to send. File does not appear to exist. You can try again in a moment or turn on full error logging and try again to log for support.';
|
2014 |
-
pb_backupbuddy::status( 'error', $error_message );
|
2015 |
-
return array( 'error' => $error_message);
|
2016 |
}
|
2017 |
if ( is_dir( $backup_file ) ) { // Error if a directory is trying to be sent.
|
2018 |
$error_message = 'You are attempting to send a directory, `' . $backup_file . '`. Try again and verify there were no javascript errors.';
|
2019 |
-
pb_backupbuddy::status( 'error', $error_message );
|
2020 |
-
return array( 'error' => $error_message);
|
2021 |
}
|
2022 |
} else {
|
2023 |
$backup_file = '';
|
2024 |
}
|
2025 |
|
2026 |
-
if ( isset($_POST['send_importbuddy']) && $_POST['send_importbuddy']
|
2027 |
$send_importbuddy = true;
|
2028 |
-
pb_backupbuddy::status( 'details', 'Cron send to be scheduled with importbuddy sending.' );
|
2029 |
} else {
|
2030 |
$send_importbuddy = false;
|
2031 |
-
pb_backupbuddy::status( 'details', 'Cron send to be scheduled WITHOUT importbuddy sending.' );
|
2032 |
}
|
2033 |
|
2034 |
-
if ( isset($_POST['delete_after']) && $_POST['delete_after']
|
2035 |
$delete_after = true;
|
2036 |
-
pb_backupbuddy::status( 'details', 'Remote send set to delete after successful send.' );
|
2037 |
} else {
|
2038 |
$delete_after = false;
|
2039 |
-
pb_backupbuddy::status( 'details', 'Remote send NOT set to delete after successful send.' );
|
2040 |
}
|
2041 |
|
2042 |
-
if ( !isset( pb_backupbuddy::$options['remote_destinations'][$destination_id] ) ) {
|
2043 |
return array( 'error' => 'Error #833383: Invalid destination ID `' . htmlentities( $destination_id ) . '`.' );
|
2044 |
}
|
2045 |
|
2046 |
-
|
2047 |
// For Stash we will check the quota prior to initiating send.
|
2048 |
-
if ( pb_backupbuddy::$options['remote_destinations'][$destination_id]['type']
|
2049 |
// Pass off to destination handler.
|
2050 |
-
require_once
|
2051 |
-
$send_result = pb_backupbuddy_destinations::get_info( 'stash' ); // Used to kick the Stash destination into life.
|
2052 |
-
$stash_quota = pb_backupbuddy_destination_stash::get_quota( pb_backupbuddy::$options['remote_destinations'][$destination_id], true );
|
2053 |
|
2054 |
if ( isset( $stash_quota['error'] ) ) {
|
2055 |
-
return array( 'error' =>
|
2056 |
}
|
2057 |
|
2058 |
-
if (
|
2059 |
$backup_file_size = filesize( $backup_file );
|
2060 |
} else {
|
2061 |
$backup_file_size = 50000;
|
@@ -2063,100 +2555,124 @@ class MainWP_Child_Back_Up_Buddy {
|
|
2063 |
if ( ( $backup_file_size + $stash_quota['quota_used'] ) > $stash_quota['quota_total'] ) {
|
2064 |
ob_start();
|
2065 |
echo "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage or delete files to make space.\n\n";
|
2066 |
-
echo 'Attempting to send file of size ' . pb_backupbuddy::$format->file_size( $backup_file_size ) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. ';
|
2067 |
echo 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).';
|
2068 |
$error = ob_get_clean();
|
2069 |
return array( 'error' => $error );
|
2070 |
} else {
|
2071 |
-
if ( isset( $stash_quota['quota_warning'] ) && ( $stash_quota['quota_warning']
|
2072 |
-
$warning
|
2073 |
$success_output = true;
|
2074 |
}
|
2075 |
}
|
|
|
2076 |
|
2077 |
-
|
2078 |
-
|
2079 |
-
pb_backupbuddy::status( 'details', 'Scheduling cron to send to this remote destination...' );
|
2080 |
|
2081 |
-
$schedule_result = backupbuddy_core::schedule_single_event( time(), 'remote_send', array( $destination_id, $backup_file, $trigger, $send_importbuddy, $delete_after ) );
|
2082 |
-
if (
|
2083 |
$error = 'Error scheduling file transfer. Please check your BackupBuddy error log for details. A plugin may have prevented scheduling or the database rejected it.';
|
2084 |
-
pb_backupbuddy::status( 'error', $error );
|
2085 |
-
return array( 'error' => $error);
|
2086 |
} else {
|
2087 |
-
pb_backupbuddy::status( 'details', 'Cron to send to remote destination scheduled.' );
|
2088 |
}
|
2089 |
-
if ( '1' != pb_backupbuddy::$options['skip_spawn_cron_call'] ) {
|
2090 |
update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item.
|
2091 |
spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit.
|
2092 |
}
|
2093 |
-
return array( 'ok' => 1);
|
2094 |
}
|
2095 |
|
2096 |
-
|
2097 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2098 |
ob_start();
|
2099 |
if ( file_exists( $log_file ) ) {
|
2100 |
readfile( $log_file );
|
2101 |
} else {
|
2102 |
-
echo __('Nothing has been logged.', '
|
2103 |
}
|
2104 |
$result = ob_get_clean();
|
2105 |
-
return array('result' => $result );
|
2106 |
}
|
2107 |
|
2108 |
-
|
2109 |
-
|
2110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2111 |
|
2112 |
$message = '';
|
2113 |
-
$error
|
2114 |
|
2115 |
-
if ( 'cleanup_now' ==
|
2116 |
$message = 'Performing cleanup procedures now trimming old files and data.';
|
2117 |
-
require_once
|
2118 |
-
backupbuddy_housekeeping::run_periodic( 0 ); // 0 cleans up everything even if not very old.
|
2119 |
-
|
2120 |
-
}
|
2121 |
-
$tempDir = backupbuddy_core::getTempDirectory();
|
2122 |
-
$logDir
|
2123 |
-
$message = 'Deleting all files contained within `' . $tempDir . '` and `' . $logDir . '`.'
|
2124 |
-
pb_backupbuddy::$filesystem->unlink_recursive( $tempDir );
|
2125 |
-
pb_backupbuddy::$filesystem->unlink_recursive( $logDir );
|
2126 |
-
pb_backupbuddy::anti_directory_browsing( $logDir, $die = false ); // Put log dir back in place.
|
2127 |
-
}
|
2128 |
-
$log_file = backupbuddy_core::getLogDirectory() . 'log-' . pb_backupbuddy::$options['log_serial'] . '.txt';
|
2129 |
if ( file_exists( $log_file ) ) {
|
2130 |
-
|
2131 |
}
|
2132 |
if ( file_exists( $log_file ) ) { // Didnt unlink.
|
2133 |
$error = 'Unable to clear log file. Please verify permissions on file `' . $log_file . '`.';
|
2134 |
} else { // Unlinked.
|
2135 |
$message = 'Cleared log file.';
|
2136 |
}
|
2137 |
-
}
|
2138 |
-
pb_backupbuddy::$options['disalerts'] = array();
|
2139 |
-
pb_backupbuddy::save();
|
2140 |
$message = 'Dismissed alerts have been reset. They may now be visible again.';
|
2141 |
|
2142 |
-
}
|
2143 |
-
require_once
|
2144 |
|
2145 |
-
$fileoptions_directory = backupbuddy_core::getLogDirectory() . 'fileoptions/';
|
2146 |
-
$files
|
2147 |
if ( ! is_array( $files ) ) {
|
2148 |
$files = array();
|
2149 |
}
|
2150 |
$cancelCount = 0;
|
2151 |
-
for ($x = 0; $x <= 3; $x++) { // Try this a few times since there may be race conditions on an open file.
|
2152 |
-
foreach( $files as $file ) {
|
2153 |
-
pb_backupbuddy::status( 'details', 'Fileoptions instance #383.' );
|
2154 |
-
|
2155 |
-
$backup_options = new pb_backupbuddy_fileoptions( $file, $read_only = false );
|
2156 |
-
|
2157 |
-
|
|
|
2158 |
} else {
|
2159 |
-
if ( empty( $backup_options->options['finish_time'] ) || ( (
|
2160 |
$backup_options->options['finish_time'] = -1; // Force marked as cancelled by user.
|
2161 |
$backup_options->save();
|
2162 |
$cancelCount++;
|
@@ -2169,12 +2685,25 @@ class MainWP_Child_Back_Up_Buddy {
|
|
2169 |
$message = 'Marked all timed out or running backups & transfers as officially cancelled (`' . $cancelCount . '` total found).';
|
2170 |
}
|
2171 |
|
2172 |
-
return array(
|
|
|
|
|
|
|
2173 |
}
|
2174 |
|
2175 |
-
|
2176 |
-
|
2177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2178 |
update_option( '_transient_doing_cron', 0 );
|
2179 |
spawn_cron( time() + 150 );
|
2180 |
|
@@ -2184,7 +2713,7 @@ class MainWP_Child_Back_Up_Buddy {
|
|
2184 |
$url = home_url();
|
2185 |
} else {
|
2186 |
$url = str_replace( $_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI'] );
|
2187 |
-
$url = str_replace( basename( $url )
|
2188 |
$url = 'http://' . $_SERVER['HTTP_HOST'] . $url;
|
2189 |
}
|
2190 |
?>
|
@@ -2199,7 +2728,7 @@ class MainWP_Child_Back_Up_Buddy {
|
|
2199 |
|
2200 |
|
2201 |
<?php
|
2202 |
-
pb_backupbuddy::$ui->start_metabox( __( 'Malware Scan URL', '
|
2203 |
|
2204 |
?>
|
2205 |
|
@@ -2208,19 +2737,18 @@ class MainWP_Child_Back_Up_Buddy {
|
|
2208 |
<?php
|
2209 |
|
2210 |
$continue_1 = true;
|
2211 |
-
if (
|
2212 |
-
_e('ERROR: You are currently running your site locally. Your site must be internet accessible to scan.', '
|
2213 |
$continue_1 = false;
|
2214 |
}
|
2215 |
|
2216 |
-
if (
|
2217 |
|
2218 |
-
if ( !empty( $_POST['refresh'] ) ) {
|
2219 |
delete_transient( 'pb_backupbuddy_malwarescan' );
|
2220 |
}
|
2221 |
|
2222 |
-
|
2223 |
-
if ( !defined( 'pluginbuddy_importbuddy' ) ) {
|
2224 |
$scan = get_transient( 'pb_backupbuddy_malwarescan' );
|
2225 |
} else {
|
2226 |
$scan = false;
|
@@ -2230,164 +2758,265 @@ class MainWP_Child_Back_Up_Buddy {
|
|
2230 |
flush();
|
2231 |
|
2232 |
$scan = wp_remote_get(
|
2233 |
-
'http://sitecheck.sucuri.net/scanner/?scan=' .
|
2234 |
array(
|
2235 |
-
'method'
|
2236 |
-
'timeout'
|
2237 |
'redirection' => 5,
|
2238 |
'httpversion' => '1.0',
|
2239 |
-
'blocking'
|
2240 |
-
'headers'
|
2241 |
-
'body'
|
2242 |
-
'cookies'
|
2243 |
)
|
2244 |
);
|
2245 |
|
2246 |
if ( is_wp_error( $scan ) ) {
|
2247 |
-
pb_backupbuddy::alert( __('ERROR #24452. Unable to load Malware Scan results. Details:', '
|
2248 |
$scan = 'N;';
|
2249 |
} else {
|
2250 |
$scan = $scan['body'];
|
2251 |
-
set_transient( 'pb_backupbuddy_malwarescan', $scan, 60*60*1 ); // 1 hour cache.
|
2252 |
}
|
2253 |
-
|
2254 |
}
|
2255 |
|
2256 |
$continue_2 = true;
|
2257 |
if ( substr( $scan, 0, 2 ) == 'N;' ) {
|
2258 |
-
echo __('An error was encountered attempting to scan this site.','
|
2259 |
-
echo __('An internet connection is required and this site must be accessible on the public internet.', '
|
2260 |
echo '<br>';
|
2261 |
-
$scan
|
2262 |
$continue_2 = false;
|
2263 |
} else {
|
2264 |
$scan = maybe_unserialize( $scan );
|
2265 |
-
//echo '<pre>';
|
2266 |
-
//print_r( $scan );
|
2267 |
-
//echo '</pre>';
|
2268 |
}
|
2269 |
-
|
2270 |
}
|
|
|
2271 |
|
2272 |
-
|
2273 |
-
?>
|
2274 |
-
|
2275 |
-
|
2276 |
|
2277 |
-
|
2278 |
-
|
2279 |
-
|
2280 |
-
|
|
|
|
|
|
|
2281 |
function lined_array( $array ) {
|
2282 |
if ( is_array( $array ) ) {
|
2283 |
-
foreach( $array as $array_key => $array_item ) {
|
2284 |
if ( is_array( $array_item ) ) {
|
2285 |
-
$array[$array_key] = lined_array( $array_item );
|
2286 |
}
|
2287 |
}
|
2288 |
-
//return implode( '<br />', $array );
|
2289 |
$return = '';
|
2290 |
-
foreach( $array as $array_item ) {
|
2291 |
$return .= $array_item . '<br />';
|
2292 |
}
|
2293 |
return $return;
|
2294 |
} else {
|
2295 |
if ( empty( $array ) ) {
|
2296 |
-
return '<i>'.__('none', '
|
2297 |
} else {
|
2298 |
return $array . '<br />';
|
2299 |
}
|
2300 |
}
|
2301 |
}
|
2302 |
|
2303 |
-
if ( !empty( $scan['MALWARE'] ) && ( $scan['MALWARE']
|
2304 |
-
echo '<table><tr><td><i class="fa fa-exclamation-circle fa-5x" style="color: red"></i></td><td><h1>', __('Warning: Possible Malware Detected!', '
|
2305 |
}
|
2306 |
-
|
2307 |
?>
|
2308 |
-
|
2309 |
-
|
2310 |
<div class="postbox-container" style="width: 100%; min-width: 750px;">
|
2311 |
<div class="metabox-holder">
|
2312 |
<div class="meta-box-sortables">
|
2313 |
|
2314 |
<div id="breadcrumbslike" class="postbox">
|
2315 |
-
<div class="handlediv" title="<?php _e('Click to toggle', '
|
2316 |
-
<h3 class="hndle"><span><?php _e('Malware Detection', '
|
2317 |
<div class="inside">
|
2318 |
-
<label><?php _e('Malware', '
|
2319 |
<?php
|
2320 |
-
if ( !empty( $scan['MALWARE']['WARN'] ) ) { // Malware found.
|
2321 |
echo lined_array( $scan['MALWARE']['WARN'] );
|
2322 |
-
backupbuddy_core::addNotification( 'malware_found', 'Malware detected on `' . $url . '`.', 'A malware scan was run on the site and detected malware.', array(), true );
|
2323 |
} else { // No malware found.
|
2324 |
-
echo '<i>', __('none', '
|
2325 |
-
backupbuddy_core::addNotification( 'malware_not_found', 'No malware detected on `' . $url . '`.', 'A malware scan was run on the site and did not detect malware.' );
|
2326 |
-
}
|
|
|
|
|
2327 |
</div>
|
2328 |
</div>
|
2329 |
|
2330 |
<div id="breadcrumbslike" class="postbox">
|
2331 |
-
<div class="handlediv" title="<?php _e('Click to toggle', '
|
2332 |
-
<h3 class="hndle"><span><?php _e('Web server details', '
|
2333 |
<div class="inside">
|
2334 |
-
<label><?php _e('Site', '
|
2335 |
-
|
2336 |
-
|
2337 |
-
|
2338 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2339 |
</div>
|
2340 |
</div>
|
2341 |
-
|
2342 |
<div id="breadcrumbslike" class="postbox">
|
2343 |
<div class="handlediv" title="Click to toggle"><br /></div>
|
2344 |
-
<h3 class="hndle"><span><?php _e('Web application', '
|
2345 |
<div class="inside">
|
2346 |
-
<label><?php _e('Details', '
|
2347 |
-
|
2348 |
-
|
2349 |
-
|
2350 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2351 |
</div>
|
2352 |
</div>
|
2353 |
|
2354 |
<div id="breadcrumbslike" class="postbox">
|
2355 |
-
<div class="handlediv" title="<?php _e('Click to toggle', '
|
2356 |
-
<h3 class="hndle"><span><?php _e('Links', '
|
2357 |
<div class="inside">
|
2358 |
-
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2359 |
</div>
|
2360 |
</div>
|
2361 |
|
2362 |
<div id="breadcrumbslike" class="postbox">
|
2363 |
-
<div class="handlediv" title="<?php _e('Click to toggle', '
|
2364 |
-
<h3 class="hndle"><span><?php _e('Local Javascript', '
|
2365 |
<div class="inside">
|
2366 |
-
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2367 |
</div>
|
2368 |
</div>
|
2369 |
|
2370 |
<div id="breadcrumbslike" class="postbox">
|
2371 |
-
<div class="handlediv" title="<?php _e('Click to toggle', '
|
2372 |
-
<h3 class="hndle"><span><?php _e('External Javascript', '
|
2373 |
<div class="inside">
|
2374 |
-
<?php
|
|
|
|
|
|
|
|
|
|
|
2375 |
</div>
|
2376 |
</div>
|
2377 |
|
2378 |
<div id="breadcrumbslike" class="postbox">
|
2379 |
-
<div class="handlediv" title="<?php
|
2380 |
-
<h3 class="hndle"><span><?php
|
2381 |
<div class="inside">
|
2382 |
-
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2383 |
</div>
|
2384 |
</div>
|
2385 |
|
2386 |
<div id="breadcrumbslike" class="postbox">
|
2387 |
-
<div class="handlediv" title="<?php
|
2388 |
-
<h3 class="hndle"><span><?php
|
2389 |
<div class="inside">
|
2390 |
-
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2391 |
</div>
|
2392 |
</div>
|
2393 |
|
@@ -2396,23 +3025,38 @@ class MainWP_Child_Back_Up_Buddy {
|
|
2396 |
</div>
|
2397 |
<?php
|
2398 |
|
2399 |
-
|
2400 |
}
|
2401 |
$result = ob_get_clean();
|
2402 |
|
2403 |
-
return array('result' => $result);
|
2404 |
}
|
2405 |
|
2406 |
|
2407 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2408 |
|
2409 |
$errors = array();
|
2410 |
|
2411 |
$archive_types = array(
|
2412 |
-
'db'
|
2413 |
-
'full'
|
2414 |
-
'plugins' => __( 'Plugins Backup', '
|
2415 |
-
'themes'
|
2416 |
);
|
2417 |
|
2418 |
$archive_periods = array(
|
@@ -2422,28 +3066,29 @@ class MainWP_Child_Back_Up_Buddy {
|
|
2422 |
'yearly',
|
2423 |
);
|
2424 |
|
2425 |
-
|
2426 |
if ( ( '' == $_POST['live_username'] ) || ( '' == $_POST['live_password'] ) ) { // A field is blank.
|
2427 |
$errors[] = 'You must enter your iThemes username & password to log in to BackupBuddy Stash Live.';
|
2428 |
} else { // Username and password provided.
|
2429 |
|
2430 |
-
require_once
|
2431 |
-
require_once
|
2432 |
-
require_once
|
|
|
|
|
2433 |
global $wp_version;
|
2434 |
|
2435 |
$itxapi_username = strtolower( $_POST['live_username'] );
|
2436 |
-
$password_hash
|
2437 |
-
$access_token
|
2438 |
|
2439 |
$settings = array(
|
2440 |
'itxapi_username' => $itxapi_username,
|
2441 |
'itxapi_password' => $access_token,
|
2442 |
);
|
2443 |
-
$response = pb_backupbuddy_destination_stash2::stashAPI( $settings, 'connect' );
|
2444 |
|
2445 |
if ( ! is_array( $response ) ) { // Error message.
|
2446 |
-
$errors[] = print_r( $response, true );
|
2447 |
} else {
|
2448 |
if ( isset( $response['error'] ) ) {
|
2449 |
$errors[] = $response['error']['message'];
|
@@ -2451,130 +3096,146 @@ class MainWP_Child_Back_Up_Buddy {
|
|
2451 |
if ( isset( $response['token'] ) ) {
|
2452 |
$itxapi_token = $response['token'];
|
2453 |
} else {
|
2454 |
-
$errors[] = 'Error #2308832: Unexpected server response. Token missing. Check your BackupBuddy Stash Live login and try again. Detailed response: `' . print_r( $response, true ) .'`.';
|
2455 |
}
|
2456 |
}
|
2457 |
}
|
2458 |
|
2459 |
// If we have the token then create the Live destination.
|
2460 |
if ( isset( $itxapi_token ) ) {
|
2461 |
-
if ( count( pb_backupbuddy::$options['remote_destinations'] ) > 0 ) {
|
2462 |
-
$nextDestKey = max( array_keys( pb_backupbuddy::$options['remote_destinations'] ) ) + 1;
|
2463 |
} else { // no destinations yet. first index.
|
2464 |
$nextDestKey = 0;
|
2465 |
}
|
2466 |
|
2467 |
-
pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]
|
2468 |
-
pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['itxapi_username'] = $_POST['live_username'];
|
2469 |
-
pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['itxapi_token']
|
2470 |
-
pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['title']
|
2471 |
|
2472 |
// Notification email.
|
2473 |
-
pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['email'] = $_POST['email'];
|
2474 |
|
2475 |
// Archive limits.
|
2476 |
-
foreach( $archive_types as $archive_type => $archive_type_name ) {
|
2477 |
-
foreach( $archive_periods as $archive_period ) {
|
2478 |
$settings_name = 'limit_' . $archive_type . '_' . $archive_period;
|
2479 |
-
pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ][ $settings_name ] = $_POST['live_settings'][$settings_name];
|
2480 |
}
|
2481 |
}
|
2482 |
|
2483 |
if ( '1' == $_POST['send_snapshot_notification'] ) {
|
2484 |
-
pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['send_snapshot_notification'] = $_POST['send_snapshot_notification'];
|
2485 |
} else {
|
2486 |
-
pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['send_snapshot_notification'] = '0';
|
2487 |
}
|
2488 |
|
2489 |
-
pb_backupbuddy::save();
|
2490 |
$destination_id = $nextDestKey;
|
2491 |
|
2492 |
// Send new settings for archive limiting to Stash API.
|
2493 |
-
backupbuddy_live::send_trim_settings();
|
2494 |
-
|
2495 |
-
|
2496 |
|
2497 |
// Set first run of BackupBuddy Stash Live so it begins immediately.
|
2498 |
-
$cronArgs
|
2499 |
-
$schedule_result = backupbuddy_core::schedule_single_event( time(), 'live_periodic', $cronArgs );
|
2500 |
if ( true === $schedule_result ) {
|
2501 |
-
pb_backupbuddy::status( 'details', 'Next Live Periodic chunk step cron event scheduled.' );
|
2502 |
} else {
|
2503 |
-
pb_backupbuddy::status( 'error', 'Next Live Periodic chunk step cron event FAILED to be scheduled.' );
|
2504 |
}
|
2505 |
-
if ( '1' != pb_backupbuddy::$options['skip_spawn_cron_call'] ) {
|
2506 |
-
pb_backupbuddy::status( 'details', 'Spawning cron now.' );
|
2507 |
update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item.
|
2508 |
spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit.
|
2509 |
}
|
2510 |
-
|
2511 |
}
|
2512 |
-
|
2513 |
} // end if user and pass set.
|
2514 |
|
2515 |
-
|
2516 |
if ( 0 == count( $errors ) ) {
|
2517 |
-
pb_backupbuddy::save();
|
2518 |
-
$data = pb_backupbuddy::$options['remote_destinations'][ $destination_id ];
|
2519 |
-
return array(
|
|
|
|
|
|
|
2520 |
} else {
|
2521 |
return array( 'errors' => $errors );
|
2522 |
}
|
2523 |
-
|
2524 |
}
|
2525 |
|
2526 |
-
|
2527 |
-
|
2528 |
-
|
2529 |
-
|
2530 |
-
|
2531 |
-
|
2532 |
-
|
2533 |
-
|
2534 |
-
|
2535 |
-
|
2536 |
-
|
2537 |
-
|
2538 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2539 |
|
2540 |
$error = '';
|
2541 |
-
if ( $new_destination_id && is_array($data) ) {
|
2542 |
-
$itxapi_username
|
2543 |
-
$itxapi_token
|
2544 |
-
$destination_settings
|
2545 |
$destination_settings['itxapi_username'] = $itxapi_username;
|
2546 |
-
$destination_settings['itxapi_token']
|
2547 |
-
pb_backupbuddy::$options['remote_destinations'][$new_destination_id] = $destination_settings;
|
2548 |
|
2549 |
-
if ($check_current && $destination_id != $new_destination_id) {
|
2550 |
-
unset(pb_backupbuddy::$options['remote_destinations'][$destination_id]);
|
2551 |
}
|
2552 |
|
2553 |
-
pb_backupbuddy::save();
|
2554 |
-
|
2555 |
-
set_transient( 'backupbuddy_live_jump', array( 'daily_init', array() ), 60*60*48 ); // Tells Live process to restart from the beginning (if mid-process) so new settigns apply.
|
2556 |
|
2557 |
-
backupbuddy_live::send_trim_settings();
|
2558 |
-
return array('ok' => 1);
|
2559 |
} else {
|
2560 |
$error = 'Invalid data. Please check and try again.';
|
2561 |
}
|
2562 |
-
return array('error' => $error);
|
2563 |
}
|
2564 |
|
2565 |
-
|
2566 |
-
|
2567 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2568 |
|
2569 |
$return = array();
|
2570 |
-
if ($liveDestinationID) {
|
2571 |
-
if (isset(pb_backupbuddy::$options['remote_destinations'][ $liveDestinationID ])) {
|
2572 |
// Clear destination settings.
|
2573 |
-
unset( pb_backupbuddy::$options['remote_destinations'][ $liveDestinationID ] );
|
2574 |
-
pb_backupbuddy::save();
|
2575 |
// Clear cached Live credentials.
|
2576 |
-
require_once
|
2577 |
-
delete_transient( pb_backupbuddy_destination_live::LIVE_ACTION_TRANSIENT_NAME );
|
2578 |
} else {
|
2579 |
$error = 'Error: destination not found.';
|
2580 |
}
|
@@ -2583,150 +3244,200 @@ class MainWP_Child_Back_Up_Buddy {
|
|
2583 |
$error = 'Error: Empty destination id.';
|
2584 |
}
|
2585 |
|
2586 |
-
if (!empty($error))
|
2587 |
$return['error'] = $error;
|
|
|
2588 |
|
2589 |
return $return;
|
2590 |
}
|
2591 |
|
2592 |
-
|
2593 |
-
|
2594 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2595 |
|
2596 |
-
require_once
|
2597 |
-
$state = backupbuddy_live_periodic::get_stats();
|
2598 |
|
2599 |
-
$destination_id = backupbuddy_live::getLiveID();
|
2600 |
-
$destination
|
2601 |
|
2602 |
if ( 'clear_log' == $action ) {
|
2603 |
-
$sumLogFile = backupbuddy_core::getLogDirectory() . 'status-live_periodic_' . pb_backupbuddy::$options['log_serial'] . '.txt';
|
2604 |
-
|
2605 |
if ( file_exists( $sumLogFile ) ) {
|
2606 |
-
$error = 'Error #893489322: Unable to clear log file `' . $sumLogFile . '`. Check permissions or manually delete.'
|
2607 |
} else {
|
2608 |
$message = 'Log file cleared.';
|
2609 |
}
|
2610 |
-
|
2611 |
-
|
2612 |
-
|
2613 |
-
|
2614 |
-
|
2615 |
-
|
2616 |
-
|
2617 |
-
|
2618 |
-
|
2619 |
-
|
2620 |
-
$
|
2621 |
-
|
2622 |
-
|
2623 |
-
|
2624 |
-
|
2625 |
-
|
2626 |
-
$start_run = false;
|
2627 |
-
if ( '1' != pb_backupbuddy::_GET( 'skip_run_live_now' ) ) {
|
2628 |
$launchNowText = '';
|
2629 |
-
$start_run
|
2630 |
-
}
|
2631 |
-
|
2632 |
-
|
2633 |
-
|
2634 |
-
$message = __( 'Live File Backup has resumed.', '
|
2635 |
-
include
|
2636 |
-
}
|
2637 |
-
|
2638 |
-
$
|
2639 |
-
|
2640 |
-
|
2641 |
-
|
2642 |
-
|
2643 |
-
|
2644 |
-
$
|
2645 |
-
|
2646 |
-
|
2647 |
-
$
|
|
|
|
|
2648 |
} else {
|
2649 |
$error = 'Error #1000. Invalid request.';
|
2650 |
}
|
2651 |
|
2652 |
-
return array(
|
|
|
|
|
|
|
|
|
2653 |
}
|
2654 |
|
2655 |
|
2656 |
-
|
2657 |
-
|
2658 |
-
|
2659 |
-
|
2660 |
-
|
2661 |
-
|
2662 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2663 |
}
|
2664 |
|
2665 |
-
|
2666 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2667 |
// Load required files.
|
2668 |
-
require_once
|
2669 |
|
2670 |
-
if ( ! isset( pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) {
|
2671 |
return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' );
|
2672 |
}
|
2673 |
-
require_once
|
2674 |
-
$settings =
|
2675 |
-
$settings = pb_backupbuddy_destination_stash2::_formatSettings( $settings );
|
2676 |
|
2677 |
-
$destination = pb_backupbuddy::$options['remote_destinations'][ $destination_id ];
|
2678 |
|
2679 |
if ( 'live' == $destination['type'] ) {
|
2680 |
-
$remotePath = 'snapshot-'
|
2681 |
-
$site_only
|
2682 |
} else {
|
2683 |
// Get list of files for this site.
|
2684 |
-
$remotePath = 'backup-'
|
2685 |
-
$site_only
|
2686 |
}
|
2687 |
|
2688 |
-
$files = pb_backupbuddy_destination_stash2::listFiles( $settings, '', $site_only ); //2nd param was $remotePath.
|
2689 |
if ( ! is_array( $files ) ) {
|
2690 |
return array( 'error' => 'Error #892329c: ' . $files );
|
2691 |
}
|
2692 |
|
2693 |
$backup_list_temp = array();
|
2694 |
-
foreach( (array)$files as $file ) {
|
2695 |
|
2696 |
-
if ( ( '' != $remotePath ) && ( ! backupbuddy_core::startsWith( basename( $file['filename'] ), $remotePath ) ) ) { // Only show backups for this site unless set to show all.
|
2697 |
continue;
|
2698 |
}
|
2699 |
|
2700 |
$last_modified = $file['uploaded_timestamp'];
|
2701 |
-
$size
|
2702 |
-
$backup_type
|
2703 |
|
2704 |
// Generate array of table rows.
|
2705 |
-
while( isset( $backup_list_temp[$last_modified] ) ) { // Avoid collisions.
|
2706 |
$last_modified += 0.1;
|
2707 |
}
|
2708 |
|
2709 |
if ( 'live' == $destination['type'] ) {
|
2710 |
-
$backup_list_temp[$last_modified] = array(
|
2711 |
-
array( base64_encode( $file['url'] ), '<span class="backupbuddy-stash-file-list-title">' . pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $last_modified ) ) . ' <span class="description">(' . pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)</span></span><br><span title="' . $file['filename'] . '">' . basename( $file['filename'] ) . '</span>' ),
|
2712 |
-
pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $last_modified ) ) . '<br /><span class="description">(' . pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)</span>',
|
2713 |
-
pb_backupbuddy::$format->file_size( $size ),
|
2714 |
-
backupbuddy_core::pretty_backup_type( $backup_type ),
|
2715 |
);
|
2716 |
} else {
|
2717 |
-
$backup_list_temp[$last_modified] = array(
|
2718 |
-
array( base64_encode( $file['url'] ), '<span title="' . $file['filename'] . '">' . basename( $file['filename'] ) . '</span>' ),
|
2719 |
-
pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $last_modified ) ) . '<br /><span class="description">(' . pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)</span>',
|
2720 |
-
pb_backupbuddy::$format->file_size( $size ),
|
2721 |
-
backupbuddy_core::pretty_backup_type( $backup_type ),
|
2722 |
);
|
2723 |
}
|
2724 |
-
|
2725 |
}
|
2726 |
|
2727 |
krsort( $backup_list_temp );
|
2728 |
$backup_list = array();
|
2729 |
-
foreach( $backup_list_temp as $backup_item ) {
|
2730 |
$backup_list[ $backup_item[0][0] ] = $backup_item;
|
2731 |
}
|
2732 |
unset( $backup_list_temp );
|
@@ -2734,56 +3445,78 @@ class MainWP_Child_Back_Up_Buddy {
|
|
2734 |
return array( 'backup_list' => $backup_list );
|
2735 |
}
|
2736 |
|
2737 |
-
|
2738 |
-
|
2739 |
-
|
2740 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2741 |
|
2742 |
// Load required files.
|
2743 |
-
require_once
|
2744 |
-
if ( ! isset( pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) {
|
2745 |
return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' );
|
2746 |
}
|
2747 |
|
2748 |
-
$settings =
|
2749 |
-
$settings = pb_backupbuddy_destination_stash2::_formatSettings( $settings );
|
2750 |
|
2751 |
-
pb_backupbuddy::status( 'details',
|
2752 |
-
backupbuddy_core::schedule_single_event( time(), 'process_remote_copy', array( 'stash2', $file, $settings ) );
|
2753 |
-
if ( '1' != pb_backupbuddy::$options['skip_spawn_cron_call'] ) {
|
2754 |
update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item.
|
2755 |
spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit.
|
2756 |
}
|
2757 |
return array( 'ok' => 1 );
|
2758 |
-
|
2759 |
}
|
2760 |
|
2761 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2762 |
// Handle deletion.
|
2763 |
-
$files
|
2764 |
-
$destination_id = $_POST['destination_id'];
|
2765 |
|
2766 |
// Load required files.
|
2767 |
-
require_once
|
2768 |
-
if ( ! isset( pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) {
|
2769 |
return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' );
|
2770 |
}
|
2771 |
|
2772 |
-
$settings =
|
2773 |
-
$settings = pb_backupbuddy_destination_stash2::_formatSettings( $settings );
|
2774 |
|
2775 |
$deleteFiles = array();
|
2776 |
-
foreach( (array)$files as $file ) {
|
2777 |
-
$file = base64_decode( $file );
|
2778 |
|
2779 |
-
$startPos = pb_backupbuddy_destination_stash2::strrpos_count( $file, '/', 2 ) + 1; // next to last slash.
|
2780 |
-
$file
|
2781 |
-
if (
|
2782 |
$file = substr( $file, 0, strpos( $file, '?' ) );
|
2783 |
}
|
2784 |
$deleteFiles[] = $file;
|
2785 |
}
|
2786 |
-
$response = pb_backupbuddy_destination_stash2::deleteFiles( $settings, $deleteFiles );
|
2787 |
|
2788 |
if ( true === $response ) {
|
2789 |
$msg = 'Deleted ' . implode( ', ', $deleteFiles ) . '.';
|
@@ -2791,122 +3524,161 @@ class MainWP_Child_Back_Up_Buddy {
|
|
2791 |
$msg = 'Failed to delete one or more files. Details: `' . $response . '`.';
|
2792 |
}
|
2793 |
|
2794 |
-
return array(
|
|
|
|
|
|
|
2795 |
}
|
2796 |
|
2797 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2798 |
|
2799 |
// Check if running PHP 5.3+.
|
2800 |
$php_minimum = 5.3;
|
2801 |
if ( version_compare( PHP_VERSION, $php_minimum, '<' ) ) { // Server's PHP is insufficient.
|
2802 |
-
return array('error' => '-1');
|
2803 |
}
|
2804 |
|
2805 |
-
|
2806 |
-
|
|
|
|
|
2807 |
}
|
2808 |
|
2809 |
// If there is more to do and too long of time has passed since activity then try to jumpstart the process at the beginning.
|
2810 |
if ( ( ( 0 == $stats['files_total'] ) || ( $stats['files_sent'] < $stats['files_total'] ) ) && ( 'wait_on_transfers' != $stats['current_function'] ) ) { // ( Files to send not yet calculated OR more remain to send ) AND not on the wait_on_transfers step.
|
2811 |
$time_since_last_activity = microtime( true ) - $stats['last_periodic_activity'];
|
2812 |
|
2813 |
-
if ( $time_since_last_activity
|
2814 |
-
// do nothing
|
2815 |
-
} else { // More than 30 seconds since last activity.
|
2816 |
|
2817 |
// Detect max PHP execution time. If TESTED value is higher than PHP value then go with that since we want to err on not overlapping processes here.
|
2818 |
-
$detected_execution = backupbuddy_core::detectLikelyHighestExecutionTime();
|
2819 |
|
2820 |
-
if ( $time_since_last_activity > ( $detected_execution + backupbuddy_constants::TIMED_OUT_PROCESS_RESUME_WIGGLE_ROOM ) ) { // Enough time has passed to assume timed out.
|
2821 |
|
2822 |
-
require_once
|
2823 |
-
|
|
|
2824 |
die( '-1' );
|
2825 |
}
|
2826 |
-
if ( '1' != pb_backupbuddy::$options['remote_destinations'][ $liveID ]['pause_periodic'] ) { // Only proceed if NOT paused.
|
2827 |
|
2828 |
-
pb_backupbuddy::status( 'warning', 'BackupBuddy Stash Live process appears timed out while user it viewing Live page. Forcing run now.' );
|
2829 |
|
2830 |
-
$cronArgs
|
2831 |
-
$schedule_result = backupbuddy_core::schedule_single_event( time(), 'live_periodic', $cronArgs );
|
2832 |
if ( true === $schedule_result ) {
|
2833 |
-
pb_backupbuddy::status( 'details', 'Next Live Periodic chunk step cron event scheduled.' );
|
2834 |
} else {
|
2835 |
-
pb_backupbuddy::status( 'error', 'Next Live Periodic chunk step cron event FAILED to be scheduled.' );
|
2836 |
}
|
2837 |
-
if ( '1' != pb_backupbuddy::$options['skip_spawn_cron_call'] ) {
|
2838 |
-
pb_backupbuddy::status( 'details', 'Spawning cron now.' );
|
2839 |
update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item.
|
2840 |
spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit.
|
2841 |
}
|
2842 |
}
|
2843 |
-
|
2844 |
}
|
2845 |
}
|
2846 |
-
|
2847 |
}
|
2848 |
|
2849 |
-
return
|
2850 |
}
|
2851 |
|
2852 |
-
|
2853 |
-
|
2854 |
-
|
|
|
|
|
|
|
|
|
|
|
2855 |
$GLOBALS['ithemes-updater-settings']->update_options( $settings );
|
2856 |
-
return array('ok' => 1);
|
2857 |
}
|
2858 |
return false;
|
2859 |
}
|
2860 |
|
2861 |
-
|
2862 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2863 |
$packages_name = array();
|
2864 |
-
if (isset($GLOBALS['ithemes_updater_path'])) {
|
2865 |
|
2866 |
-
require_once
|
2867 |
-
require_once
|
2868 |
-
require_once
|
2869 |
|
2870 |
-
require_once
|
2871 |
|
2872 |
-
$details
|
2873 |
-
$packages = isset($details['packages']) ? $details['packages'] : array();
|
2874 |
-
if (is_array($packages)) {
|
2875 |
foreach ( $packages as $path => $data ) {
|
2876 |
-
$packages_name[$path] = Ithemes_Updater_Functions::get_package_name( $data['package'] );
|
2877 |
}
|
2878 |
}
|
2879 |
-
|
2880 |
}
|
2881 |
-
return array(
|
|
|
|
|
|
|
|
|
2882 |
}
|
2883 |
|
2884 |
-
|
2885 |
-
|
2886 |
-
|
2887 |
-
|
2888 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2889 |
|
2890 |
$return = array( 'ok' => 1 );
|
2891 |
-
if (isset($GLOBALS['ithemes_updater_path'])) {
|
2892 |
|
2893 |
-
require_once
|
2894 |
-
require_once
|
2895 |
-
require_once
|
2896 |
|
2897 |
-
require_once
|
2898 |
|
2899 |
-
|
2900 |
-
$response = Ithemes_Updater_API::activate_package( $username, $password, $packages );
|
2901 |
|
2902 |
if ( is_wp_error( $response ) ) {
|
2903 |
-
$errors[]
|
2904 |
$return['errors'] = $errors;
|
2905 |
return $return;
|
2906 |
}
|
2907 |
|
2908 |
if ( empty( $response['packages'] ) ) {
|
2909 |
-
$errors[]
|
2910 |
$return['errors'] = $errors;
|
2911 |
return $return;
|
2912 |
}
|
@@ -2914,118 +3686,142 @@ class MainWP_Child_Back_Up_Buddy {
|
|
2914 |
uksort( $response['packages'], 'strnatcasecmp' );
|
2915 |
|
2916 |
$success = array();
|
2917 |
-
$warn
|
2918 |
-
$fail
|
2919 |
|
2920 |
foreach ( $response['packages'] as $package => $data ) {
|
2921 |
-
if ( preg_match( '/ \|\|\| \d+$/', $package ) )
|
2922 |
continue;
|
|
|
2923 |
|
2924 |
-
$name = Ithemes_Updater_Functions::get_package_name( $package );
|
2925 |
|
2926 |
-
if ( ! empty( $data['key'] ) )
|
2927 |
$success[] = $name;
|
2928 |
-
|
2929 |
-
$warn[$name] = __( 'Your product subscription has expired', '
|
2930 |
-
else
|
2931 |
-
$fail[$name] = $data['error']['message'];
|
|
|
2932 |
}
|
2933 |
|
2934 |
-
|
2935 |
if ( ! empty( $success ) ) {
|
2936 |
-
$messages[]
|
2937 |
$return['messages'] = $messages;
|
2938 |
}
|
2939 |
|
2940 |
if ( ! empty( $fail ) ) {
|
2941 |
-
foreach ( $fail as $name => $reason )
|
2942 |
-
$errors[] = sprintf( __( 'Unable to license %1$s. Reason: %2$s', '
|
|
|
2943 |
$return['errors'] = $errors;
|
2944 |
}
|
2945 |
|
2946 |
if ( ! empty( $warn ) ) {
|
2947 |
-
foreach ( $warn as $name => $reason )
|
2948 |
-
$soft_errors[] = sprintf( __( 'Unable to license %1$s. Reason: %2$s', '
|
|
|
2949 |
$return['soft_errors'] = $soft_errors;
|
2950 |
}
|
2951 |
-
|
2952 |
}
|
2953 |
return $return;
|
2954 |
}
|
2955 |
|
2956 |
-
|
2957 |
-
|
2958 |
-
|
2959 |
-
|
2960 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2961 |
|
2962 |
$return = array( 'ok' => 1 );
|
2963 |
|
2964 |
-
if (isset($GLOBALS['ithemes_updater_path'])) {
|
2965 |
|
2966 |
-
require_once
|
2967 |
-
require_once
|
2968 |
-
require_once
|
2969 |
|
2970 |
-
require_once
|
2971 |
|
2972 |
-
$response = Ithemes_Updater_API::deactivate_package($username, $password, $packages );
|
2973 |
|
2974 |
if ( is_wp_error( $response ) ) {
|
2975 |
-
$errors[]
|
2976 |
$return['errors'] = $errors;
|
2977 |
return $return;
|
2978 |
}
|
2979 |
|
2980 |
if ( empty( $response['packages'] ) ) {
|
2981 |
-
$errors[]
|
2982 |
$return['errors'] = $errors;
|
2983 |
return $return;
|
2984 |
}
|
2985 |
|
2986 |
-
|
2987 |
uksort( $response['packages'], 'strnatcasecmp' );
|
2988 |
|
2989 |
$success = array();
|
2990 |
-
$fail
|
2991 |
|
2992 |
foreach ( $response['packages'] as $package => $data ) {
|
2993 |
-
if ( preg_match( '/ \|\|\| \d+$/', $package ) )
|
2994 |
continue;
|
|
|
2995 |
|
2996 |
-
$name = Ithemes_Updater_Functions::get_package_name( $package );
|
2997 |
|
2998 |
-
if ( isset( $data['status'] ) && ( 'inactive' == $data['status'] ) )
|
2999 |
$success[] = $name;
|
3000 |
-
|
3001 |
-
$fail[$name] = $data['error']['message'];
|
3002 |
-
else
|
3003 |
-
$fail[$name] = __( 'Unknown server error.', 'it-l10n-mainwp-backupbuddy' );
|
|
|
3004 |
}
|
3005 |
|
3006 |
-
|
3007 |
if ( ! empty( $success ) ) {
|
3008 |
-
$messages[]
|
3009 |
$return['messages'] = $messages;
|
3010 |
}
|
3011 |
|
3012 |
if ( ! empty( $fail ) ) {
|
3013 |
-
foreach ( $fail as $name => $reason )
|
3014 |
$errors[] = sprintf( __( 'Unable to remove license from %1$s. Reason: %2$s', 'it-l10n-mainwp-backupbuddy' ), $name, $reason );
|
|
|
3015 |
$return['errors'] = $errors;
|
3016 |
|
3017 |
}
|
3018 |
-
|
3019 |
}
|
3020 |
return $return;
|
3021 |
}
|
3022 |
|
3023 |
-
|
3024 |
-
|
3025 |
-
|
3026 |
-
|
3027 |
-
|
3028 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3029 |
case 'ITXAPI_Updater_Bad_Login':
|
3030 |
$message = __( 'Incorrect password. Please make sure that you are supplying your iThemes membership username and password details.', 'it-l10n-mainwp-backupbuddy' );
|
3031 |
break;
|
@@ -3040,15 +3836,16 @@ class MainWP_Child_Back_Up_Buddy {
|
|
3040 |
$message = sprintf( __( '%1$s could not be licensed since the membership account is out of available licenses for this product. You can unlicense the product on other sites or upgrade your membership to one with a higher number of licenses in order to increase the amount of available licenses.', 'it-l10n-mainwp-backupbuddy' ), $package_name );
|
3041 |
break;
|
3042 |
case 'ITXAPI_License_Key_Generate_Failed':
|
3043 |
-
$message = sprintf( __( '%s could not be licensed due to an internal error. Please try to license %s again at a later time. If this problem continues, please contact iThemes support.', 'it-l10n-mainwp-backupbuddy' ), $package_name );
|
3044 |
break;
|
3045 |
}
|
3046 |
|
3047 |
if ( empty( $message ) ) {
|
3048 |
-
if ( ! empty( $package ) )
|
3049 |
$message = sprintf( __( 'An unknown error relating to the %1$s product occurred. Please contact iThemes support. Error details: %2$s', 'it-l10n-mainwp-backupbuddy' ), $package_name, $error->get_error_message() . " ($code)" );
|
3050 |
-
else
|
3051 |
$message = sprintf( __( 'An unknown error occurred. Please contact iThemes support. Error details: %s', 'it-l10n-mainwp-backupbuddy' ), $error->get_error_message() . " ($code)" );
|
|
|
3052 |
}
|
3053 |
|
3054 |
return $message;
|
@@ -3057,4 +3854,3 @@ class MainWP_Child_Back_Up_Buddy {
|
|
3057 |
|
3058 |
|
3059 |
}
|
3060 |
-
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Backup Buddy
|
4 |
+
*
|
5 |
+
* The code is used for the MainWP Buddy Extension.
|
6 |
*
|
7 |
* Credits
|
8 |
*
|
15 |
* The code is used for the MainWP Buddy Extension
|
16 |
* Extension URL: https://mainwp.com/extension/mainwpbuddy/
|
17 |
*
|
18 |
+
* @package MainWP\Child
|
19 |
+
*/
|
20 |
+
|
21 |
+
namespace MainWP\Child;
|
22 |
+
|
23 |
+
// phpcs:disable -- third party credit.
|
24 |
+
|
25 |
|
26 |
+
/**
|
27 |
+
* Class MainWP_Child_Back_Up_Buddy
|
28 |
+
*/
|
29 |
class MainWP_Child_Back_Up_Buddy {
|
|
|
|
|
|
|
30 |
|
31 |
+
/**
|
32 |
+
* Public static variable to hold the single instance of MainWP_Child_Back_Up_Buddy.
|
33 |
+
* @var null
|
34 |
+
*/
|
35 |
+
public static $instance = null;
|
36 |
+
|
37 |
+
/** @var string $plugin_translate Plugin translation string. */
|
38 |
+
public $plugin_translate = 'mainwp-child';
|
39 |
+
|
40 |
+
/** @var bool $is_backupbuddy_installed Whether or not BackupBuddy is installed. Default: False. */
|
41 |
+
public $is_backupbuddy_installed = false;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Create a public static instance of MainWP_Child_Back_Up_Buddy.
|
45 |
+
*
|
46 |
+
* @return MainWP_Child_Back_Up_Buddy|null
|
47 |
+
*/
|
48 |
+
public static function instance() {
|
49 |
+
if ( null === self::$instance ) {
|
50 |
+
self::$instance = new self();
|
51 |
}
|
52 |
+
return self::$instance;
|
53 |
}
|
54 |
|
55 |
+
/**
|
56 |
+
* MainWP_Child_Back_Up_Buddy constructor.
|
57 |
+
*
|
58 |
+
* Run any time class is called.
|
59 |
+
*/
|
60 |
+
public function __construct() {
|
61 |
+
// To fix bug run dashboard on local machine.
|
62 |
+
if ( class_exists( '\pb_backupbuddy' ) ) {
|
63 |
$this->is_backupbuddy_installed = true;
|
64 |
}
|
65 |
|
66 |
+
if ( ! $this->is_backupbuddy_installed ) {
|
67 |
return;
|
68 |
}
|
69 |
|
70 |
+
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
71 |
|
72 |
add_action( 'wp_ajax_mainwp_backupbuddy_download_archive', array( $this, 'download_archive' ) );
|
73 |
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
|
76 |
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
77 |
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
78 |
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
79 |
+
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );
|
80 |
}
|
81 |
}
|
82 |
|
83 |
+
/**
|
84 |
+
* Hide Backupbuddy update notice.
|
85 |
+
*
|
86 |
+
* @param string $slugs plugin slug.
|
87 |
+
* @return string $slugs Return slugs array.
|
88 |
+
*/
|
89 |
+
public function hide_update_notice( $slugs ) {
|
90 |
+
$slugs[] = 'backupbuddy/backupbuddy.php';
|
91 |
+
return $slugs;
|
92 |
+
}
|
93 |
|
94 |
+
/**
|
95 |
+
* Remove update nag.
|
96 |
+
*
|
97 |
+
* @param array $value Plugin slug array.
|
98 |
+
* @return array $value Plugin slug array.
|
99 |
+
*
|
100 |
+
* @uses \MainWP\Child\MainWP_Helper::is_updates_screen()
|
101 |
+
*/
|
102 |
+
public function remove_update_nag( $value ) {
|
103 |
if ( isset( $_POST['mainwpsignature'] ) ) {
|
104 |
return $value;
|
105 |
}
|
106 |
|
107 |
+
if ( ! MainWP_Helper::is_updates_screen() ) {
|
108 |
+
return $value;
|
109 |
+
}
|
110 |
|
111 |
if ( isset( $value->response['backupbuddy/backupbuddy.php'] ) ) {
|
112 |
unset( $value->response['backupbuddy/backupbuddy.php'] );
|
116 |
}
|
117 |
|
118 |
|
119 |
+
/**
|
120 |
+
* Remove Backup buddy from plugins list.
|
121 |
+
*
|
122 |
+
* @param array $plugins All plugins array.
|
123 |
+
* @return array $plugins All plugins array with backupbuddy removed.
|
124 |
+
*/
|
125 |
+
public function all_plugins( $plugins ) {
|
126 |
foreach ( $plugins as $key => $value ) {
|
127 |
$plugin_slug = basename( $key, '.php' );
|
128 |
if ( 'backupbuddy' === $plugin_slug ) {
|
133 |
return $plugins;
|
134 |
}
|
135 |
|
136 |
+
/**
|
137 |
+
* Remove backupbuddy from admin menu.
|
138 |
+
*/
|
139 |
+
public function admin_menu() {
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Submenu array.
|
143 |
+
*
|
144 |
+
* @global object
|
145 |
+
*/
|
146 |
global $submenu;
|
147 |
+
|
148 |
remove_menu_page( 'pb_backupbuddy_backup' );
|
149 |
|
150 |
+
if ( isset( $_SERVER['REQUEST_URI'] ) && false !== stripos( wp_unslash( $_SERVER['REQUEST_URI'] ), 'admin.php?page=pb_backupbuddy_' ) ) {
|
151 |
+
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
152 |
exit();
|
153 |
}
|
154 |
}
|
155 |
|
156 |
|
157 |
+
/**
|
158 |
+
* Backupbuddy Client Reports log.
|
159 |
+
*
|
160 |
+
* @uses MainWP_Child_Back_Up_Buddy::do_reports_log()
|
161 |
+
*/
|
162 |
+
public function do_site_stats() {
|
163 |
+
if ( has_action( 'mainwp_child_reports_log' ) ) {
|
164 |
+
do_action( 'mainwp_child_reports_log', 'backupbuddy' );
|
165 |
} else {
|
166 |
+
$this->do_reports_log( 'backupbuddy' );
|
167 |
}
|
168 |
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Create BackupBuddy Client Reports log.
|
172 |
+
*
|
173 |
+
* @param string $ext Extension to create log for.
|
174 |
+
*
|
175 |
+
* @uses MainWP_Child_Back_Up_Buddy::is_backupbuddy_installed()
|
176 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
177 |
+
* @uses \MainWP\Child\MainWP_Helper::check_properties()
|
178 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
179 |
+
* @uses \MainWP\Child\MainWP_Helper::check_classes_exists()
|
180 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
181 |
+
* @uses \pb_backupbuddy_fileoptions()
|
182 |
+
* @uses \pb_backupbuddy_fileoptions::is_ok()
|
183 |
+
* @uses \pb_backupbuddy::$format::prettify()
|
184 |
+
* @uses \backupbuddy_live_periodic::get_stats()
|
185 |
+
* @uses \Exception
|
186 |
+
*/
|
187 |
+
public function do_reports_log( $ext = '' ) {
|
188 |
+
if ( 'backupbuddy' !== $ext ) {
|
189 |
return;
|
190 |
+
}
|
191 |
|
192 |
+
if ( ! $this->is_backupbuddy_installed ) {
|
193 |
return;
|
194 |
}
|
195 |
|
196 |
+
try {
|
197 |
|
198 |
+
MainWP_Helper::check_methods( '\pb_backupbuddy', array( 'plugin_path' ) );
|
199 |
|
200 |
+
if ( ! class_exists( '\backupbuddy_core' ) ) {
|
201 |
+
if ( file_exists( \pb_backupbuddy::plugin_path() . '/classes/core.php' ) ) {
|
202 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/core.php';
|
203 |
+
}
|
204 |
+
}
|
205 |
+
|
206 |
+
if ( file_exists( \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ) ) {
|
207 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
208 |
+
}
|
209 |
+
|
210 |
+
MainWP_Helper::check_classes_exists( array( '\backupbuddy_core', '\pb_backupbuddy_fileoptions' ) );
|
211 |
+
MainWP_Helper::check_methods( '\backupbuddy_core', 'getLogDirectory' );
|
212 |
+
|
213 |
+
$pretty_type = array(
|
214 |
+
'full' => 'Full',
|
215 |
+
'db' => 'Database',
|
216 |
+
'files' => 'Files',
|
217 |
+
);
|
218 |
+
|
219 |
+
$recentBackups_list = glob( \backupbuddy_core::getLogDirectory() . 'fileoptions/*.txt' );
|
220 |
|
221 |
+
foreach ( $recentBackups_list as $backup_fileoptions ) {
|
222 |
+
|
223 |
+
$backup = new \pb_backupbuddy_fileoptions( $backup_fileoptions, $read_only = true );
|
224 |
+
$result = $backup->is_ok();
|
225 |
+
if ( method_exists( $backup, 'is_ok' ) && true !== $result ) {
|
226 |
+
continue;
|
227 |
+
}
|
228 |
+
|
229 |
+
$backup = &$backup->options;
|
230 |
+
|
231 |
+
if ( ! isset( $backup['serial'] ) || ( '' == $backup['serial'] ) ) {
|
232 |
+
continue;
|
233 |
+
}
|
234 |
+
|
235 |
+
$check_finished = false;
|
236 |
+
if ( ( $backup['finish_time'] >= $backup['start_time'] ) && ( 0 != $backup['start_time'] ) ) {
|
237 |
+
$check_finished = true;
|
238 |
+
}
|
239 |
+
|
240 |
+
if ( ! $check_finished ) {
|
241 |
+
continue;
|
242 |
+
}
|
243 |
+
|
244 |
+
$backupType = '';
|
245 |
+
if ( isset( $backup['profile'] ) && isset( $backup['profile']['type'] ) ) {
|
246 |
+
if ( true === MainWP_Helper::check_properties( '\pb_backupbuddy', 'format', true ) ) {
|
247 |
+
if ( true === MainWP_Helper::check_methods( \pb_backupbuddy::$format, array( 'prettify' ), true ) ) {
|
248 |
+
$backupType = \pb_backupbuddy::$format->prettify( $backup['profile']['type'], $pretty_type );
|
249 |
+
}
|
250 |
+
}
|
251 |
+
} else {
|
252 |
+
if ( true === MainWP_Helper::check_methods( '\backupbuddy_core', array( 'pretty_backup_type', 'getBackupTypeFromFile' ), true ) ) {
|
253 |
+
$backupType = \backupbuddy_core::pretty_backup_type( \backupbuddy_core::getBackupTypeFromFile( $backup['archive_file'] ) );
|
254 |
+
}
|
255 |
+
}
|
256 |
+
|
257 |
+
if ( '' == $backupType ) {
|
258 |
+
$backupType = 'Unknown';
|
259 |
+
}
|
260 |
+
|
261 |
+
$finish_time = $backup['finish_time'];
|
262 |
+
$message = 'BackupBuddy ' . $backupType . ' finished';
|
263 |
+
if ( ! empty( $finish_time ) ) {
|
264 |
+
do_action( 'mainwp_reports_backupbuddy_backup', $message, $backupType, $finish_time );
|
265 |
+
}
|
266 |
+
}
|
267 |
+
|
268 |
+
if ( file_exists( \pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php' ) ) {
|
269 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php';
|
270 |
+
|
271 |
+
MainWP_Helper::check_classes_exists( array( '\backupbuddy_live_periodic' ) );
|
272 |
+
MainWP_Helper::check_methods( '\backupbuddy_live_periodic', 'get_stats' );
|
273 |
+
|
274 |
+
$state = \backupbuddy_live_periodic::get_stats();
|
275 |
+
if ( is_array( $state ) && isset( $state['stats'] ) ) {
|
276 |
+
|
277 |
+
if ( is_array( $state['stats'] ) && isset( $state['stats']['last_remote_snapshot'] ) ) {
|
278 |
+
if ( isset( $state['stats']['last_remote_snapshot_response'] ) ) {
|
279 |
+
$resp = $state['stats']['last_remote_snapshot_response'];
|
280 |
+
if ( isset( $resp['success'] ) && $resp['success'] ) {
|
281 |
+
$finish_time = $state['stats']['last_remote_snapshot'];
|
282 |
+
$backupType = 'Live Backup to cloud';
|
283 |
+
$message = 'BackupBuddy ' . $backupType . ' finished';
|
284 |
+
if ( ! empty( $finish_time ) ) {
|
285 |
+
do_action( 'mainwp_reports_backupbuddy_backup', $message, $backupType, $finish_time );
|
286 |
+
}
|
287 |
+
}
|
288 |
+
}
|
289 |
+
}
|
290 |
+
}
|
291 |
+
}
|
292 |
+
} catch ( \Exception $e ) {
|
293 |
+
// ok!
|
294 |
+
}
|
295 |
+
}
|
296 |
+
|
297 |
+
/**
|
298 |
+
* MainWP Child BackupBuddy actions.
|
299 |
+
*
|
300 |
+
* @uses MainWP_Child_Back_Up_Buddy::is_backupbuddy_installed()
|
301 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
302 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
303 |
+
* @uses MainWP_Child_Back_Up_Buddy::set_showhide()
|
304 |
+
* @uses MainWP_Child_Back_Up_Buddy::save_settings()
|
305 |
+
* @uses MainWP_Child_Back_Up_Buddy::reset_defaults()
|
306 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_notifications()
|
307 |
+
* @uses MainWP_Child_Back_Up_Buddy::schedules_list()
|
308 |
+
* @uses MainWP_Child_Back_Up_Buddy::run_scheduled_backup()
|
309 |
+
* @uses MainWP_Child_Back_Up_Buddy::save_scheduled_backup()
|
310 |
+
* @uses MainWP_Child_Back_Up_Buddy::delete_scheduled_backup()
|
311 |
+
* @uses MainWP_Child_Back_Up_Buddy::save_profile()
|
312 |
+
* @uses MainWP_Child_Back_Up_Buddy::delete_profile()
|
313 |
+
* @uses MainWP_Child_Back_Up_Buddy::delete_backup()
|
314 |
+
* @uses MainWP_Child_Back_Up_Buddy::backup_list()
|
315 |
+
* @uses MainWP_Child_Back_Up_Buddy::save_note()
|
316 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_hash()
|
317 |
+
* @uses MainWP_Child_Back_Up_Buddy::zip_viewer()
|
318 |
+
* @uses MainWP_Child_Back_Up_Buddy::exclude_tree()
|
319 |
+
* @uses MainWP_Child_Back_Up_Buddy::restore_file_view()
|
320 |
+
* @uses MainWP_Child_Back_Up_Buddy::restore_file_restore()
|
321 |
+
* @uses MainWP_Child_Back_Up_Buddy::view_log()
|
322 |
+
* @uses MainWP_Child_Back_Up_Buddy::view_detail()
|
323 |
+
* @uses MainWP_Child_Back_Up_Buddy::reset_integrity()
|
324 |
+
* @uses MainWP_Child_Back_Up_Buddy::download_archive()
|
325 |
+
* @uses MainWP_Child_Back_Up_Buddy::create_backup()
|
326 |
+
* @uses MainWP_Child_Back_Up_Buddy::start_backup()
|
327 |
+
* @uses MainWP_Child_Back_Up_Buddy::backup_status()
|
328 |
+
* @uses MainWP_Child_Back_Up_Buddy::stop_backup()
|
329 |
+
* @uses MainWP_Child_Back_Up_Buddy::remote_save()
|
330 |
+
* @uses MainWP_Child_Back_Up_Buddy::remote_delete()
|
331 |
+
* @uses MainWP_Child_Back_Up_Buddy::remote_send()
|
332 |
+
* @uses MainWP_Child_Back_Up_Buddy::remote_list()
|
333 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_main_log()
|
334 |
+
* @uses MainWP_Child_Back_Up_Buddy::settings_other()
|
335 |
+
* @uses MainWP_Child_Back_Up_Buddy::malware_scan()
|
336 |
+
* @uses MainWP_Child_Back_Up_Buddy::live_setup()
|
337 |
+
* @uses MainWP_Child_Back_Up_Buddy::live_save_settings()
|
338 |
+
* @uses MainWP_Child_Back_Up_Buddy::live_action_disconnect()
|
339 |
+
* @uses MainWP_Child_Back_Up_Buddy::live_action()
|
340 |
+
* @uses MainWP_Child_Back_Up_Buddy::download_troubleshooting()
|
341 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_live_backups()
|
342 |
+
* @uses MainWP_Child_Back_Up_Buddy::copy_file_to_local()
|
343 |
+
* @uses MainWP_Child_Back_Up_Buddy::delete_file_backup()
|
344 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_live_stats()
|
345 |
+
* @uses MainWP_Child_Back_Up_Buddy::load_products_license()
|
346 |
+
* @uses MainWP_Child_Back_Up_Buddy::save_license_settings()
|
347 |
+
* @uses MainWP_Child_Back_Up_Buddy::activate_package()
|
348 |
+
* @uses MainWP_Child_Back_Up_Buddy::deactivate_package()
|
349 |
+
*/
|
350 |
+
public function action() {
|
351 |
$information = array();
|
352 |
if ( ! $this->is_backupbuddy_installed ) {
|
353 |
MainWP_Helper::write( array( 'error' => __( 'Please install the BackupBuddy plugin on the child site.', $this->plugin_translate ) ) );
|
354 |
}
|
355 |
|
356 |
+
if ( ! class_exists( '\backupbuddy_core' ) ) {
|
357 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/core.php';
|
358 |
}
|
359 |
|
360 |
+
if ( ! isset( \pb_backupbuddy::$options ) ) {
|
361 |
+
\pb_backupbuddy::load();
|
362 |
}
|
363 |
+
|
364 |
+
$mwp_action = isset( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
365 |
if ( isset( $_POST['mwp_action'] ) ) {
|
366 |
+
switch ( $mwp_action ) {
|
367 |
case 'set_showhide':
|
368 |
$information = $this->set_showhide();
|
369 |
break;
|
507 |
MainWP_Helper::write( $information );
|
508 |
}
|
509 |
|
510 |
+
/**
|
511 |
+
* Set show or hide BackupBuddy Plugin from Admin & plugins list.
|
512 |
+
*
|
513 |
+
* @return array $information Return results.
|
514 |
+
*/
|
515 |
+
public function set_showhide() {
|
516 |
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
517 |
MainWP_Helper::update_option( 'mainwp_backupbuddy_hide_plugin', $hide );
|
518 |
$information['result'] = 'SUCCESS';
|
519 |
return $information;
|
520 |
}
|
521 |
|
522 |
+
/**
|
523 |
+
* Save BackupBuddy settings.
|
524 |
+
*
|
525 |
+
* @return array $out Return response array.
|
526 |
+
*
|
527 |
+
* @uses \pb_backupbuddy::$options()
|
528 |
+
* @uses \backupbuddy_core::_getBackupDirectoryDefault()
|
529 |
+
*/
|
530 |
+
public function save_settings() {
|
531 |
|
532 |
+
$type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
|
533 |
|
534 |
+
if ( 'general_settings' !== $type && 'advanced_settings' !== $type && 'all' !== $type ) {
|
535 |
+
return array( 'error' => __( 'Invalid data. Please check and try again.' ) );
|
536 |
}
|
537 |
|
538 |
$filter_advanced_settings = array(
|
563 |
'disable_https_local_ssl_verify',
|
564 |
'prevent_flush',
|
565 |
'save_comment_meta',
|
566 |
+
'integrity_check',
|
567 |
'backup_cron_rescheduling',
|
568 |
'skip_spawn_cron_call',
|
569 |
'backup_cron_passed_force_time',
|
570 |
'php_runtime_test_minimum_interval',
|
571 |
'php_memory_test_minimum_interval',
|
572 |
'database_method_strategy',
|
573 |
+
'skip_database_dump',
|
574 |
'breakout_tables',
|
575 |
'force_single_db_file',
|
576 |
'phpmysqldump_maxrows',
|
588 |
'ignore_zip_symlinks',
|
589 |
);
|
590 |
|
|
|
591 |
$filter_general_settings = array(
|
592 |
'importbuddy_pass_hash',
|
593 |
'importbuddy_pass_length',
|
601 |
'archive_limit_files',
|
602 |
'title_multisite',
|
603 |
'multisite_export',
|
604 |
+
'backup_nonwp_tables',
|
605 |
+
'mysqldump_additional_includes',
|
606 |
+
'mysqldump_additional_excludes',
|
607 |
+
'excludes',
|
608 |
'email_notify_scheduled_start',
|
609 |
'email_notify_scheduled_start_subject',
|
610 |
'email_notify_scheduled_start_body',
|
618 |
'email_notify_error',
|
619 |
'email_notify_error_subject',
|
620 |
'email_notify_error_body',
|
621 |
+
'email_return',
|
622 |
);
|
623 |
|
624 |
$filter_profile0_values = array(
|
627 |
'excludes',
|
628 |
'integrity_check',
|
629 |
'skip_database_dump',
|
630 |
+
'backup_nonwp_tables',
|
631 |
);
|
632 |
|
633 |
+
$settings = unserialize( base64_decode( wp_unslash( $_POST['options'] ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
634 |
|
635 |
$save_settings = array();
|
636 |
|
637 |
+
if ( is_array( $settings ) ) {
|
638 |
+
if ( 'all' === $type || 'general_settings' === $type ) {
|
639 |
+
foreach ( $filter_general_settings as $field ) {
|
640 |
+
if ( isset( $settings[ $field ] ) ) {
|
641 |
+
$save_settings[ $field ] = $settings[ $field ];
|
642 |
}
|
643 |
}
|
644 |
}
|
645 |
|
646 |
+
if ( 'all' === $type || 'advanced_settings' === $type ) {
|
647 |
+
foreach ( $filter_advanced_settings as $field ) {
|
648 |
+
if ( isset( $settings[ $field ] ) ) {
|
649 |
+
$save_settings[ $field ] = $settings[ $field ];
|
650 |
}
|
651 |
}
|
652 |
}
|
653 |
}
|
654 |
|
655 |
+
if ( ! empty( $save_settings ) ) {
|
656 |
+
$newOptions = \pb_backupbuddy::$options;
|
657 |
|
658 |
+
foreach ( $newOptions as $key => $val ) {
|
659 |
+
if ( isset( $save_settings[ $key ] ) ) {
|
660 |
+
$newOptions[ $key ] = $save_settings[ $key ];
|
661 |
}
|
662 |
}
|
663 |
|
664 |
+
if ( isset( $newOptions['profiles'] ) && isset( $newOptions['profiles'][0] ) ) {
|
665 |
+
foreach ( $filter_profile0_values as $field ) {
|
666 |
+
if ( isset( $settings[ $field ] ) ) {
|
667 |
+
$newOptions['profiles'][0][ $field ] = $settings[ $field ];
|
668 |
}
|
669 |
}
|
670 |
}
|
671 |
|
672 |
+
if ( 'general_settings' === $type || 'all' === $type ) {
|
673 |
$newOptions['importbuddy_pass_hash_confirm'] = '';
|
674 |
}
|
675 |
|
676 |
+
/** @global object $wpdb WordPres Database object. */
|
677 |
global $wpdb;
|
678 |
+
|
679 |
+
$option = 'pb_' . \pb_backupbuddy::settings( 'slug' );
|
680 |
$newOptions = sanitize_option( $option, $newOptions );
|
681 |
+
$newOptions = maybe_serialize( $newOptions ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- third party credit.
|
682 |
|
683 |
+
add_site_option( $option, $newOptions, '', 'no' ); // 'No' prevents autoload if we wont always need the data loaded.
|
684 |
$wpdb->update( $wpdb->options, array( 'option_value' => $newOptions ), array( 'option_name' => $option ) );
|
685 |
|
686 |
+
$information['backupDirectoryDefault'] = \backupbuddy_core::_getBackupDirectoryDefault();
|
687 |
+
$information['result'] = 'SUCCESS';
|
688 |
}
|
689 |
|
690 |
return $information;
|
691 |
}
|
692 |
|
693 |
+
/**
|
694 |
+
* Reset BackupBuddy defaults.
|
695 |
+
*
|
696 |
+
* @return array $information Return success message & result.
|
697 |
+
*
|
698 |
+
* @uses \pb_backupbuddy::$options
|
699 |
+
* @uses \pb_backupbuddy::settings()
|
700 |
+
* @uses \pb_backupbuddy::save()
|
701 |
+
* @uses \backupbuddy_core::verify_directories()
|
702 |
+
* @uses \backupbuddy_core::addNotification()
|
703 |
+
*/
|
704 |
+
public function reset_defaults() {
|
705 |
+
|
706 |
// Keep log serial.
|
707 |
+
$old_log_serial = \pb_backupbuddy::$options['log_serial'];
|
708 |
|
709 |
+
$keepDestNote = '';
|
710 |
+
$remote_destinations = \pb_backupbuddy::$options['remote_destinations'];
|
711 |
+
\pb_backupbuddy::$options = \pb_backupbuddy::settings( 'default_options' );
|
712 |
if ( '1' == $_POST['keep_destinations'] ) {
|
713 |
+
\pb_backupbuddy::$options['remote_destinations'] = $remote_destinations;
|
714 |
+
$keepDestNote = ' ' . __( 'Remote destination settings were not reset.', 'mainwp-child' );
|
715 |
}
|
716 |
|
717 |
// Replace log serial.
|
718 |
+
\pb_backupbuddy::$options['log_serial'] = $old_log_serial;
|
719 |
|
720 |
+
\pb_backupbuddy::save();
|
721 |
+
$skipTempGeneration = true;
|
722 |
+
\backupbuddy_core::verify_directories( $skipTempGeneration ); // Re-verify directories such as backup dir, temp, etc.
|
723 |
$resetNote = __( 'Plugin settings have been reset to defaults.', 'mainwp-child' );
|
724 |
+
\backupbuddy_core::addNotification( 'settings_reset', 'Plugin settings reset', $resetNote . $keepDestNote );
|
725 |
|
726 |
$information['message'] = $resetNote . $keepDestNote;
|
727 |
+
$information['result'] = 'SUCCESS';
|
728 |
return $information;
|
729 |
}
|
730 |
|
731 |
+
/**
|
732 |
+
* Get BackupBuddy core success notifications.
|
733 |
+
*
|
734 |
+
* @return array Return BackupBuddy SUCCESS notifications.
|
735 |
+
*
|
736 |
+
* @uses \backupbuddy_core::getNotifications()
|
737 |
+
*/
|
738 |
+
public function get_notifications() {
|
739 |
+
return array(
|
740 |
+
'result' => 'SUCCESS',
|
741 |
+
'notifications' => \backupbuddy_core::getNotifications(),
|
742 |
+
);
|
743 |
}
|
744 |
|
745 |
+
/**
|
746 |
+
* Get schedules run time.
|
747 |
+
*
|
748 |
+
* @return array Return $schedules_run_time.
|
749 |
+
*
|
750 |
+
* @uses \pb_backupbuddy::$options
|
751 |
+
* @uses \pb_backupbuddy::$format::date()
|
752 |
+
* @uses \pb_backupbuddy::$format::localize_time()
|
753 |
+
*/
|
754 |
+
public function get_schedules_run_time() {
|
755 |
$schedules_run_time = array();
|
756 |
+
foreach ( \pb_backupbuddy::$options['schedules'] as $schedule_id => $schedule ) {
|
757 |
// Determine first run.
|
758 |
+
$first_run = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $schedule['first_run'] ) );
|
759 |
// Determine last run.
|
760 |
if ( isset( $schedule['last_run'] ) ) { // backward compatibility before last run tracking added. Pre v2.2.11. Eventually remove this.
|
761 |
+
if ( 0 == $schedule['last_run'] ) {
|
762 |
+
$last_run = '<i>' . __( 'Never', 'mainwp-child' ) . '</i>';
|
763 |
} else {
|
764 |
+
$last_run = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $schedule['last_run'] ) );
|
765 |
}
|
766 |
} else { // backward compatibility for before last run tracking was added.
|
767 |
+
$last_run = '<i> ' . __( 'Unknown', 'mainwp-child' ) . '</i>';
|
768 |
}
|
769 |
|
770 |
// Determine next run.
|
771 |
+
$next_run = wp_next_scheduled( 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int) $schedule_id ) ) );
|
772 |
if ( false === $next_run ) {
|
773 |
$next_run = '<font color=red>Error: Cron event not found</font>';
|
774 |
} else {
|
775 |
+
$next_run = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $next_run ) );
|
776 |
}
|
777 |
|
778 |
$run_time = 'First run: ' . $first_run . '<br>' .
|
779 |
+
'Last run: ' . $last_run . '<br>' .
|
780 |
+
'Next run: ' . $next_run;
|
781 |
|
782 |
+
$schedules_run_time[ $schedule_id ] = $run_time;
|
783 |
|
784 |
}
|
785 |
|
786 |
return $schedules_run_time;
|
787 |
}
|
788 |
|
789 |
+
/**
|
790 |
+
* List schedules.
|
791 |
+
*
|
792 |
+
* @return array $information Return results array.
|
793 |
+
*
|
794 |
+
* @uses \pb_backupbuddy::$options
|
795 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_schedules_run_time()
|
796 |
+
*/
|
797 |
+
public function schedules_list() {
|
798 |
+
$information = array();
|
799 |
+
$information['schedules'] = \pb_backupbuddy::$options['schedules'];
|
800 |
+
$information['next_schedule_index'] = \pb_backupbuddy::$options['next_schedule_index'];
|
801 |
+
$information['schedules_run_time'] = $this->get_schedules_run_time();
|
802 |
+
|
803 |
+
// to fix missing destination notice.
|
804 |
+
if ( isset( \pb_backupbuddy::$options['remote_destinations'] ) ) {
|
805 |
+
$information['remote_destinations'] = \pb_backupbuddy::$options['remote_destinations'];
|
806 |
}
|
807 |
|
808 |
$information['result'] = 'SUCCESS';
|
810 |
}
|
811 |
|
812 |
|
813 |
+
/**
|
814 |
+
* Run scheduled backup.
|
815 |
+
*
|
816 |
+
* @return array $information Return results array.
|
817 |
+
*
|
818 |
+
* @uses \pb_backupbuddy::$options
|
819 |
+
* @uses \pb_backupbuddy::alert()
|
820 |
+
* @uses \pb_backupbuddy_cron::_run_scheduled_backup()
|
821 |
+
*/
|
822 |
+
public function run_scheduled_backup() {
|
823 |
if ( ! is_main_site() ) { // Only run for main site or standalone. Multisite subsites do not allow schedules.
|
824 |
+
return array( 'error' => __( 'Only run for main site or standalone. Multisite subsites do not allow schedules', 'mainwp-child' ) );
|
825 |
}
|
826 |
|
827 |
$schedule_id = (int) $_POST['schedule_id'];
|
828 |
|
829 |
+
if ( ! isset( \pb_backupbuddy::$options['schedules'][ $schedule_id ] ) || ! is_array( \pb_backupbuddy::$options['schedules'][ $schedule_id ] ) ) {
|
830 |
+
return array( 'error' => __( 'Error: not found the backup schedule or invalid data', 'mainwp-child' ) );
|
831 |
}
|
832 |
|
833 |
+
\pb_backupbuddy::alert( 'Manually running scheduled backup "' . \pb_backupbuddy::$options['schedules'][ $schedule_id ]['title'] . '" in the background.<br>' . __( 'Note: If there is no site activity there may be delays between steps in the backup. Access the site or use a 3rd party service, such as a free pinging service, to generate site activity.', 'mainwp-child' ) );
|
834 |
+
\pb_backupbuddy_cron::_run_scheduled_backup( $schedule_id );
|
|
|
835 |
|
836 |
$information['result'] = 'SUCCESS';
|
837 |
|
839 |
}
|
840 |
|
841 |
|
842 |
+
/**
|
843 |
+
* Save scheduled backup.
|
844 |
+
*
|
845 |
+
* @return array|string[] $information Return results array.
|
846 |
+
*
|
847 |
+
* @uses \pb_backupbuddy::$options
|
848 |
+
* @uses \backupbuddy_core::schedule_event()
|
849 |
+
* @uses \backupbuddy_core::unschedule_event()
|
850 |
+
* @uses \pb_backupbuddy::save()
|
851 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_schedules_run_time()
|
852 |
+
*/
|
853 |
+
public function save_scheduled_backup() {
|
854 |
+
$schedule_id = intval( $_POST['schedule_id'] );
|
855 |
+
$schedule = unserialize( base64_decode( wp_unslash( $_POST['data'] ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
856 |
+
|
857 |
+
if ( ! is_array( $schedule ) ) {
|
858 |
+
return array( 'error' => __( 'Invalid schedule data', 'mainwp-child' ) );
|
859 |
}
|
860 |
$information = array();
|
861 |
+
|
862 |
+
if ( ! isset( \pb_backupbuddy::$options['schedules'][ $schedule_id ] ) ) {
|
863 |
+
$next_index = \pb_backupbuddy::$options['next_schedule_index'];
|
864 |
+
\pb_backupbuddy::$options['next_schedule_index']++; // This change will be saved in savesettings function below.
|
865 |
+
\pb_backupbuddy::$options['schedules'][ $schedule_id ] = $schedule;
|
866 |
+
$result = \backupbuddy_core::schedule_event( $schedule['first_run'], $schedule['interval'], 'run_scheduled_backup', array( $schedule_id ) );
|
867 |
+
if ( false === $result ) {
|
868 |
+
return array( 'error' => 'Error scheduling event with WordPress. Your schedule may not work properly. Please try again. Error #3488439b. Check your BackupBuddy error log for details.' );
|
869 |
}
|
870 |
} else {
|
871 |
+
$first_run = $schedule['first_run'];
|
872 |
+
$next_scheduled_time = wp_next_scheduled( 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int) $schedule_id ) ) );
|
873 |
+
\backupbuddy_core::unschedule_event( $next_scheduled_time, 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int) $schedule_id ) ) );
|
874 |
+
\backupbuddy_core::schedule_event( $first_run, $schedule['interval'], 'run_scheduled_backup', array( (int) $schedule_id ) ); // Add new schedule.
|
875 |
+
\pb_backupbuddy::$options['schedules'][ $schedule_id ] = $schedule;
|
876 |
+
}
|
877 |
+
\pb_backupbuddy::save();
|
878 |
+
$information['result'] = 'SUCCESS';
|
879 |
+
$information['schedules'] = \pb_backupbuddy::$options['schedules'];
|
880 |
+
$information['next_schedule_index'] = \pb_backupbuddy::$options['next_schedule_index'];
|
881 |
+
$information['schedules_run_time'] = $this->get_schedules_run_time();
|
882 |
return $information;
|
883 |
}
|
884 |
|
885 |
|
886 |
+
/**
|
887 |
+
* Save profile.
|
888 |
+
*
|
889 |
+
* @return array $information Return response array.
|
890 |
+
*
|
891 |
+
* @uses \pb_backupbuddy::$options
|
892 |
+
* @uses \pb_backupbuddy::save()
|
893 |
+
*/
|
894 |
+
public function save_profile() {
|
895 |
+
$profile_id = isset( $_POST['profile_id'] ) ? sanitize_text_field( wp_unslash( $_POST['profile_id'] ) ) : 0;
|
896 |
+
$profile = unserialize( base64_decode( wp_unslash( $_POST['data'] ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
897 |
|
898 |
+
if ( ! is_array( $profile ) ) {
|
899 |
+
return array( 'error' => __( 'Invalid profile data', 'mainwp-child' ) );
|
900 |
}
|
901 |
|
902 |
+
\pb_backupbuddy::$options['profiles'][ $profile_id ] = $profile;
|
903 |
+
\pb_backupbuddy::save();
|
904 |
|
905 |
$information['result'] = 'SUCCESS';
|
906 |
return $information;
|
907 |
}
|
908 |
|
909 |
|
910 |
+
/**
|
911 |
+
* Delete profile.
|
912 |
+
*
|
913 |
+
* @return array $information Return results array.
|
914 |
+
*
|
915 |
+
* @uses \pb_backupbuddy::$options
|
916 |
+
* @uses \pb_backupbuddy::save()
|
917 |
+
*/
|
918 |
+
public function delete_profile() {
|
919 |
+
$profile_id = isset( $_POST['profile_id'] ) ? sanitize_text_field( wp_unslash( $_POST['profile_id'] ) ) : 0;
|
920 |
|
921 |
+
if ( isset( \pb_backupbuddy::$options['profiles'][ $profile_id ] ) ) {
|
922 |
+
unset( \pb_backupbuddy::$options['profiles'][ $profile_id ] );
|
923 |
+
}
|
924 |
|
925 |
+
\pb_backupbuddy::save();
|
926 |
$information['result'] = 'SUCCESS';
|
927 |
return $information;
|
928 |
}
|
929 |
|
930 |
+
/**
|
931 |
+
* Delete backup.
|
932 |
+
*
|
933 |
+
* @param string $type Type of backup.
|
934 |
+
* @param bool $subsite_mode Whether or not the backup is for a subsite. Default: false.
|
935 |
+
*
|
936 |
+
* @return array $information Return results array.
|
937 |
+
*
|
938 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
939 |
+
* @uses \backupbuddy_core::get_serial_from_file()
|
940 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
941 |
+
* @uses \backupbuddy_core::getLogDirectory::re::get_serial_from_file()
|
942 |
+
* @uses \pb_backupbuddy::save()
|
943 |
+
*/
|
944 |
+
public function delete_backup( $type = 'default', $subsite_mode = false ) {
|
945 |
+
$item_ids = isset( $_POST['item_ids'] ) ? explode( ',', wp_unslash( $_POST['item_ids'] ) ) : array();
|
946 |
$information = array();
|
947 |
if ( is_array( $item_ids ) && count( $item_ids ) > 0 ) {
|
948 |
+
$needs_save = false;
|
949 |
$deleted_files = array();
|
950 |
+
foreach ( $item_ids as $item ) {
|
951 |
+
if ( file_exists( \backupbuddy_core::getBackupDirectory() . $item ) ) {
|
952 |
+
if ( unlink( \backupbuddy_core::getBackupDirectory() . $item ) === true ) {
|
953 |
$deleted_files[] = $item;
|
954 |
|
955 |
// Cleanup any related fileoptions files.
|
956 |
+
$serial = \backupbuddy_core::get_serial_from_file( $item );
|
957 |
|
958 |
+
$backup_files = glob( \backupbuddy_core::getBackupDirectory() . '*.zip' );
|
959 |
if ( ! is_array( $backup_files ) ) {
|
960 |
$backup_files = array();
|
961 |
}
|
962 |
if ( count( $backup_files ) > 5 ) { // Keep a minimum number of backups in array for stats.
|
963 |
+
$this_serial = \backupbuddy_core::get_serial_from_file( $item );
|
964 |
+
$fileoptions_file = \backupbuddy_core::getLogDirectory() . 'fileoptions/' . $this_serial . '.txt';
|
965 |
if ( file_exists( $fileoptions_file ) ) {
|
966 |
+
unlink( $fileoptions_file );
|
967 |
}
|
968 |
if ( file_exists( $fileoptions_file . '.lock' ) ) {
|
969 |
+
unlink( $fileoptions_file . '.lock' );
|
970 |
}
|
971 |
$needs_save = true;
|
972 |
}
|
973 |
}
|
974 |
+
}
|
975 |
+
}
|
976 |
+
if ( true === $needs_save ) {
|
977 |
+
\pb_backupbuddy::save();
|
978 |
}
|
979 |
|
980 |
$information['result'] = 'SUCCESS';
|
981 |
|
982 |
+
}
|
983 |
return $information;
|
984 |
}
|
985 |
|
986 |
+
/**
|
987 |
+
* Sync other data from $data[] and merge with $information[]
|
988 |
+
*
|
989 |
+
* @param array $information Returned response array for MainWP BackWPup Extension actions.
|
990 |
+
* @param array $data Other data to sync to $information array.
|
991 |
+
*
|
992 |
+
* @return array $information Returned information array with both sets of data.
|
993 |
+
*/
|
994 |
+
public function sync_others_data( $information, $data = array() ) {
|
995 |
+
if ( isset( $data['syncBackupBuddy'] ) && $data['syncBackupBuddy'] ) {
|
996 |
+
try {
|
997 |
+
$information['syncBackupBuddy'] = $this->get_sync_data();
|
998 |
+
} catch ( \Exception $e ) {
|
999 |
+
// ok!
|
1000 |
+
}
|
1001 |
+
}
|
1002 |
return $information;
|
1003 |
}
|
1004 |
|
1005 |
+
/**
|
1006 |
+
* Get sync data.
|
1007 |
+
*
|
1008 |
+
* @return array|bool $out Return Updraft data array or FALSE on failure.
|
1009 |
+
* @throws Exception Error message.
|
1010 |
+
*
|
1011 |
+
* @uses MainWP_Helper::check_classes_exists()
|
1012 |
+
* @uses MainWP_Helper::check_methods()
|
1013 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1014 |
+
* @uses \backupbuddy_core::get_plugins_root()
|
1015 |
+
* @uses \backupbuddy_core::get_themes_root()
|
1016 |
+
* @uses \backupbuddy_core::get_media_root()
|
1017 |
+
* @uses MainWP_Child_Back_Up_Buddy::pb_additional_tables()
|
1018 |
+
*/
|
1019 |
+
public function get_sync_data() {
|
1020 |
+
try {
|
1021 |
+
if ( ! class_exists( '\backupbuddy_core' ) ) {
|
1022 |
+
MainWP_Helper::check_classes_exists( '\pb_backupbuddy' );
|
1023 |
+
MainWP_Helper::check_methods( '\pb_backupbuddy', array( 'plugin_path' ) );
|
1024 |
+
|
1025 |
+
$plugin_path = \pb_backupbuddy::plugin_path();
|
1026 |
+
if ( file_exists( $plugin_path . '/classes/core.php' ) ) {
|
1027 |
+
require_once $plugin_path . '/classes/core.php';
|
1028 |
+
}
|
1029 |
+
}
|
1030 |
|
1031 |
+
MainWP_Helper::check_classes_exists( array( '\backupbuddy_core', '\backupbuddy_api' ) );
|
1032 |
+
MainWP_Helper::check_methods( '\backupbuddy_core', array( 'get_plugins_root', 'get_themes_root', 'get_media_root' ) );
|
1033 |
+
MainWP_Helper::check_methods( '\backupbuddy_api', array( 'getOverview' ) );
|
1034 |
|
1035 |
+
$data = array();
|
1036 |
+
$data['plugins_root'] = \backupbuddy_core::get_plugins_root();
|
1037 |
+
$data['themes_root'] = \backupbuddy_core::get_themes_root();
|
1038 |
+
$data['media_root'] = \backupbuddy_core::get_media_root();
|
1039 |
+
$data['additional_tables'] = $this->pb_additional_tables();
|
1040 |
+
$data['abspath'] = ABSPATH;
|
1041 |
|
1042 |
+
$getOverview = \backupbuddy_api::getOverview();
|
1043 |
+
$data['editsSinceLastBackup'] = $getOverview['editsSinceLastBackup'];
|
1044 |
|
1045 |
+
if ( isset( $getOverview['lastBackupStats']['finish'] ) ) {
|
1046 |
+
$finish_time = $getOverview['lastBackupStats']['finish'];
|
1047 |
+
$time = $this->localize_time( $finish_time );
|
1048 |
+
$data['lastBackupStats'] = date( 'M j - g:i A', $time ); // phpcs:ignore -- local time.
|
1049 |
+
$data['lasttime_backup'] = $finish_time;
|
1050 |
+
MainWP_Utility::update_lasttime_backup( 'backupbuddy', $finish_time ); // support Require Backup Before Update feature.
|
1051 |
+
} else {
|
1052 |
+
$data['lastBackupStats'] = 'Unknown';
|
1053 |
+
}
|
1054 |
|
1055 |
+
return $data;
|
1056 |
+
} catch ( \Exception $e ) {
|
1057 |
+
// not exit here!
|
1058 |
+
}
|
1059 |
|
1060 |
return false;
|
1061 |
}
|
1062 |
|
1063 |
+
/**
|
1064 |
+
* Localize time.
|
1065 |
+
*
|
1066 |
+
* @param float $timestamp Time to localize.
|
1067 |
+
*
|
1068 |
+
* @return float|int Return localized timestamp.
|
1069 |
+
*/
|
1070 |
+
public function localize_time($timestamp ) {
|
1071 |
if ( function_exists( 'get_option' ) ) {
|
1072 |
$gmt_offset = get_option( 'gmt_offset' );
|
1073 |
} else {
|
1076 |
return $timestamp + ( $gmt_offset * 3600 );
|
1077 |
}
|
1078 |
|
1079 |
+
/**
|
1080 |
+
* Backup list.
|
1081 |
+
*
|
1082 |
+
* @return array $information Return results array.
|
1083 |
+
*
|
1084 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1085 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_backup_list()
|
1086 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_recent_backup_list()
|
1087 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
1088 |
+
*/
|
1089 |
+
public function backup_list() {
|
1090 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php';
|
1091 |
+
$information = array();
|
1092 |
+
$information['backup_list'] = $this->get_backup_list();
|
1093 |
+
$information['recent_backup_list'] = $this->get_recent_backup_list();
|
1094 |
+
$backup_directory = \backupbuddy_core::getBackupDirectory();
|
1095 |
+
$backup_directory = str_replace( '\\', '/', $backup_directory );
|
1096 |
+
$backup_directory = rtrim( $backup_directory, '/\\' ) . '/';
|
1097 |
+
$information['backupDirectoryWithinSiteRoot'] = ( false !== stristr( $backup_directory, ABSPATH ) ) ? 'yes' : 'no';
|
1098 |
+
$information['result'] = 'SUCCESS';
|
1099 |
return $information;
|
1100 |
}
|
1101 |
|
1102 |
+
/**
|
1103 |
+
* Save note.
|
1104 |
+
*
|
1105 |
+
* @return array $information Return results array.
|
1106 |
+
*
|
1107 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1108 |
+
* @uses \pb_backupbuddy::$classes
|
1109 |
+
* @uses \pb_backupbuddy::$classes::get_comment()
|
1110 |
+
* @uses \pb_backupbuddy::status()
|
1111 |
+
* @uses \pb_backupbuddy_fileoptions()
|
1112 |
+
* @uses \pb_backupbuddy_fileoptions::is_ok()
|
1113 |
+
* @uses \pb_backupbuddy_fileoptions::save()
|
1114 |
+
* @uses \pb_backupbuddy::$classes::set_comment()
|
1115 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
1116 |
+
* @uses \backupbuddy_core::normalize_comment_data()
|
1117 |
+
* @uses \backupbuddy_core::get_serial_from_file()
|
1118 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
1119 |
+
*/
|
1120 |
+
public function save_note() {
|
1121 |
+
if ( ! isset( \pb_backupbuddy::$classes['zipbuddy'] ) ) {
|
1122 |
+
require_once \pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
|
1123 |
+
\pb_backupbuddy::$classes['zipbuddy'] = new \pluginbuddy_zipbuddy( \backupbuddy_core::getBackupDirectory() );
|
1124 |
+
}
|
1125 |
+
$backup_file = isset( $_POST['backup_file'] ) ? wp_unslash( $_POST['backup_file'] ) : '';
|
1126 |
+
$note = isset( $_POST['backup_file'] ) ? wp_unslash( $_POST['note'] ) : '';
|
1127 |
+
$note = preg_replace( '/[[:space:]]+/', ' ', $note );
|
1128 |
+
$note = preg_replace( '/[^[:print:]]/', '', $note );
|
1129 |
+
$note = substr( $note, 0, 200 );
|
1130 |
|
1131 |
// Returns true on success, else the error message.
|
1132 |
+
$old_comment = \pb_backupbuddy::$classes['zipbuddy']->get_comment( $backup_file );
|
1133 |
+
$comment = \backupbuddy_core::normalize_comment_data( $old_comment );
|
1134 |
$comment['note'] = $note;
|
1135 |
|
1136 |
+
$comment_result = \pb_backupbuddy::$classes['zipbuddy']->set_comment( $backup_file, $comment );
|
|
|
|
|
1137 |
|
1138 |
$information = array();
|
1139 |
+
if ( true === $comment_result ) {
|
1140 |
$information['result'] = 'SUCCESS';
|
1141 |
}
|
1142 |
|
1143 |
// Even if we cannot save the note into the archive file, store it in internal settings.
|
1144 |
+
$serial = \backupbuddy_core::get_serial_from_file( $backup_file );
|
1145 |
|
1146 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
1147 |
+
\pb_backupbuddy::status( 'details', 'Fileoptions instance #24.' );
|
1148 |
+
$backup_options = new \pb_backupbuddy_fileoptions( \backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt' );
|
1149 |
+
$result = $backup_options->is_ok();
|
1150 |
+
if ( true === $result ) {
|
1151 |
$backup_options->options['integrity']['comment'] = $note;
|
1152 |
$backup_options->save();
|
1153 |
}
|
1154 |
return $information;
|
1155 |
}
|
1156 |
|
1157 |
+
/**
|
1158 |
+
* Get hash.
|
1159 |
+
*
|
1160 |
+
* @return array|string[] Return results array.
|
1161 |
+
*
|
1162 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
1163 |
+
*/
|
1164 |
+
public function get_hash() {
|
1165 |
+
$callback_data = isset( $_POST['callback_data'] ) ? wp_unslash( $_POST['callback_data'] ) : '';
|
1166 |
+
$file = \backupbuddy_core::getBackupDirectory() . $callback_data;
|
1167 |
+
if ( file_exists( $file ) ) {
|
1168 |
+
return array(
|
1169 |
+
'result' => 'SUCCESS',
|
1170 |
+
'hash' => md5_file( $file ),
|
1171 |
+
);
|
1172 |
+
} else {
|
1173 |
+
return array( 'error' => 'Not found the file' );
|
1174 |
+
}
|
1175 |
}
|
1176 |
|
1177 |
+
/**
|
1178 |
+
* Zip viewer.
|
1179 |
+
*
|
1180 |
+
* @return array|string[] Return results array.
|
1181 |
+
*
|
1182 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1183 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
1184 |
+
* @uses \pb_backupbuddy::status()
|
1185 |
+
* @uses \pb_backupbuddy_fileoptions()
|
1186 |
+
* @uses \pb_backupbuddy_fileoptions::is_ok()
|
1187 |
+
* @uses \pb_backupbuddy_fileoptions::save()
|
1188 |
+
* @uses \pb_backupbuddy::$classes
|
1189 |
+
* @uses \pb_backupbuddy::$classes::get_file_list()
|
1190 |
+
* @uses \pluginbuddy_zipbuddy()
|
1191 |
+
*/
|
1192 |
+
public function zip_viewer() {
|
1193 |
+
|
1194 |
+
// How long to cache the specific backup file tree information for (seconds).
|
1195 |
$max_cache_time = 86400;
|
1196 |
|
1197 |
+
// This is the root directory we want the listing for.
|
1198 |
+
$root = isset( $_POST['dir'] ) ? wp_unslash( $_POST['dir'] ) : '';
|
1199 |
$root_len = strlen( $root );
|
1200 |
|
1201 |
+
// This will identify the backup zip file we want to list.
|
1202 |
+
$serial = isset( $_POST['serial'] ) ? sanitize_text_field( wp_unslash( $_POST['serial'] ) ) : '';
|
1203 |
$alerts = array();
|
1204 |
+
// The fileoptions file that contains the file tree information.
|
1205 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
1206 |
+
$fileoptions_file = \backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '-filetree.txt';
|
1207 |
|
1208 |
// Purge cache if too old.
|
1209 |
if ( file_exists( $fileoptions_file ) && ( ( time() - filemtime( $fileoptions_file ) ) > $max_cache_time ) ) {
|
1210 |
if ( false === unlink( $fileoptions_file ) ) {
|
1211 |
+
$alerts[] = 'Error #456765545. Unable to wipe cached fileoptions file `' . $fileoptions_file . '`.';
|
1212 |
}
|
1213 |
}
|
1214 |
|
1215 |
+
\pb_backupbuddy::status( 'details', 'Fileoptions instance #28.' );
|
1216 |
+
$fileoptions = new \pb_backupbuddy_fileoptions( $fileoptions_file );
|
1217 |
+
$zip_viewer = isset( $_POST['zip_viewer'] ) ? wp_unslash( $_POST['zip_viewer'] ) : '';
|
1218 |
+
// Either we are getting cached file tree information or we need to create afresh.
|
1219 |
+
$result = $fileoptions->is_ok();
|
1220 |
+
if ( true !== $result ) {
|
1221 |
// Get file listing.
|
1222 |
+
require_once \pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
|
1223 |
+
\pb_backupbuddy::$classes['zipbuddy'] = new \pluginbuddy_zipbuddy( ABSPATH, array(), 'unzip' );
|
1224 |
+
$files = \pb_backupbuddy::$classes['zipbuddy']->get_file_list( \backupbuddy_core::getBackupDirectory() . str_replace( '\\/', '', $zip_viewer ) );
|
1225 |
+
$fileoptions->options = $files;
|
1226 |
$fileoptions->save();
|
1227 |
} else {
|
1228 |
$files = &$fileoptions->options;
|
1229 |
}
|
1230 |
|
|
|
1231 |
if ( ! is_array( $files ) ) {
|
1232 |
return array( 'error' => 'Error #548484. Unable to retrieve file listing from backup file `' . htmlentities( $zip_viewer ) . '`.' );
|
1233 |
}
|
|
|
|
|
1234 |
$subdirs = array();
|
1235 |
|
1236 |
+
foreach ( $files as $key => $file ) {
|
1237 |
+
if ( strlen( $file[0] ) < $root_len ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
1238 |
unset( $files[ $key ] );
|
1239 |
continue;
|
|
|
1240 |
}
|
1241 |
|
1242 |
+
if ( substr( $file[0], 0, $root_len ) != $root ) {
|
|
|
|
|
|
|
|
|
|
|
1243 |
unset( $files[ $key ] );
|
1244 |
continue;
|
|
|
1245 |
}
|
1246 |
|
1247 |
+
if ( 0 == strcmp( $file[0], $root ) ) {
|
|
|
|
|
|
|
|
|
1248 |
unset( $files[ $key ] );
|
1249 |
continue;
|
|
|
1250 |
}
|
1251 |
+
$unrooted_file = substr( $file[0], $root_len );
|
1252 |
+
$pos = strpos( $unrooted_file, '/' );
|
1253 |
+
if ( false !== $pos ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1254 |
$subdir = substr( $unrooted_file, 0, ( $pos + 1 ) );
|
1255 |
+
if ( ! in_array( $subdir, $subdirs ) ) {
|
1256 |
+
$subdirs[] = $subdir;
|
1257 |
+
$files[ $key ][0] = $subdir;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1258 |
} else {
|
|
|
|
|
1259 |
unset( $files[ $key ] );
|
1260 |
continue;
|
1261 |
|
1262 |
}
|
|
|
1263 |
} else {
|
1264 |
+
$files[ $key ][0] = $unrooted_file;
|
|
|
|
|
|
|
|
|
1265 |
}
|
|
|
1266 |
}
|
1267 |
|
1268 |
+
return array(
|
1269 |
+
'result' => 'SUCCESS',
|
1270 |
+
'files' => $files,
|
1271 |
+
'message' => implode( '<br/>', $alerts ),
|
1272 |
+
);
|
1273 |
}
|
1274 |
|
1275 |
+
/**
|
1276 |
+
* Exclude tree.
|
1277 |
+
*
|
1278 |
+
* @return array|string[] Return excluded files & directories list html or ERROR message.
|
1279 |
+
*/
|
1280 |
+
public function exclude_tree() {
|
1281 |
+
$root = substr( ABSPATH, 0, strlen( ABSPATH ) - 1 ) . '/' . ( isset( $_POST['dir'] ) ? ltrim( urldecode( $_POST['dir'] ), '/\\' ) : '' );
|
1282 |
+
if ( file_exists( $root ) ) {
|
1283 |
$files = scandir( $root );
|
1284 |
|
1285 |
natcasesort( $files );
|
1286 |
|
1287 |
// Sort with directories first.
|
1288 |
+
$sorted_files = array(); // Temporary holder for sorting files.
|
1289 |
$sorted_directories = array(); // Temporary holder for sorting directories.
|
1290 |
+
foreach ( $files as $file ) {
|
1291 |
+
if ( ( '.' == $file ) || ( '..' == $file ) ) {
|
1292 |
continue;
|
1293 |
}
|
1294 |
+
if ( is_file( str_replace( '//', '/', $root . $file ) ) ) {
|
1295 |
array_push( $sorted_files, $file );
|
1296 |
} else {
|
1297 |
array_unshift( $sorted_directories, $file );
|
1304 |
|
1305 |
ob_start();
|
1306 |
|
1307 |
+
if ( count( $files ) > 0 ) { // Files found.
|
1308 |
echo '<ul class="jqueryFileTree" style="display: none;">';
|
1309 |
+
foreach ( $files as $file ) {
|
1310 |
+
if ( file_exists( str_replace( '//', '/', $root . $file ) ) ) {
|
1311 |
if ( is_dir( str_replace( '//', '/', $root . $file ) ) ) { // Directory.
|
1312 |
echo '<li class="directory collapsed">';
|
1313 |
+
$return = '';
|
1314 |
$return .= '<div class="pb_backupbuddy_treeselect_control">';
|
1315 |
+
$return .= '<img src="' . \pb_backupbuddy::plugin_url() . '/images/redminus.png" style="vertical-align: -3px;" title="Add to exclusions..." class="pb_backupbuddy_filetree_exclude">';
|
1316 |
$return .= '</div>';
|
1317 |
+
echo '<a href="#" rel="' . htmlentities( str_replace( ABSPATH, '', $root ) . $file ) . '/" title="Toggle expand...">' . htmlentities( $file ) . $return . '</a>';
|
1318 |
echo '</li>';
|
1319 |
} else { // File.
|
1320 |
echo '<li class="file collapsed">';
|
1321 |
+
$return = '';
|
1322 |
$return .= '<div class="pb_backupbuddy_treeselect_control">';
|
1323 |
+
$return .= '<img src="' . \pb_backupbuddy::plugin_url() . '/images/redminus.png" style="vertical-align: -3px;" title="Add to exclusions..." class="pb_backupbuddy_filetree_exclude">';
|
1324 |
$return .= '</div>';
|
1325 |
+
echo '<a href="#" rel="' . htmlentities( str_replace( ABSPATH, '', $root ) . $file ) . '">' . htmlentities( $file ) . $return . '</a>';
|
1326 |
echo '</li>';
|
1327 |
}
|
1328 |
}
|
1330 |
echo '</ul>';
|
1331 |
} else {
|
1332 |
echo '<ul class="jqueryFileTree" style="display: none;">';
|
1333 |
+
echo '<li><a href="#" rel="' . htmlentities( \pb_backupbuddy::_POST( 'dir' ) . 'NONE' ) . '"><i>Empty Directory ...</i></a></li>';
|
1334 |
echo '</ul>';
|
1335 |
}
|
1336 |
|
1337 |
$html = ob_get_clean();
|
1338 |
+
return array( 'result' => $html );
|
1339 |
} else {
|
1340 |
+
return array( 'error' => 'Error #1127555. Unable to read child site root.' );
|
1341 |
}
|
|
|
1342 |
}
|
1343 |
|
1344 |
+
/**
|
1345 |
+
* Additional tables.
|
1346 |
+
*
|
1347 |
+
* @param bool $display_size Display size. Default: false.
|
1348 |
+
*
|
1349 |
+
* @return string Additional table html.
|
1350 |
+
* @throws Exception Error message.
|
1351 |
+
*
|
1352 |
+
* @uses \MainWP\Child\MainWP_Helper::check_classes_exists()
|
1353 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
1354 |
+
* @uses \MainWP\Child\MainWP_Helper::check_properties()
|
1355 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
1356 |
+
* @uses $wpdb::get_results()
|
1357 |
+
* @uses \pb_backupbuddy::$format::file_size()
|
1358 |
+
* @uses \pb_backupbuddy::plugin_url()
|
1359 |
+
*/
|
1360 |
+
public function pb_additional_tables( $display_size = false ) {
|
1361 |
+
|
1362 |
+
MainWP_Helper::check_classes_exists( '\pb_backupbuddy' );
|
1363 |
+
MainWP_Helper::check_methods( '\pb_backupbuddy', 'plugin_url' );
|
1364 |
+
MainWP_Helper::check_properties( '\pb_backupbuddy', 'format' );
|
1365 |
+
MainWP_Helper::check_methods( \pb_backupbuddy::$format, 'file_size' );
|
1366 |
+
|
1367 |
+
$return = '';
|
1368 |
$size_string = '';
|
1369 |
|
1370 |
+
/** @global object $wpdb WordPress Database. */
|
1371 |
global $wpdb;
|
1372 |
+
|
1373 |
if ( true === $display_size ) {
|
1374 |
+
$results = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A );
|
1375 |
} else {
|
1376 |
+
$results = $wpdb->get_results( 'SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE()', ARRAY_A );
|
1377 |
}
|
1378 |
+
foreach ( $results as $result ) {
|
1379 |
|
1380 |
if ( true === $display_size ) {
|
1381 |
// Fix up row count and average row length for InnoDB engine which returns inaccurate (and changing) values for these.
|
1382 |
+
if ( 'InnoDB' === $result['Engine'] ) {
|
1383 |
+
$rowCount = $wpdb->get_var( "SELECT COUNT(1) as rowCount FROM `{$result[ 'Name' ]}`", ARRAY_A ); // phpcs:ignore -- safe query.
|
1384 |
+
if ( false !== $rowCount ) {
|
1385 |
+
$result['Rows'] = $rowCount;
|
1386 |
+
if ( 0 < $result['Rows'] ) {
|
1387 |
+
$result['Avg_row_length'] = ( $result['Data_length'] / $result['Rows'] );
|
1388 |
}
|
1389 |
}
|
1390 |
unset( $rowCount );
|
1391 |
}
|
1392 |
|
1393 |
// Table size.
|
1394 |
+
$size_string = ' (' . \pb_backupbuddy::$format->file_size( ( $result['Data_length'] + $result['Index_length'] ) ) . ') ';
|
1395 |
|
1396 |
} // end if display size enabled.
|
1397 |
|
1398 |
$return .= '<li class="file ext_sql collapsed">';
|
1399 |
$return .= '<a rel="/" alt="' . $result['table_name'] . '">' . $result['table_name'] . $size_string;
|
1400 |
$return .= '<div class="pb_backupbuddy_treeselect_control">';
|
1401 |
+
$return .= '<img src="' . \pb_backupbuddy::plugin_url() . '/images/redminus.png" style="vertical-align: -3px;" title="Add to exclusions..." class="pb_backupbuddy_table_addexclude"> <img src="' . \pb_backupbuddy::plugin_url() . '/images/greenplus.png" style="vertical-align: -3px;" title="Add to inclusions..." class="pb_backupbuddy_table_addinclude">';
|
1402 |
$return .= '</div>';
|
1403 |
$return .= '</a>';
|
1404 |
$return .= '</li>';
|
1407 |
return '<div class="jQueryOuterTree" style="position: absolute; height: 160px;"><ul class="jqueryFileTree">' . $return . '</ul></div>';
|
1408 |
}
|
1409 |
|
1410 |
+
/**
|
1411 |
+
* Restore file view.
|
1412 |
+
*
|
1413 |
+
* @return array|string[] Return results array. ERROR message on failure.
|
1414 |
+
*
|
1415 |
+
* @uses \backupbuddy_core::get_serial_from_file()
|
1416 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1417 |
+
* @uses \pluginbuddy_zipbuddy()
|
1418 |
+
* @uses \pluginbuddy_zipbuddy::extract()
|
1419 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
1420 |
+
* @uses \pb_backupbuddy::status()
|
1421 |
+
* @uses \pb_backupbuddy::anti_directory_browsing()
|
1422 |
+
* @uses \pb_backupbuddy::$filesystem::unlink_recursive()
|
1423 |
+
*/
|
1424 |
+
public function restore_file_view() {
|
1425 |
+
|
1426 |
+
$archive_file = isset( $_POST['archive'] ) ? wp_unslash( $_POST['archive'] ) : ''; // archive to extract from.
|
1427 |
+
$file = isset( $_POST['file'] ) ? wp_unslash( $_POST['file'] ) : ''; // file to extract.
|
1428 |
+
$serial = \backupbuddy_core::get_serial_from_file( $archive_file ); // serial of archive.
|
1429 |
+
$temp_file = uniqid(); // temp filename to extract into.
|
1430 |
+
|
1431 |
+
require_once \pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
|
1432 |
+
$zipbuddy = new \pluginbuddy_zipbuddy( \backupbuddy_core::getBackupDirectory() );
|
1433 |
|
1434 |
// Calculate temp directory & lock it down.
|
1435 |
+
$temp_dir = get_temp_dir();
|
1436 |
$destination = $temp_dir . 'backupbuddy-' . $serial;
|
1437 |
if ( ( ( ! file_exists( $destination ) ) && ( false === mkdir( $destination ) ) ) ) {
|
1438 |
$error = 'Error #458485945b: Unable to create temporary location.';
|
1439 |
+
\pb_backupbuddy::status( 'error', $error );
|
1440 |
+
return array( 'error' => $error );
|
1441 |
}
|
1442 |
|
1443 |
// If temp directory is within webroot then lock it down.
|
1444 |
$temp_dir = str_replace( '\\', '/', $temp_dir ); // Normalize for Windows.
|
1445 |
$temp_dir = rtrim( $temp_dir, '/\\' ) . '/'; // Enforce single trailing slash.
|
1446 |
+
if ( false !== stristr( $temp_dir, ABSPATH ) ) { // Temp dir is within webroot.
|
1447 |
+
\pb_backupbuddy::anti_directory_browsing( $destination );
|
1448 |
}
|
1449 |
unset( $temp_dir );
|
1450 |
|
1451 |
$message = 'Extracting "' . $file . '" from archive "' . $archive_file . '" into temporary file "' . $destination . '". ';
|
1452 |
+
\pb_backupbuddy::status( 'details', $message );
|
|
|
|
|
1453 |
|
1454 |
$file_content = '';
|
1455 |
|
1456 |
+
$extractions = array( $file => $temp_file );
|
1457 |
+
$extract_result = $zipbuddy->extract( \backupbuddy_core::getBackupDirectory() . $archive_file, $destination, $extractions );
|
1458 |
if ( false === $extract_result ) { // failed.
|
|
|
1459 |
$error = 'Error #584984458. Unable to extract.';
|
1460 |
+
\pb_backupbuddy::status( 'error', $error );
|
1461 |
return array( 'error' => $error );
|
1462 |
} else { // success.
|
1463 |
$file_content = file_get_contents( $destination . '/' . $temp_file );
|
1465 |
|
1466 |
// Try to cleanup.
|
1467 |
if ( file_exists( $destination ) ) {
|
1468 |
+
if ( false === \pb_backupbuddy::$filesystem->unlink_recursive( $destination ) ) {
|
1469 |
+
\pb_backupbuddy::status( 'details', 'Unable to delete temporary holding directory `' . $destination . '`.' );
|
1470 |
} else {
|
1471 |
+
\pb_backupbuddy::status( 'details', 'Cleaned up temporary files.' );
|
1472 |
}
|
1473 |
}
|
1474 |
|
1475 |
+
return array(
|
1476 |
+
'result' => 'SUCCESS',
|
1477 |
+
'file_content' => $file_content,
|
1478 |
+
);
|
1479 |
}
|
1480 |
|
1481 |
|
1482 |
+
/**
|
1483 |
+
* Backupbuddy Restore files.
|
1484 |
+
*
|
1485 |
+
* @return array Return results array.
|
1486 |
+
*
|
1487 |
+
* @uses \pb_backupbuddy::set_status_serial()
|
1488 |
+
* @uses \pb_backupbuddy::status()
|
1489 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1490 |
+
* @uses \backupbuddy_restore_files::restore()
|
1491 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
1492 |
+
* @uses \pb_backupbuddy::flush()
|
1493 |
+
*/
|
1494 |
+
public function restore_file_restore() {
|
1495 |
|
1496 |
+
$files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : ''; // file to extract.
|
1497 |
+
$archive_file = isset( $_POST['archive'] ) ? wp_unslash( $_POST['archive'] ) : ''; // archive to extract from.
|
1498 |
|
1499 |
$files_array = explode( ',', $files );
|
1500 |
+
$files = array();
|
1501 |
+
foreach ( $files_array as $file ) {
|
1502 |
if ( substr( $file, -1 ) == '/' ) { // If directory then add wildcard.
|
1503 |
$file = $file . '*';
|
1504 |
}
|
1505 |
+
$files[ $file ] = $file;
|
1506 |
}
|
1507 |
unset( $files_array );
|
1508 |
|
1509 |
$success = false;
|
1510 |
|
1511 |
+
/** @global object $pb_backupbuddy_js_status BackupBuddy js status. */
|
1512 |
global $pb_backupbuddy_js_status;
|
1513 |
+
|
1514 |
$pb_backupbuddy_js_status = true;
|
1515 |
+
|
1516 |
+
\pb_backupbuddy::set_status_serial( 'restore' );
|
1517 |
+
|
1518 |
+
/** @global string $wp_version WordPress version. */
|
1519 |
global $wp_version;
|
|
|
1520 |
|
1521 |
+
\pb_backupbuddy::status( 'details', 'BackupBuddy v' . \pb_backupbuddy::settings( 'version' ) . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.' );
|
1522 |
+
|
1523 |
+
require \pb_backupbuddy::plugin_path() . '/classes/_restoreFiles.php';
|
1524 |
|
1525 |
ob_start();
|
1526 |
+
$result = \backupbuddy_restore_files::restore( \backupbuddy_core::getBackupDirectory() . $archive_file, $files, $finalPath = ABSPATH );
|
1527 |
$restore_result = ob_get_clean();
|
1528 |
+
\pb_backupbuddy::flush();
|
1529 |
+
return array( 'restore_result' => $restore_result );
|
1530 |
}
|
1531 |
|
1532 |
+
/**
|
1533 |
+
* Get backup list.
|
1534 |
+
*
|
1535 |
+
* @param string $type Type of backup.
|
1536 |
+
* @param bool $subsite_mode Whether or not the backup is for a subsite. Default: false.
|
1537 |
+
*
|
1538 |
+
* @return array Return $sorted_backups array.
|
1539 |
+
*
|
1540 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
1541 |
+
* @uses \backupbuddy_core::backup_prefix()
|
1542 |
+
* @uses \backupbuddy_core::get_serial_from_file()
|
1543 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
1544 |
+
* @uses \backupbuddy_core::backup_integrity_check()
|
1545 |
+
* @uses \backupbuddy_core::pretty_backup_type()
|
1546 |
+
* @uses \backupbuddy_core::getBackupTypeFromFile()
|
1547 |
+
* @uses \backupbuddy_core::pretty_backup_type()
|
1548 |
+
* @uses \backupbuddy_core::getBackupTypeFromFile()
|
1549 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1550 |
+
* @uses \pb_backupbuddy::status()
|
1551 |
+
* @uses \pb_backupbuddy_fileoptions()
|
1552 |
+
* @uses \pb_backupbuddy_fileoptions()
|
1553 |
+
* @uses \pb_backupbuddy::$format::file_size()
|
1554 |
+
* @uses \pb_backupbuddy::$format::time_ago()
|
1555 |
+
* @uses \pb_backupbuddy::$format::prettify()
|
1556 |
+
* @uses \pb_backupbuddy::$format::date()
|
1557 |
+
* @uses \pb_backupbuddy::$format::localize_time()
|
1558 |
+
*/
|
1559 |
+
public function get_backup_list( $type = 'default', $subsite_mode = false ) {
|
1560 |
+
$backups = array();
|
1561 |
$backup_sort_dates = array();
|
1562 |
|
1563 |
+
$files = glob( \backupbuddy_core::getBackupDirectory() . 'backup*.zip' );
|
1564 |
if ( ! is_array( $files ) ) {
|
1565 |
$files = array();
|
1566 |
}
|
1567 |
|
1568 |
+
$files2 = glob( \backupbuddy_core::getBackupDirectory() . 'snapshot*.zip' );
|
1569 |
if ( ! is_array( $files2 ) ) {
|
1570 |
$files2 = array();
|
1571 |
}
|
1572 |
|
1573 |
$files = array_merge( $files, $files2 );
|
1574 |
|
1575 |
+
if ( is_array( $files ) && ! empty( $files ) ) { // For robustness. Without open_basedir the glob() function returns an empty array for no match. With open_basedir in effect the glob() function returns a boolean false for no match.
|
1576 |
|
1577 |
+
$backup_prefix = \backupbuddy_core::backup_prefix(); // To checking that this user can see this backup.
|
1578 |
+
foreach ( $files as $file_id => $file ) {
|
1579 |
|
1580 |
+
if ( ( true === $subsite_mode ) && is_multisite() ) { // If a Network and NOT the superadmin must make sure they can only see the specific subsite backups for security purposes.
|
1581 |
|
1582 |
// Only allow viewing of their own backups.
|
1583 |
if ( ! strstr( $file, $backup_prefix ) ) {
|
1584 |
+
unset( $files[ $file_id ] ); // Remove this backup from the list. This user does not have access to it.
|
1585 |
continue; // Skip processing to next file.
|
1586 |
}
|
1587 |
}
|
1588 |
|
1589 |
+
$serial = \backupbuddy_core::get_serial_from_file( $file );
|
1590 |
|
1591 |
$options = array();
|
1592 |
+
if ( file_exists( \backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt' ) ) {
|
1593 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
1594 |
+
\pb_backupbuddy::status( 'details', 'Fileoptions instance #33.' );
|
1595 |
+
$backup_options = new \pb_backupbuddy_fileoptions( \backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt', $read_only = false, $ignore_lock = false, $create_file = true ); // Will create file to hold integrity data if nothing exists.
|
1596 |
} else {
|
1597 |
$backup_options = '';
|
1598 |
}
|
1599 |
+
$backup_integrity = \backupbuddy_core::backup_integrity_check( $file, $backup_options, $options );
|
1600 |
|
1601 |
// Backup status.
|
1602 |
$pretty_status = array(
|
1603 |
+
true => '<span class="pb_label pb_label-success">Good</span>', // v4.0+ Good.
|
1604 |
+
'pass' => '<span class="pb_label pb_label-success">Good</span>', // Pre-v4.0 Good.
|
1605 |
+
false => '<span class="pb_label pb_label-important">Bad</span>', // v4.0+ Bad.
|
1606 |
+
'fail' => '<span class="pb_label pb_label-important">Bad</span>', // Pre-v4.0 Bad.
|
1607 |
);
|
1608 |
|
1609 |
// Backup type.
|
1610 |
$pretty_type = array(
|
1611 |
+
'full' => 'Full',
|
1612 |
+
'db' => 'Database',
|
1613 |
+
'files' => 'Files',
|
1614 |
+
'themes' => 'Themes',
|
1615 |
+
'plugins' => 'Plugins',
|
1616 |
);
|
1617 |
|
1618 |
+
// Defaults.
|
|
|
1619 |
$detected_type = '';
|
1620 |
+
$file_size = '';
|
1621 |
+
$modified = '';
|
1622 |
$modified_time = 0;
|
1623 |
+
$integrity = '';
|
1624 |
|
1625 |
$main_string = 'Warn#284.';
|
1626 |
if ( is_array( $backup_integrity ) ) { // Data intact... put it all together.
|
1627 |
// Calculate time ago.
|
1628 |
$time_ago = '';
|
1629 |
if ( isset( $backup_integrity['modified'] ) ) {
|
1630 |
+
$time_ago = \pb_backupbuddy::$format->time_ago( $backup_integrity['modified'] ) . ' ago';
|
1631 |
}
|
1632 |
|
1633 |
+
$detected_type = \pb_backupbuddy::$format->prettify( $backup_integrity['detected_type'], $pretty_type );
|
1634 |
+
if ( '' == $detected_type ) {
|
1635 |
+
$detected_type = \backupbuddy_core::pretty_backup_type( \backupbuddy_core::getBackupTypeFromFile( $file ) );
|
1636 |
if ( '' == $detected_type ) {
|
1637 |
$detected_type = '<span class="description">Unknown</span>';
|
1638 |
}
|
1644 |
<span style="display: inline-block; float: left; height: 15px; border-right: 1px solid #EBEBEB; margin-left: 6px; margin-right: 6px;"></span>
|
1645 |
' . htmlentities( $backup_options->options['profile']['title'] ) . '
|
1646 |
</div>
|
1647 |
+
';
|
|
|
1648 |
}
|
1649 |
}
|
1650 |
|
1651 |
+
$file_size = \pb_backupbuddy::$format->file_size( $backup_integrity['size'] );
|
1652 |
+
$modified = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $backup_integrity['modified'] ), 'l, F j, Y - g:i:s a' );
|
1653 |
$modified_time = $backup_integrity['modified'];
|
1654 |
if ( isset( $backup_integrity['status'] ) ) { // Pre-v4.0.
|
1655 |
$status = $backup_integrity['status'];
|
1656 |
+
} else { // v4.0+.
|
1657 |
$status = $backup_integrity['is_ok'];
|
1658 |
}
|
1659 |
|
|
|
1660 |
// Calculate main row string.
|
1661 |
+
if ( 'default' == $type ) { // Default backup listing.
|
1662 |
+
$download_url = '/wp-admin/admin-ajax.php?action=mainwp_backupbuddy_download_archive&backupbuddy_backup=' . basename( $file ) . '&_wpnonce=' . MainWP_Utility::create_nonce_without_session( 'mainwp_download_backup' );
|
1663 |
+
$main_string = '<a href="#" download-url="' . $download_url . '"class="backupbuddyFileTitle mwp_bb_download_backup_lnk" title="' . basename( $file ) . '">' . $modified . ' (' . $time_ago . ')</a>';
|
1664 |
+
} elseif ( 'migrate' == $type ) { // Migration backup listing.
|
1665 |
+
$main_string = '<a class="pb_backupbuddy_hoveraction_migrate backupbuddyFileTitle" rel="' . basename( $file ) . '" href="' . \pb_backupbuddy::page_url() . '&migrate=' . basename( $file ) . '&value=' . basename( $file ) . '" title="' . basename( $file ) . '">' . $modified . ' (' . $time_ago . ')</a>';
|
1666 |
} else {
|
1667 |
$main_string = '{Unknown type.}';
|
1668 |
}
|
1669 |
// Add comment to main row string if applicable.
|
1670 |
+
if ( isset( $backup_integrity['comment'] ) && ( false !== $backup_integrity['comment'] ) && ( '' !== $backup_integrity['comment'] ) ) {
|
1671 |
$main_string .= '<br><span class="description">Note: <span class="pb_backupbuddy_notetext">' . htmlentities( $backup_integrity['comment'] ) . '</span></span>';
|
1672 |
}
|
1673 |
|
1674 |
+
$integrity = \pb_backupbuddy::$format->prettify( $status, $pretty_status ) . ' ';
|
1675 |
+
if ( isset( $backup_integrity['scan_notes'] ) && count( (array) $backup_integrity['scan_notes'] ) > 0 ) {
|
1676 |
+
foreach ( (array) $backup_integrity['scan_notes'] as $scan_note ) {
|
|
|
1677 |
$integrity .= $scan_note . ' ';
|
1678 |
}
|
1679 |
}
|
1680 |
+
$integrity .= '<a href="#" serial="' . $serial . '" class="mwp_bb_reset_integrity_lnk" file-name="' . basename( $file ) . '" title="Rescan integrity. Last checked ' . \pb_backupbuddy::$format->date( $backup_integrity['scan_time'] ) . '."> <i class="fa fa-refresh" aria-hidden="true"></i></a>';
|
1681 |
$integrity .= '<div class="row-actions"><a title="' . __( 'Backup Status', 'mainwp-child' ) . '" href="#" serial="' . $serial . '" class="mainwp_bb_view_details_lnk thickbox">' . __( 'View Details', 'mainwp-child' ) . '</a></div>';
|
1682 |
|
1683 |
+
$sumLogFile = \backupbuddy_core::getLogDirectory() . 'status-' . $serial . '_' . \pb_backupbuddy::$options['log_serial'] . '.txt';
|
1684 |
if ( file_exists( $sumLogFile ) ) {
|
1685 |
$integrity .= '<div class="row-actions"><a title="' . __( 'View Backup Log', 'mainwp-child' ) . '" href="#" serial="' . $serial . '" class="mainwp_bb_view_log_lnk thickbox">' . __( 'View Log', 'mainwp-child' ) . '</a></div>';
|
1686 |
}
|
1687 |
+
}
|
|
|
1688 |
|
1689 |
// No integrity check for themes or plugins types.
|
1690 |
+
$raw_type = \backupbuddy_core::getBackupTypeFromFile( $file );
|
1691 |
if ( ( 'themes' == $raw_type ) || ( 'plugins' == $raw_type ) ) {
|
1692 |
$integrity = 'n/a';
|
1693 |
}
|
1694 |
|
1695 |
+
$backups[ basename( $file ) ] = array(
|
1696 |
array( basename( $file ), $main_string . '<br><span class="description" style="color: #AAA; display: inline-block; margin-top: 5px;">' . basename( $file ) . '</span>' ),
|
1697 |
$detected_type,
|
1698 |
$file_size,
|
1699 |
$integrity,
|
1700 |
);
|
1701 |
|
1702 |
+
$backup_sort_dates[ basename( $file ) ] = $modified_time;
|
1703 |
|
1704 |
+
}
|
1705 |
+
}
|
|
|
|
|
|
|
1706 |
|
1707 |
// Sort backup by date.
|
1708 |
arsort( $backup_sort_dates );
|
1709 |
// Re-arrange backups based on sort dates.
|
1710 |
$sorted_backups = array();
|
1711 |
+
foreach ( $backup_sort_dates as $backup_file => $backup_sort_date ) {
|
1712 |
+
$sorted_backups[ $backup_file ] = $backups[ $backup_file ];
|
1713 |
+
unset( $backups[ $backup_file ] );
|
1714 |
}
|
1715 |
unset( $backups );
|
1716 |
return $sorted_backups;
|
1717 |
+
}
|
1718 |
|
1719 |
+
/**
|
1720 |
+
* Get recent backup list.
|
1721 |
+
*
|
1722 |
+
* @return array $recentBackups Return recent backups array.
|
1723 |
+
*
|
1724 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
1725 |
+
* @uses \backupbuddy_core::pretty_backup_type()
|
1726 |
+
* @uses \backupbuddy_core::getBackupTypeFromFile()
|
1727 |
+
* @uses \backupbuddy_core::getBackupTypeFromFile()
|
1728 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1729 |
+
* @uses \pb_backupbuddy::status()
|
1730 |
+
* @uses \pb_backupbuddy_fileoptions()
|
1731 |
+
* @uses \pb_backupbuddy_fileoptions::is_ok()
|
1732 |
+
* @uses \pb_backupbuddy::$format::date()
|
1733 |
+
* @uses \pb_backupbuddy::$format::localize_time()
|
1734 |
+
* @uses \pb_backupbuddy::$format::prettify()
|
1735 |
+
* @uses \pb_backupbuddy::$format::file_size()
|
1736 |
+
*/
|
1737 |
+
public function get_recent_backup_list() {
|
1738 |
+
$recentBackups_list = glob( \backupbuddy_core::getLogDirectory() . 'fileoptions/*.txt' );
|
1739 |
if ( ! is_array( $recentBackups_list ) ) {
|
1740 |
$recentBackups_list = array();
|
1741 |
}
|
1745 |
|
1746 |
// Backup type.
|
1747 |
$pretty_type = array(
|
1748 |
+
'full' => 'Full',
|
1749 |
+
'db' => 'Database',
|
1750 |
+
'files' => 'Files',
|
1751 |
);
|
1752 |
|
1753 |
+
foreach ( $recentBackups_list as $backup_fileoptions ) {
|
1754 |
|
1755 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
1756 |
+
\pb_backupbuddy::status( 'details', 'Fileoptions instance #1.' );
|
1757 |
+
$backup = new \pb_backupbuddy_fileoptions( $backup_fileoptions, $read_only = true );
|
1758 |
+
$result = $backup->is_ok();
|
1759 |
+
if ( true !== $result ) {
|
1760 |
+
\pb_backupbuddy::status( 'error', __( 'Unable to access fileoptions data file.', 'mainwp-child' ) . ' Error: ' . $result );
|
1761 |
continue;
|
1762 |
}
|
1763 |
$backup = &$backup->options;
|
1764 |
|
1765 |
+
if ( ! isset( $backup['serial'] ) || ( '' == $backup['serial'] ) ) {
|
1766 |
continue;
|
1767 |
}
|
1768 |
if ( ( $backup['finish_time'] >= $backup['start_time'] ) && ( 0 != $backup['start_time'] ) ) {
|
1769 |
$status = '<span class="pb_label pb_label-success">Completed</span>';
|
1770 |
+
} elseif ( -1 == $backup['finish_time'] ) {
|
1771 |
$status = '<span class="pb_label pb_label-warning">Cancelled</span>';
|
1772 |
+
} elseif ( false === $backup['finish_time'] ) {
|
1773 |
$status = '<span class="pb_label pb_label-error">Failed (timeout?)</span>';
|
1774 |
+
} elseif ( ( time() - $backup['updated_time'] ) > \backupbuddy_constants::TIME_BEFORE_CONSIDERED_TIMEOUT ) {
|
1775 |
$status = '<span class="pb_label pb_label-error">Failed (likely timeout)</span>';
|
1776 |
} else {
|
1777 |
$status = '<span class="pb_label pb_label-warning">In progress or timed out</span>';
|
1778 |
}
|
1779 |
$status .= '<br>';
|
1780 |
|
|
|
1781 |
// Technical details link.
|
1782 |
$status .= '<div class="row-actions">';
|
1783 |
$status .= '<a title="' . __( 'Backup Process Technical Details', 'mainwp-child' ) . '" href="#" serial="' . $backup['serial'] . '" class="mainwp_bb_view_details_lnk thickbox">View Details</a>';
|
1784 |
|
1785 |
+
$sumLogFile = \backupbuddy_core::getLogDirectory() . 'status-' . $backup['serial'] . '_' . \pb_backupbuddy::$options['log_serial'] . '.txt';
|
1786 |
if ( file_exists( $sumLogFile ) ) {
|
1787 |
$status .= '<div class="row-actions"><a title="' . __( 'View Backup Log', 'mainwp-child' ) . '" href="#" serial="' . $backup['serial'] . '" class="mainwp_bb_view_log_lnk thickbox">' . __( 'View Log', 'mainwp-child' ) . '</a></div>';
|
1788 |
}
|
1791 |
|
1792 |
// Calculate finish time (if finished).
|
1793 |
if ( $backup['finish_time'] > 0 ) {
|
1794 |
+
$finish_time = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $backup['finish_time'] ) ) . '<br><span class="description">' . \pb_backupbuddy::$format->time_ago( $backup['finish_time'] ) . ' ago</span>';
|
1795 |
} else { // unfinished.
|
1796 |
$finish_time = '<i>Unfinished</i>';
|
1797 |
}
|
1798 |
|
1799 |
+
$backupTitle = '<span class="backupbuddyFileTitle" style="color: #000;" title="' . basename( $backup['archive_file'] ) . '">' . \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $backup['start_time'] ), 'l, F j, Y - g:i:s a' ) . ' (' . \pb_backupbuddy::$format->time_ago( $backup['start_time'] ) . ' ago)</span><br><span class="description">' . basename( $backup['archive_file'] ) . '</span>';
|
1800 |
|
1801 |
if ( isset( $backup['profile'] ) && isset( $backup['profile']['type'] ) ) {
|
1802 |
+
$backupType = '<div><span style="color: #AAA; float: left;">' . \pb_backupbuddy::$format->prettify( $backup['profile']['type'], $pretty_type ) . '</span><span style="display: inline-block; float: left; height: 15px; border-right: 1px solid #EBEBEB; margin-left: 6px; margin-right: 6px;"></span>' . $backup['profile']['title'] . '</div>';
|
|
|
|
|
|
|
|
|
1803 |
} else {
|
1804 |
+
$backupType = \backupbuddy_core::pretty_backup_type( \backupbuddy_core::getBackupTypeFromFile( $backup['archive_file'] ) );
|
1805 |
if ( '' == $backupType ) {
|
1806 |
$backupType = '<span class="description">Unknown</span>';
|
1807 |
}
|
1808 |
}
|
1809 |
|
1810 |
if ( isset( $backup['archive_size'] ) && ( $backup['archive_size'] > 0 ) ) {
|
1811 |
+
$archive_size = \pb_backupbuddy::$format->file_size( $backup['archive_size'] );
|
1812 |
} else {
|
1813 |
$archive_size = 'n/a';
|
1814 |
}
|
1815 |
|
1816 |
// No integrity check for themes or plugins types.
|
1817 |
+
$raw_type = \backupbuddy_core::getBackupTypeFromFile( $backup['archive_file'] );
|
1818 |
if ( ( 'themes' == $raw_type ) || ( 'plugins' == $raw_type ) ) {
|
1819 |
$status = 'n/a';
|
1820 |
}
|
1832 |
}
|
1833 |
|
1834 |
$columns = array(
|
1835 |
+
__( 'Recently Made Backups (Start Time)', 'mainwp-child' ),
|
1836 |
+
__( 'Type | Profile', 'mainwp-child' ),
|
1837 |
+
__( 'File Size', 'mainwp-child' ),
|
1838 |
+
__( 'Trigger', 'mainwp-child' ),
|
1839 |
+
__( 'Status', 'mainwp-child' ) . ' <span class="description">(hover for options)</span>',
|
1840 |
);
|
1841 |
|
1842 |
+
/**
|
1843 |
+
* Backupbuddy Sort.
|
1844 |
+
*
|
1845 |
+
* @param array $array Array to sort.
|
1846 |
+
* @param strign $key Sort key.
|
1847 |
+
*
|
1848 |
+
* @return array $array Return sorted array.
|
1849 |
+
*/
|
1850 |
+
function pb_backupbuddy_aasort( &$array, $key ) {
|
1851 |
+
$sorter = array();
|
1852 |
+
$ret = array();
|
1853 |
+
reset( $array );
|
1854 |
+
foreach ( $array as $ii => $va ) {
|
1855 |
+
$sorter[ $ii ] = $va[ $key ];
|
1856 |
}
|
1857 |
+
asort( $sorter );
|
1858 |
+
foreach ( $sorter as $ii => $va ) {
|
1859 |
+
$ret[ $ii ] = $array[ $ii ];
|
1860 |
}
|
1861 |
+
$array = $ret;
|
1862 |
}
|
1863 |
|
1864 |
+
\pb_backupbuddy_aasort( $recentBackups, 'start_timestamp' ); // Sort by multidimensional array with key start_timestamp.
|
1865 |
$recentBackups = array_reverse( $recentBackups ); // Reverse array order to show newest first.
|
1866 |
}
|
1867 |
|
1868 |
return $recentBackups;
|
1869 |
}
|
1870 |
|
1871 |
+
/**
|
1872 |
+
* Delete sheduled backup.
|
1873 |
+
*
|
1874 |
+
* @return array $information Return results array.
|
1875 |
+
*
|
1876 |
+
* @uses \pb_backupbuddy::$options
|
1877 |
+
* @uses \pb_backupbuddy::save()
|
1878 |
+
*/
|
1879 |
+
public function delete_scheduled_backup() {
|
1880 |
+
$schedule_ids = isset( $_POST['schedule_ids'] ) ? wp_unslash( $_POST['schedule_ids'] ) : '';
|
1881 |
+
$schedule_ids = explode( ',', $schedule_ids );
|
1882 |
|
1883 |
+
if ( empty( $schedule_ids ) ) {
|
1884 |
+
return array( 'error' => __( 'Empty schedule ids', 'mainwp-child' ) );
|
1885 |
}
|
1886 |
+
foreach ( $schedule_ids as $sch_id ) {
|
1887 |
+
if ( isset( \pb_backupbuddy::$options['schedules'][ $sch_id ] ) ) {
|
1888 |
+
unset( \pb_backupbuddy::$options['schedules'][ $sch_id ] );
|
1889 |
}
|
1890 |
}
|
1891 |
+
\pb_backupbuddy::save();
|
1892 |
$information['result'] = 'SUCCESS';
|
1893 |
return $information;
|
1894 |
}
|
1895 |
|
1896 |
+
/**
|
1897 |
+
* View log.
|
1898 |
+
*
|
1899 |
+
* @return array|string[] Return log html.
|
1900 |
+
*
|
1901 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
1902 |
+
* @uses \pb_backupbuddy::$format::date()
|
1903 |
+
* @uses \pb_backupbuddy::$format::time_ago()
|
1904 |
+
* @uses \pb_backupbuddy::flush()
|
1905 |
+
*/
|
1906 |
+
public function view_log() {
|
1907 |
+
$serial = isset( $_POST['serial'] ) ? sanitize_text_field( wp_unslash( $_POST['serial'] ) ) : '';
|
1908 |
+
$logFile = \backupbuddy_core::getLogDirectory() . 'status-' . $serial . '_sum_' . \pb_backupbuddy::$options['log_serial'] . '.txt';
|
1909 |
|
1910 |
if ( ! file_exists( $logFile ) ) {
|
1911 |
+
return array( 'error' => 'Error #858733: Log file `' . $logFile . '` not found or access denied.' );
|
1912 |
}
|
1913 |
|
1914 |
$lines = file_get_contents( $logFile );
|
1916 |
ob_start();
|
1917 |
?>
|
1918 |
|
1919 |
+
<textarea readonly="readonly" id="backupbuddy_messages" wrap="off" style="width: 100%; min-height: 400px; height: 500px; height: 80%; background: #FFF;">
|
1920 |
+
<?php
|
1921 |
+
foreach ( (array) $lines as $rawline ) {
|
1922 |
+
$line = json_decode( $rawline, true );
|
1923 |
+
if ( is_array( $line ) ) {
|
1924 |
+
$u = '';
|
1925 |
+
if ( isset( $line['u'] ) ) {
|
1926 |
+
$u = '.' . $line['u'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1927 |
}
|
1928 |
+
echo \pb_backupbuddy::$format->date( $line['time'], 'G:i:s' ) . $u . "\t\t";
|
1929 |
+
echo $line['run'] . "sec\t";
|
1930 |
+
echo $line['mem'] . "MB\t";
|
1931 |
+
echo $line['event'] . "\t";
|
1932 |
+
echo $line['data'] . "\n";
|
1933 |
+
} else {
|
1934 |
+
echo $rawline . "\n";
|
1935 |
}
|
1936 |
+
}
|
1937 |
+
?>
|
1938 |
+
</textarea><br><br>
|
1939 |
<small>Log file: <?php echo $logFile; ?></small>
|
1940 |
<br>
|
1941 |
<?php
|
1942 |
+
echo '<small>Last modified: ' . \pb_backupbuddy::$format->date( filemtime( $logFile ) ) . ' (' . \pb_backupbuddy::$format->time_ago( filemtime( $logFile ) ) . ' ago)';
|
1943 |
?>
|
1944 |
<br><br>
|
1945 |
<?php
|
1946 |
$html = ob_get_clean();
|
1947 |
+
\pb_backupbuddy::flush();
|
1948 |
+
return array(
|
1949 |
+
'result' => 'SUCCESS',
|
1950 |
+
'html_log' => $html,
|
1951 |
+
);
|
1952 |
}
|
1953 |
+
|
1954 |
+
|
1955 |
+
/**
|
1956 |
+
* Pretty results.
|
1957 |
+
*
|
1958 |
+
* @param bool $value Results TRUE|FALSE.
|
1959 |
+
*
|
1960 |
+
* @return string Return Pass or Fail message.
|
1961 |
+
*/
|
1962 |
+
function pb_pretty_results( $value ) {
|
1963 |
+
if ( true === $value ) {
|
1964 |
+
return '<span class="pb_label pb_label-success">Pass</span>';
|
1965 |
+
} else {
|
1966 |
+
return '<span class="pb_label pb_label-important">Fail</span>';
|
1967 |
+
}
|
1968 |
+
}
|
1969 |
+
|
1970 |
+
|
1971 |
+
/**
|
1972 |
+
* View details.
|
1973 |
+
*
|
1974 |
+
* @return array|string[] Return results array & echo details.
|
1975 |
+
*
|
1976 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
1977 |
+
* @uses \backupbuddy_core::getZipMeta()
|
1978 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
1979 |
+
* @uses \pb_backupbuddy_fileoptions()
|
1980 |
+
* @uses \pb_backupbuddy_fileoptions::is_ok()
|
1981 |
+
* @uses \pb_backupbuddy::$format::date()
|
1982 |
+
* @uses \pb_backupbuddy::$format::localize_time()
|
1983 |
+
* @uses \pb_backupbuddy::$ui::list_table()
|
1984 |
+
* @uses \pb_backupbuddy::load()
|
1985 |
+
* @uses \pb_backupbuddy::plugin_path()
|
1986 |
+
* @uses \pb_backupbuddy::status()
|
1987 |
+
* @uses \pb_backupbuddy::flush()
|
1988 |
+
*/
|
1989 |
+
public function view_detail() {
|
1990 |
+
|
1991 |
+
$serial = isset( $_POST['serial'] ) ? sanitize_text_field( wp_unslash( $_POST['serial'] ) ) : '';
|
1992 |
$serial = str_replace( '/\\', '', $serial );
|
1993 |
+
\pb_backupbuddy::load();
|
1994 |
|
1995 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
1996 |
+
\pb_backupbuddy::status( 'details', 'Fileoptions instance #27.' );
|
1997 |
+
$optionsFile = \backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt';
|
1998 |
+
$backup_options = new \pb_backupbuddy_fileoptions( $optionsFile, $read_only = true );
|
1999 |
+
$result = $backup_options->is_ok();
|
2000 |
+
if ( true !== $result ) {
|
2001 |
+
return array( 'error' => __( 'Unable to access fileoptions data file.', 'mainwp-child' ) . ' Error: ' . $result );
|
2002 |
}
|
2003 |
ob_start();
|
2004 |
$integrity = $backup_options->options['integrity'];
|
2005 |
|
2006 |
+
$start_time = 'Unknown';
|
2007 |
$finish_time = 'Unknown';
|
2008 |
if ( isset( $backup_options->options['start_time'] ) ) {
|
2009 |
+
$start_time = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $backup_options->options['start_time'] ) ) . ' <span class="description">(' . \pb_backupbuddy::$format->time_ago( $backup_options->options['start_time'] ) . ' ago)</span>';
|
2010 |
if ( $backup_options->options['finish_time'] > 0 ) {
|
2011 |
+
$finish_time = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $backup_options->options['finish_time'] ) ) . ' <span class="description">(' . \pb_backupbuddy::$format->time_ago( $backup_options->options['finish_time'] ) . ' ago)</span>';
|
2012 |
} else { // unfinished.
|
2013 |
$finish_time = '<i>Unfinished</i>';
|
2014 |
}
|
2015 |
}
|
2016 |
|
2017 |
+
// ***** BEGIN TESTS AND RESULTS.
|
2018 |
+
if ( isset( $integrity['status_details'] ) ) {
|
|
|
2019 |
echo '<h3>Integrity Technical Details</h3>';
|
2020 |
echo '<textarea style="width: 100%; height: 175px;" wrap="off">';
|
2021 |
+
foreach ( $integrity as $item_name => $item_value ) {
|
2022 |
$item_value = str_replace( '<br />', '<br>', $item_value );
|
2023 |
$item_value = str_replace( '<br><br>', '<br>', $item_value );
|
2024 |
$item_value = str_replace( '<br>', "\n ", $item_value );
|
2025 |
echo $item_name . ' => ' . $item_value . "\n";
|
2026 |
}
|
2027 |
echo '</textarea><br><br><b>Note:</b> It is normal to see several "file not found" entries as BackupBuddy checks for expected files in multiple locations, expecting to only find each file once in one of those locations.';
|
2028 |
+
} else {
|
2029 |
|
2030 |
echo '<br>';
|
2031 |
|
2032 |
if ( isset( $integrity['status_details'] ) ) { // PRE-v4.0 Tests.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2033 |
|
2034 |
+
|
2035 |
+
// The tests & their status.
|
2036 |
+
$tests = array();
|
2037 |
+
$tests[] = array( 'BackupBackup data file exists', $this->pb_pretty_results( $integrity['status_details']['found_dat'] ) );
|
2038 |
+
$tests[] = array( 'Database SQL file exists', $this->pb_pretty_results( $integrity['status_details']['found_sql'] ) );
|
2039 |
+
if ( 'full' == $integrity['detected_type'] ) {
|
2040 |
+
$tests[] = array( 'WordPress wp-config.php exists (full/files backups only)', $this->pb_pretty_results( $integrity['status_details']['found_wpconfig'] ) );
|
2041 |
+
} elseif ( 'files' == $integrity['detected_type'] ) {
|
2042 |
+
$tests[] = array( 'WordPress wp-config.php exists (full/files backups only)', $this->pb_pretty_results( $integrity['status_details']['found_wpconfig'] ) );
|
2043 |
} else { // DB only.
|
2044 |
$tests[] = array( 'WordPress wp-config.php exists (full/files backups only)', '<span class="pb_label pb_label-success">N/A</span>' );
|
2045 |
}
|
2046 |
} else { // 4.0+ Tests.
|
2047 |
$tests = array();
|
2048 |
if ( isset( $integrity['tests'] ) ) {
|
2049 |
+
foreach ( (array) $integrity['tests'] as $test ) {
|
2050 |
if ( true === $test['pass'] ) {
|
2051 |
$status_text = '<span class="pb_label pb_label-success">Pass</span>';
|
2052 |
} else {
|
2062 |
__( 'Status', 'mainwp-child' ),
|
2063 |
);
|
2064 |
|
2065 |
+
\pb_backupbuddy::$ui->list_table(
|
2066 |
$tests,
|
2067 |
array(
|
2068 |
+
'columns' => $columns,
|
2069 |
+
'css' => 'width: 100%; min-width: 200px;',
|
2070 |
)
|
2071 |
);
|
2072 |
|
2073 |
+
}
|
2074 |
echo '<br><br>';
|
2075 |
+
// ***** END TESTS AND RESULTS.
|
|
|
2076 |
|
2077 |
// Output meta info table (if any).
|
2078 |
$metaInfo = array();
|
2079 |
+
$metaInfo = \backupbuddy_core::getZipMeta( \backupbuddy_core::getBackupDirectory() . $integrity['file'] );
|
2080 |
+
if ( isset( $integrity['file'] ) && ( false === $metaInfo ) ) {
|
2081 |
echo '<i>No meta data found in zip comment. Skipping meta information display.</i>';
|
2082 |
} else {
|
2083 |
+
\pb_backupbuddy::$ui->list_table(
|
2084 |
$metaInfo,
|
2085 |
array(
|
2086 |
+
'columns' => array( 'Backup Details', 'Value' ),
|
2087 |
+
'css' => 'width: 100%; min-width: 200px;',
|
2088 |
)
|
2089 |
);
|
2090 |
}
|
2091 |
echo '<br><br>';
|
2092 |
|
2093 |
+
// ***** BEGIN STEPS.
|
2094 |
+
$steps = array();
|
|
|
2095 |
$steps[] = array( 'Start Time', $start_time, '' );
|
2096 |
if ( isset( $backup_options->options['steps'] ) ) {
|
2097 |
+
foreach ( $backup_options->options['steps'] as $step ) {
|
2098 |
+
if ( isset( $step['finish_time'] ) && ( 0 != $step['finish_time'] ) ) {
|
2099 |
|
2100 |
// Step name.
|
2101 |
+
if ( 'backup_create_database_dump' == $step['function'] ) {
|
2102 |
if ( count( $step['args'][0] ) == 1 ) {
|
2103 |
$step_name = 'Database dump (breakout: ' . $step['args'][0][0] . ')';
|
2104 |
} else {
|
2105 |
$step_name = 'Database dump';
|
2106 |
}
|
2107 |
+
} elseif ( 'backup_zip_files' == $step['function'] ) {
|
2108 |
if ( isset( $backup_options->options['steps']['backup_zip_files'] ) ) {
|
2109 |
$zip_time = $backup_options->options['steps']['backup_zip_files'];
|
2110 |
} else {
|
2112 |
}
|
2113 |
|
2114 |
// Calculate write speed in MB/sec for this backup.
|
2115 |
+
if ( '0' == $zip_time ) { // Took approx 0 seconds to backup so report this speed.
|
2116 |
+
$write_speed = '> ' . \pb_backupbuddy::$format->file_size( $backup_options->options['integrity']['size'] );
|
2117 |
} else {
|
2118 |
+
if ( 0 == $zip_time ) {
|
2119 |
$write_speed = '';
|
2120 |
} else {
|
2121 |
+
$write_speed = \pb_backupbuddy::$format->file_size( $backup_options->options['integrity']['size'] / $zip_time ) . '/sec';
|
2122 |
}
|
2123 |
}
|
2124 |
$step_name = 'Zip archive creation (Write speed: ' . $write_speed . ')';
|
2125 |
+
} elseif ( 'post_backup' == $step['function'] ) {
|
2126 |
$step_name = 'Post-backup cleanup';
|
2127 |
+
} elseif ( 'integrity_check' == $step['function'] ) {
|
2128 |
$step_name = 'Integrity Check';
|
2129 |
} else {
|
2130 |
$step_name = $step['function'];
|
2131 |
}
|
2132 |
|
2133 |
// Step time taken.
|
2134 |
+
$seconds = (int) ( $step['finish_time'] - $step['start_time'] );
|
2135 |
if ( $seconds < 1 ) {
|
2136 |
$step_time = '< 1 second';
|
2137 |
} else {
|
2138 |
$step_time = $seconds . ' seconds';
|
2139 |
}
|
2140 |
|
|
|
2141 |
// Compile details for this step into array.
|
2142 |
$steps[] = array(
|
2143 |
$step_name,
|
2146 |
);
|
2147 |
|
2148 |
}
|
2149 |
+
}
|
2150 |
+
} else {
|
2151 |
$step_times[] = 'unknown';
|
2152 |
+
}
|
|
|
2153 |
|
2154 |
// Total overall time from initiation to end.
|
2155 |
+
if ( isset( $backup_options->options['finish_time'] ) && isset( $backup_options->options['start_time'] ) && ( 0 != $backup_options->options['finish_time'] ) && ( 0 != $backup_options->options['start_time'] ) ) {
|
2156 |
$seconds = ( $backup_options->options['finish_time'] - $backup_options->options['start_time'] );
|
2157 |
if ( $seconds < 1 ) {
|
2158 |
$total_time = '< 1 second';
|
2178 |
if ( count( $steps ) == 0 ) {
|
2179 |
_e( 'No step statistics were found for this backup.', 'mainwp-child' );
|
2180 |
} else {
|
2181 |
+
\pb_backupbuddy::$ui->list_table(
|
2182 |
$steps,
|
2183 |
array(
|
2184 |
+
'columns' => $columns,
|
2185 |
+
'css' => 'width: 100%; min-width: 200px;',
|
2186 |
)
|
2187 |
);
|
2188 |
}
|
2189 |
echo '<br><br>';
|
2190 |
+
// ***** END STEPS.
|
2191 |
|
2192 |
if ( isset( $backup_options->options['trigger'] ) ) {
|
2193 |
$trigger = $backup_options->options['trigger'];
|
2195 |
$trigger = 'Unknown trigger';
|
2196 |
}
|
2197 |
if ( isset( $integrity['scan_time'] ) ) {
|
2198 |
+
$scanned = \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $integrity['scan_time'] ) );
|
2199 |
echo ucfirst( $trigger ) . " backup {$integrity['file']} last scanned {$scanned}.";
|
2200 |
}
|
2201 |
echo '<br><br><br>';
|
2203 |
echo '<a class="button secondary-button" onclick="jQuery(\'#pb_backupbuddy_advanced_debug\').slideToggle();">Display Advanced Debugging</a>';
|
2204 |
echo '<div id="pb_backupbuddy_advanced_debug" style="display: none;">From options file: `' . $optionsFile . '`.<br>';
|
2205 |
echo '<textarea style="width: 100%; height: 400px;" wrap="on">';
|
2206 |
+
echo print_r( $backup_options->options, true ); // phpcs:ignore -- debug feature.
|
2207 |
echo '</textarea><br><br>';
|
2208 |
echo '</div><br><br>';
|
2209 |
|
2210 |
$html = ob_get_clean();
|
2211 |
+
\pb_backupbuddy::flush();
|
2212 |
+
return array(
|
2213 |
+
'result' => 'SUCCESS',
|
2214 |
+
'html_detail' => $html,
|
2215 |
+
);
|
2216 |
}
|
2217 |
|
2218 |
+
/**
|
2219 |
+
* Reset Integrity.
|
2220 |
+
*
|
2221 |
+
* @return array $information Return results array.
|
2222 |
+
*/
|
2223 |
+
public function reset_integrity() {
|
2224 |
+
$_GET['reset_integrity'] = isset( $_POST['reset_integrity'] ) ? sanitize_text_field( wp_unslash( $_POST['reset_integrity'] ) ) : '';
|
2225 |
$information['backup_list'] = $this->get_backup_list();
|
2226 |
+
$information['result'] = 'SUCCESS';
|
2227 |
return $information;
|
2228 |
}
|
2229 |
|
2230 |
+
/**
|
2231 |
+
* Download backup archive.
|
2232 |
+
*
|
2233 |
+
* @uses \MainWP\Child\MainWP_Utility::verify_nonce_without_session()
|
2234 |
+
* @uses \pb_backupbuddy::_GET()
|
2235 |
+
* @uses \pb_backupbuddy::$option
|
2236 |
+
* @uses \backupbuddy_core::verifyAjaxAccess()
|
2237 |
+
* @uses \backupbuddy_core::backup_prefix()
|
2238 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
2239 |
+
*/
|
2240 |
+
public function download_archive() {
|
2241 |
|
2242 |
if ( ! isset( $_GET['_wpnonce'] ) || empty( $_GET['_wpnonce'] ) ) {
|
2243 |
die( '-1' );
|
2244 |
}
|
2245 |
|
2246 |
+
if ( ! MainWP_Utility::verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_backup' ) ) {
|
2247 |
die( '-2' );
|
2248 |
}
|
2249 |
|
2250 |
+
\backupbuddy_core::verifyAjaxAccess();
|
2251 |
|
2252 |
+
if ( is_multisite() && ! current_user_can( 'manage_network' ) ) { // If a Network and NOT the superadmin must make sure they can only download the specific subsite backups for security purposes.
|
2253 |
|
2254 |
+
if ( ! strstr( \pb_backupbuddy::_GET( 'backupbuddy_backup' ), \backupbuddy_core::backup_prefix() ) ) {
|
2255 |
die( 'Access Denied. You may only download backups specific to your Multisite Subsite. Only Network Admins may download backups for another subsite in the network.' );
|
2256 |
}
|
2257 |
}
|
2258 |
|
2259 |
+
if ( ! file_exists( \backupbuddy_core::getBackupDirectory() . \pb_backupbuddy::_GET( 'backupbuddy_backup' ) ) ) { // Does not exist.
|
2260 |
die( 'Error #548957857584784332. The requested backup file does not exist. It may have already been deleted.' );
|
2261 |
}
|
2262 |
|
2263 |
+
$abspath = str_replace( '\\', '/', ABSPATH );
|
2264 |
+
$backup_dir = str_replace( '\\', '/', \backupbuddy_core::getBackupDirectory() );
|
2265 |
|
2266 |
+
if ( false === stristr( $backup_dir, $abspath ) ) {
|
2267 |
die( 'Error #5432532. You cannot download backups stored outside of the WordPress web root. Please use FTP or other means.' );
|
2268 |
}
|
2269 |
|
2270 |
+
$sitepath = str_replace( $abspath, '', $backup_dir );
|
2271 |
+
$download_url = rtrim( site_url(), '/\\' ) . '/' . trim( $sitepath, '/\\' ) . '/' . \pb_backupbuddy::_GET( 'backupbuddy_backup' );
|
2272 |
|
2273 |
+
if ( '1' == \pb_backupbuddy::$options['lock_archives_directory'] ) {
|
2274 |
|
2275 |
+
if ( file_exists( \backupbuddy_core::getBackupDirectory() . '.htaccess' ) ) {
|
2276 |
+
$unlink_status = unlink( \backupbuddy_core::getBackupDirectory() . '.htaccess' );
|
2277 |
+
if ( false === $unlink_status ) {
|
2278 |
die( 'Error #844594. Unable to temporarily remove .htaccess security protection on archives directory to allow downloading. Please verify permissions of the BackupBuddy archives directory or manually download via FTP.' );
|
2279 |
}
|
2280 |
}
|
2284 |
flush();
|
2285 |
sleep( 8 );
|
2286 |
|
2287 |
+
$htaccess_creation_status = file_put_contents( \backupbuddy_core::getBackupDirectory() . '.htaccess', 'deny from all' );
|
2288 |
+
if ( false === $htaccess_creation_status ) {
|
2289 |
die( 'Error #344894545. Security Warning! Unable to create security file (.htaccess) in backups archive directory. This file prevents unauthorized downloading of backups should someone be able to guess the backup location and filenames. This is unlikely but for best security should be in place. Please verify permissions on the backups directory.' );
|
2290 |
}
|
|
|
2291 |
} else {
|
2292 |
header( 'Location: ' . $download_url );
|
2293 |
}
|
2294 |
die();
|
2295 |
}
|
2296 |
|
2297 |
+
/**
|
2298 |
+
* Create backup.
|
2299 |
+
*
|
2300 |
+
* @return array|string[] Return SUCCESS message or ERROR message.
|
2301 |
+
*
|
2302 |
+
* @uses \pb_backupbuddy::$options
|
2303 |
+
* @uses \pb_backupbuddy_backup()
|
2304 |
+
* @uses \pb_backupbuddy::plugin_path()
|
2305 |
+
* @uses \pb_backupbuddy::random_string()
|
2306 |
+
* @uses \pb_backupbuddy_backup::start_backup_process()
|
2307 |
+
*/
|
2308 |
+
public function create_backup() {
|
2309 |
+
$requested_profile = isset( $_POST['profile_id'] ) ? sanitize_text_field( wp_unslash( $_POST['profile_id'] ) ) : 0;
|
2310 |
|
2311 |
+
if ( ! isset( \pb_backupbuddy::$options['profiles'][ $requested_profile ] ) ) {
|
2312 |
+
return array( 'error' => 'Invalid Profile. Not found.' );
|
2313 |
}
|
2314 |
|
2315 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/backup.php';
|
2316 |
+
$newBackup = new \pb_backupbuddy_backup();
|
2317 |
|
2318 |
+
$profile_array = \pb_backupbuddy::$options['profiles'][ $requested_profile ];
|
2319 |
+
$serial_override = \pb_backupbuddy::random_string( 10 );
|
2320 |
|
2321 |
+
if ( true !== $newBackup->start_backup_process( $profile_array, 'manual', array(), isset( $_POST['post_backup_steps'] ) && is_array( $_POST['post_backup_steps'] ) ? wp_unslash( $_POST['post_backup_steps'] ) : array(), '', $serial_override, '', '', '' ) ) {
|
2322 |
+
return array( 'error' => __( 'Fatal Error #4344443: Backup failure. Please see any errors listed in the Status Log for details.', 'mainwp-child' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2323 |
}
|
2324 |
+
return array( 'result' => 'SUCCESS' );
|
2325 |
}
|
2326 |
|
2327 |
+
/**
|
2328 |
+
* Start backup.
|
2329 |
+
*
|
2330 |
+
* @return array|int[]|string[] Return results array containing either OK->1 OR ERROR message.
|
2331 |
+
*
|
2332 |
+
* @uses \pb_backupbuddy::plugin_path()
|
2333 |
+
* @uses \pb_backupbuddy_backup()
|
2334 |
+
* @uses \pb_backupbuddy_backup::start_backup_process()
|
2335 |
+
*/
|
2336 |
+
public function start_backup() {
|
2337 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/backup.php';
|
2338 |
+
$newBackup = new \pb_backupbuddy_backup();
|
2339 |
+
$data = isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : '';
|
2340 |
+
if ( is_array( $data ) && isset( $data['serial_override'] ) ) {
|
2341 |
if ( $newBackup->start_backup_process(
|
2342 |
+
$data['profile_array'],
|
2343 |
+
$data['trigger'],
|
2344 |
+
array(),
|
2345 |
+
isset( $data['post_backup_steps'] ) && is_array( $data['post_backup_steps'] ) ? $data['post_backup_steps'] : array(),
|
2346 |
+
'',
|
2347 |
+
$data['serial_override'],
|
2348 |
+
isset( $data['export_plugins'] ) ? $data['export_plugins'] : '',
|
2349 |
+
$data['direction'],
|
2350 |
+
isset( $data['deployDestination'] ) ? $data['deployDestination'] : ''
|
2351 |
+
) !== true ) {
|
2352 |
+
return array( 'error' => __( 'Fatal Error #4344443: Backup failure. Please see any errors listed in the Status Log for details.', 'mainwp-child' ) );
|
2353 |
}
|
2354 |
} else {
|
2355 |
+
return array( 'error' => 'Invalid backup request.' );
|
2356 |
}
|
2357 |
|
2358 |
+
return array( 'ok' => 1 );
|
|
|
2359 |
}
|
2360 |
|
2361 |
+
/**
|
2362 |
+
* Backup status.
|
2363 |
+
*
|
2364 |
+
* @return array|string[] Return results array or ERROR message on failure.
|
2365 |
+
*
|
2366 |
+
* @uses \backupbuddy_api::getBackupStatus()
|
2367 |
+
*
|
2368 |
+
*/
|
2369 |
+
public function backup_status() {
|
2370 |
+
$data = isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : '';
|
2371 |
$result = '';
|
2372 |
+
if ( is_array( $data ) && isset( $data['serial'] ) ) {
|
2373 |
ob_start();
|
2374 |
+
\backupbuddy_api::getBackupStatus( $data['serial'], $data['specialAction'], $data['initwaitretrycount'], $data['sqlFile'], $echo = true );
|
2375 |
$result = ob_get_clean();
|
2376 |
} else {
|
2377 |
+
return array( 'error' => 'Invalid backup request.' );
|
2378 |
}
|
2379 |
+
return array(
|
2380 |
+
'ok' => 1,
|
2381 |
+
'result' => $result,
|
2382 |
+
);
|
2383 |
}
|
2384 |
|
2385 |
+
/**
|
2386 |
+
* Stop Backup.
|
2387 |
+
*
|
2388 |
+
* @return int[] Return 1 on success.
|
2389 |
+
*/
|
2390 |
+
public function stop_backup() {
|
2391 |
+
$serial = isset( $_POST['serial'] ) ? wp_unslash( $_POST['serial'] ) : '';
|
2392 |
+
set_transient( 'pb_backupbuddy_stop_backup-' . $serial, true, ( 60 * 60 * 24 ) );
|
2393 |
+
return array( 'ok' => 1 );
|
2394 |
}
|
2395 |
|
2396 |
+
/**
|
2397 |
+
* Remove Save.
|
2398 |
+
*
|
2399 |
+
* @return int[]|string[] Return 1 on success or ERROR message on failure.
|
2400 |
+
*
|
2401 |
+
* @uses \pb_backupbuddy::$options
|
2402 |
+
* @uses \pb_backupbuddy::save()
|
2403 |
+
*/
|
2404 |
+
public function remote_save() {
|
2405 |
+
$data = isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : false;
|
2406 |
+
$destination_id = isset( $_POST['destination_id'] ) ? sanitize_text_field( wp_unslash( $_POST['destination_id'] ) ) : 0;
|
2407 |
+
|
2408 |
+
if ( is_array( $data ) && isset( $data['do_not_override'] ) ) {
|
2409 |
+
|
2410 |
+
if ( true == $data['do_not_override'] ) {
|
2411 |
+
if ( ( 's32' == $data['type'] || 's33' == $data['type'] ) ) {
|
2412 |
+
$not_override = array(
|
2413 |
+
'accesskey',
|
2414 |
+
'secretkey',
|
2415 |
+
'bucket',
|
2416 |
+
'region',
|
2417 |
+
);
|
2418 |
+
foreach ( $not_override as $opt ) {
|
2419 |
+
if ( isset( $data[ $opt ] ) ) {
|
2420 |
+
unset( $data[ $opt ] );
|
2421 |
+
}
|
2422 |
+
}
|
2423 |
+
}
|
2424 |
+
}
|
2425 |
|
2426 |
+
unset( $data['do_not_override'] );
|
2427 |
+
}
|
2428 |
|
2429 |
+
if ( is_array( $data ) ) {
|
2430 |
+
if ( isset( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) {
|
2431 |
+
\pb_backupbuddy::$options['remote_destinations'][ $destination_id ] = array_merge( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ], $data );
|
2432 |
+
} else {
|
2433 |
+
$data['token'] = \pb_backupbuddy::$options['dropboxtemptoken'];
|
2434 |
+
\pb_backupbuddy::$options['remote_destinations'][ $destination_id ] = $data;
|
2435 |
}
|
2436 |
+
\pb_backupbuddy::save();
|
2437 |
+
return array( 'ok' => 1 );
|
2438 |
} else {
|
2439 |
+
return array( 'error' => 'Invalid request.' );
|
2440 |
}
|
2441 |
}
|
2442 |
|
2443 |
+
/**
|
2444 |
+
* Remove backup list.
|
2445 |
+
*
|
2446 |
+
* @return array $information Return results array.
|
2447 |
+
*
|
2448 |
+
* @uses \pb_backupbuddy::$options
|
2449 |
+
*/
|
2450 |
+
public function remote_list() {
|
2451 |
$information = array();
|
2452 |
+
if ( isset( \pb_backupbuddy::$options['remote_destinations'] ) ) {
|
2453 |
+
$information['remote_destinations'] = \pb_backupbuddy::$options['remote_destinations'];
|
2454 |
}
|
2455 |
$information['result'] = 'SUCCESS';
|
2456 |
return $information;
|
2457 |
}
|
2458 |
|
2459 |
+
/**
|
2460 |
+
* Remote backup delete.
|
2461 |
+
*
|
2462 |
+
* @return array|int[]|string[] Returm OK on success or ERROR message on failure.
|
2463 |
+
*
|
2464 |
+
* @uses \pb_backupbuddy::plugin_path()
|
2465 |
+
* @uses \pb_backupbuddy_destinations::delete_destination()
|
2466 |
+
*/
|
2467 |
+
public function remote_delete() {
|
2468 |
+
$destination_id = isset( $_POST['destination_id'] ) ? sanitize_text_field( wp_unslash( $_POST['destination_id'] ) ) : null;
|
2469 |
+
if ( null !== $destination_id ) {
|
2470 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php';
|
2471 |
+
$delete_response = \pb_backupbuddy_destinations::delete_destination( $destination_id, true );
|
2472 |
+
|
2473 |
+
if ( true !== $delete_response ) {
|
2474 |
+
return array( 'error' => $delete_response );
|
2475 |
} else {
|
2476 |
+
return array( 'ok' => 1 );
|
2477 |
}
|
2478 |
} else {
|
2479 |
+
return array( 'error' => 'Invalid request.' );
|
2480 |
}
|
2481 |
}
|
2482 |
|
2483 |
+
/**
|
2484 |
+
* Remove send.
|
2485 |
+
*
|
2486 |
+
* @return array|int[]|string[] Return 1 on sucess or ERROR message on failure.
|
2487 |
+
*
|
2488 |
+
* @uses \backupbuddy_core::getBackupDirectory()
|
2489 |
+
* @uses \backupbuddy_core::status()
|
2490 |
+
* @uses \backupbuddy_core::schedule_single_event()
|
2491 |
+
* @uses \pb_backupbuddy::$options
|
2492 |
+
* @uses \pb_backupbuddy::plugin_path()
|
2493 |
+
* @uses \pb_backupbuddy_destinations::get_info()
|
2494 |
+
* @uses \pb_backupbuddy_destination_stash::get_quota()
|
2495 |
+
* @uses \pb_backupbuddy::$format::file_size()
|
2496 |
+
*/
|
2497 |
+
public function remote_send() {
|
2498 |
+
|
2499 |
+
$destination_id = isset( $_POST['destination_id'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['destination_id'] ) ) : null;
|
2500 |
+
$file = isset( $_POST['file'] ) ? wp_unslash( $_POST['file'] ) : null;
|
2501 |
+
$trigger = isset( $_POST['trigger'] ) ? wp_unslash( $_POST['trigger'] ) : 'manual';
|
2502 |
+
|
2503 |
+
if ( 'importbuddy.php' != $file ) {
|
2504 |
+
$backup_file = \backupbuddy_core::getBackupDirectory() . $file;
|
2505 |
if ( ! file_exists( $backup_file ) ) { // Error if file to send did not exist!
|
2506 |
$error_message = 'Unable to find file `' . $backup_file . '` to send. File does not appear to exist. You can try again in a moment or turn on full error logging and try again to log for support.';
|
2507 |
+
\pb_backupbuddy::status( 'error', $error_message );
|
2508 |
+
return array( 'error' => $error_message );
|
2509 |
}
|
2510 |
if ( is_dir( $backup_file ) ) { // Error if a directory is trying to be sent.
|
2511 |
$error_message = 'You are attempting to send a directory, `' . $backup_file . '`. Try again and verify there were no javascript errors.';
|
2512 |
+
\pb_backupbuddy::status( 'error', $error_message );
|
2513 |
+
return array( 'error' => $error_message );
|
2514 |
}
|
2515 |
} else {
|
2516 |
$backup_file = '';
|
2517 |
}
|
2518 |
|
2519 |
+
if ( isset( $_POST['send_importbuddy'] ) && '1' == $_POST['send_importbuddy'] ) {
|
2520 |
$send_importbuddy = true;
|
2521 |
+
\pb_backupbuddy::status( 'details', 'Cron send to be scheduled with importbuddy sending.' );
|
2522 |
} else {
|
2523 |
$send_importbuddy = false;
|
2524 |
+
\pb_backupbuddy::status( 'details', 'Cron send to be scheduled WITHOUT importbuddy sending.' );
|
2525 |
}
|
2526 |
|
2527 |
+
if ( isset( $_POST['delete_after'] ) && '1' == $_POST['delete_after'] ) {
|
2528 |
$delete_after = true;
|
2529 |
+
\pb_backupbuddy::status( 'details', 'Remote send set to delete after successful send.' );
|
2530 |
} else {
|
2531 |
$delete_after = false;
|
2532 |
+
\pb_backupbuddy::status( 'details', 'Remote send NOT set to delete after successful send.' );
|
2533 |
}
|
2534 |
|
2535 |
+
if ( ! isset( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) {
|
2536 |
return array( 'error' => 'Error #833383: Invalid destination ID `' . htmlentities( $destination_id ) . '`.' );
|
2537 |
}
|
2538 |
|
|
|
2539 |
// For Stash we will check the quota prior to initiating send.
|
2540 |
+
if ( 'stash' == \pb_backupbuddy::$options['remote_destinations'][ $destination_id ]['type'] ) {
|
2541 |
// Pass off to destination handler.
|
2542 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php';
|
2543 |
+
$send_result = \pb_backupbuddy_destinations::get_info( 'stash' ); // Used to kick the Stash destination into life.
|
2544 |
+
$stash_quota = \pb_backupbuddy_destination_stash::get_quota( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ], true );
|
2545 |
|
2546 |
if ( isset( $stash_quota['error'] ) ) {
|
2547 |
+
return array( 'error' => ' Error accessing Stash account. Send aborted. Details: `' . implode( ' - ', $stash_quota['error'] ) . '`.' );
|
2548 |
}
|
2549 |
|
2550 |
+
if ( '' != $backup_file ) {
|
2551 |
$backup_file_size = filesize( $backup_file );
|
2552 |
} else {
|
2553 |
$backup_file_size = 50000;
|
2555 |
if ( ( $backup_file_size + $stash_quota['quota_used'] ) > $stash_quota['quota_total'] ) {
|
2556 |
ob_start();
|
2557 |
echo "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage or delete files to make space.\n\n";
|
2558 |
+
echo 'Attempting to send file of size ' . \pb_backupbuddy::$format->file_size( $backup_file_size ) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. ';
|
2559 |
echo 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).';
|
2560 |
$error = ob_get_clean();
|
2561 |
return array( 'error' => $error );
|
2562 |
} else {
|
2563 |
+
if ( isset( $stash_quota['quota_warning'] ) && ( '' != $stash_quota['quota_warning'] ) ) {
|
2564 |
+
$warning = 'Warning: ' . $stash_quota['quota_warning'] . "\n\n";
|
2565 |
$success_output = true;
|
2566 |
}
|
2567 |
}
|
2568 |
+
}
|
2569 |
|
2570 |
+
\pb_backupbuddy::status( 'details', 'Scheduling cron to send to this remote destination...' );
|
|
|
|
|
2571 |
|
2572 |
+
$schedule_result = \backupbuddy_core::schedule_single_event( time(), 'remote_send', array( $destination_id, $backup_file, $trigger, $send_importbuddy, $delete_after ) );
|
2573 |
+
if ( false === $schedule_result ) {
|
2574 |
$error = 'Error scheduling file transfer. Please check your BackupBuddy error log for details. A plugin may have prevented scheduling or the database rejected it.';
|
2575 |
+
\pb_backupbuddy::status( 'error', $error );
|
2576 |
+
return array( 'error' => $error );
|
2577 |
} else {
|
2578 |
+
\pb_backupbuddy::status( 'details', 'Cron to send to remote destination scheduled.' );
|
2579 |
}
|
2580 |
+
if ( '1' != \pb_backupbuddy::$options['skip_spawn_cron_call'] ) {
|
2581 |
update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item.
|
2582 |
spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit.
|
2583 |
}
|
2584 |
+
return array( 'ok' => 1 );
|
2585 |
}
|
2586 |
|
2587 |
+
/**
|
2588 |
+
* Get main log.
|
2589 |
+
*
|
2590 |
+
* @return array Return result array or ERROR message on failure.
|
2591 |
+
*
|
2592 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
2593 |
+
* @uses \pb_backupbuddy::$options
|
2594 |
+
*/
|
2595 |
+
public function get_main_log() {
|
2596 |
+
$log_file = \backupbuddy_core::getLogDirectory() . 'log-' . \pb_backupbuddy::$options['log_serial'] . '.txt';
|
2597 |
ob_start();
|
2598 |
if ( file_exists( $log_file ) ) {
|
2599 |
readfile( $log_file );
|
2600 |
} else {
|
2601 |
+
echo __( 'Nothing has been logged.', 'mainwp-child' );
|
2602 |
}
|
2603 |
$result = ob_get_clean();
|
2604 |
+
return array( 'result' => $result );
|
2605 |
}
|
2606 |
|
2607 |
+
/**
|
2608 |
+
* Other settings.
|
2609 |
+
*
|
2610 |
+
* @return string[] Return results array.
|
2611 |
+
*
|
2612 |
+
* @uses \pb_backupbuddy::plugin_path()
|
2613 |
+
* @uses \backupbuddy_housekeeping::run_periodic()
|
2614 |
+
* @uses \backupbuddy_core::getTempDirectory()
|
2615 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
2616 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
2617 |
+
* @uses \pb_backupbuddy::$filesystem->unlink_recursive()
|
2618 |
+
* @uses \pb_backupbuddy::anti_directory_browsing()
|
2619 |
+
* @uses \pb_backupbuddy::save()
|
2620 |
+
* @uses \pb_backupbuddy_fileoptions()
|
2621 |
+
* @uses \pb_backupbuddy_fileoptions::is_ok()
|
2622 |
+
*/
|
2623 |
+
public function settings_other() {
|
2624 |
+
|
2625 |
+
$other_action = isset( $_POST['other_action'] ) ? wp_unslash( $_POST['other_action'] ) : '';
|
2626 |
|
2627 |
$message = '';
|
2628 |
+
$error = '';
|
2629 |
|
2630 |
+
if ( 'cleanup_now' == $other_action ) {
|
2631 |
$message = 'Performing cleanup procedures now trimming old files and data.';
|
2632 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/housekeeping.php';
|
2633 |
+
\backupbuddy_housekeeping::run_periodic( 0 ); // 0 cleans up everything even if not very old.
|
2634 |
+
|
2635 |
+
} elseif ( 'delete_tempfiles_now' == $other_action ) {
|
2636 |
+
$tempDir = \backupbuddy_core::getTempDirectory();
|
2637 |
+
$logDir = \backupbuddy_core::getLogDirectory();
|
2638 |
+
$message = 'Deleting all files contained within `' . $tempDir . '` and `' . $logDir . '`.';
|
2639 |
+
\pb_backupbuddy::$filesystem->unlink_recursive( $tempDir );
|
2640 |
+
\pb_backupbuddy::$filesystem->unlink_recursive( $logDir );
|
2641 |
+
\pb_backupbuddy::anti_directory_browsing( $logDir, $die = false ); // Put log dir back in place.
|
2642 |
+
} elseif ( 'reset_log' == $other_action ) {
|
2643 |
+
$log_file = \backupbuddy_core::getLogDirectory() . 'log-' . \pb_backupbuddy::$options['log_serial'] . '.txt';
|
2644 |
if ( file_exists( $log_file ) ) {
|
2645 |
+
unlink( $log_file );
|
2646 |
}
|
2647 |
if ( file_exists( $log_file ) ) { // Didnt unlink.
|
2648 |
$error = 'Unable to clear log file. Please verify permissions on file `' . $log_file . '`.';
|
2649 |
} else { // Unlinked.
|
2650 |
$message = 'Cleared log file.';
|
2651 |
}
|
2652 |
+
} elseif ( 'reset_disalerts' == $other_action ) {
|
2653 |
+
\pb_backupbuddy::$options['disalerts'] = array();
|
2654 |
+
\pb_backupbuddy::save();
|
2655 |
$message = 'Dismissed alerts have been reset. They may now be visible again.';
|
2656 |
|
2657 |
+
} elseif ( 'cancel_running_backups' == $other_action ) {
|
2658 |
+
require_once \pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
|
2659 |
|
2660 |
+
$fileoptions_directory = \backupbuddy_core::getLogDirectory() . 'fileoptions/';
|
2661 |
+
$files = glob( $fileoptions_directory . '*.txt' );
|
2662 |
if ( ! is_array( $files ) ) {
|
2663 |
$files = array();
|
2664 |
}
|
2665 |
$cancelCount = 0;
|
2666 |
+
for ( $x = 0; $x <= 3; $x++ ) { // Try this a few times since there may be race conditions on an open file.
|
2667 |
+
foreach ( $files as $file ) {
|
2668 |
+
\pb_backupbuddy::status( 'details', 'Fileoptions instance #383.' );
|
2669 |
+
|
2670 |
+
$backup_options = new \pb_backupbuddy_fileoptions( $file, $read_only = false );
|
2671 |
+
$result = $backup_options->is_ok();
|
2672 |
+
if ( true !== $result ) {
|
2673 |
+
\pb_backupbuddy::status( 'error', 'Error retrieving fileoptions file `' . $file . '`. Err 335353266.' );
|
2674 |
} else {
|
2675 |
+
if ( empty( $backup_options->options['finish_time'] ) || ( ( false !== $backup_options->options['finish_time'] ) && ( '-1' != $backup_options->options['finish_time'] ) ) ) {
|
2676 |
$backup_options->options['finish_time'] = -1; // Force marked as cancelled by user.
|
2677 |
$backup_options->save();
|
2678 |
$cancelCount++;
|
2685 |
$message = 'Marked all timed out or running backups & transfers as officially cancelled (`' . $cancelCount . '` total found).';
|
2686 |
}
|
2687 |
|
2688 |
+
return array(
|
2689 |
+
'_error' => $error,
|
2690 |
+
'_message' => $message,
|
2691 |
+
);
|
2692 |
}
|
2693 |
|
2694 |
+
/**
|
2695 |
+
* Malware scan.
|
2696 |
+
*
|
2697 |
+
* @return array $result Return result array.
|
2698 |
+
*
|
2699 |
+
* @uses \backupbuddy_core::schedule_single_event()
|
2700 |
+
* @uses \backupbuddy_core::addNotification()
|
2701 |
+
* @uses \pb_backupbuddy::$ui::start_metabox()
|
2702 |
+
* @uses \pb_backupbuddy::alert()
|
2703 |
+
*/
|
2704 |
+
public function malware_scan() {
|
2705 |
+
|
2706 |
+
\backupbuddy_core::schedule_single_event( time(), 'housekeeping', array() );
|
2707 |
update_option( '_transient_doing_cron', 0 );
|
2708 |
spawn_cron( time() + 150 );
|
2709 |
|
2713 |
$url = home_url();
|
2714 |
} else {
|
2715 |
$url = str_replace( $_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI'] );
|
2716 |
+
$url = str_replace( basename( $url ), '', $url );
|
2717 |
$url = 'http://' . $_SERVER['HTTP_HOST'] . $url;
|
2718 |
}
|
2719 |
?>
|
2728 |
|
2729 |
|
2730 |
<?php
|
2731 |
+
\pb_backupbuddy::$ui->start_metabox( __( 'Malware Scan URL', 'mainwp-child' ), true, 'width: 100%;' );
|
2732 |
|
2733 |
?>
|
2734 |
|
2737 |
<?php
|
2738 |
|
2739 |
$continue_1 = true;
|
2740 |
+
if ( 'http://localhost' == $url ) {
|
2741 |
+
_e( 'ERROR: You are currently running your site locally. Your site must be internet accessible to scan.', 'mainwp-child' );
|
2742 |
$continue_1 = false;
|
2743 |
}
|
2744 |
|
2745 |
+
if ( true === $continue_1 ) {
|
2746 |
|
2747 |
+
if ( ! empty( $_POST['refresh'] ) ) {
|
2748 |
delete_transient( 'pb_backupbuddy_malwarescan' );
|
2749 |
}
|
2750 |
|
2751 |
+
if ( ! defined( 'pluginbuddy_importbuddy' ) ) {
|
|
|
2752 |
$scan = get_transient( 'pb_backupbuddy_malwarescan' );
|
2753 |
} else {
|
2754 |
$scan = false;
|
2758 |
flush();
|
2759 |
|
2760 |
$scan = wp_remote_get(
|
2761 |
+
'http://sitecheck.sucuri.net/scanner/?scan=' . rawurlencode( $url ) . '&serialized&clear=true',
|
2762 |
array(
|
2763 |
+
'method' => 'GET',
|
2764 |
+
'timeout' => 45,
|
2765 |
'redirection' => 5,
|
2766 |
'httpversion' => '1.0',
|
2767 |
+
'blocking' => true,
|
2768 |
+
'headers' => array(),
|
2769 |
+
'body' => null,
|
2770 |
+
'cookies' => array(),
|
2771 |
)
|
2772 |
);
|
2773 |
|
2774 |
if ( is_wp_error( $scan ) ) {
|
2775 |
+
\pb_backupbuddy::alert( __( 'ERROR #24452. Unable to load Malware Scan results. Details:', 'mainwp-child' ) . ' ' . $scan->get_error_message(), true );
|
2776 |
$scan = 'N;';
|
2777 |
} else {
|
2778 |
$scan = $scan['body'];
|
2779 |
+
set_transient( 'pb_backupbuddy_malwarescan', $scan, 60 * 60 * 1 ); // 1 hour cache.
|
2780 |
}
|
|
|
2781 |
}
|
2782 |
|
2783 |
$continue_2 = true;
|
2784 |
if ( substr( $scan, 0, 2 ) == 'N;' ) {
|
2785 |
+
echo __( 'An error was encountered attempting to scan this site.', 'mainwp-child' ), '<br />';
|
2786 |
+
echo __( 'An internet connection is required and this site must be accessible on the public internet.', 'mainwp-child' );
|
2787 |
echo '<br>';
|
2788 |
+
$scan = array();
|
2789 |
$continue_2 = false;
|
2790 |
} else {
|
2791 |
$scan = maybe_unserialize( $scan );
|
|
|
|
|
|
|
2792 |
}
|
|
|
2793 |
}
|
2794 |
+
\pb_backupbuddy::$ui->end_metabox();
|
2795 |
|
2796 |
+
if ( true === $continue_2 ) {
|
|
|
|
|
|
|
2797 |
|
2798 |
+
/**
|
2799 |
+
* Turn array into html li.
|
2800 |
+
*
|
2801 |
+
* @param array $array Array of data to convert.
|
2802 |
+
*
|
2803 |
+
* @return string Return html list.
|
2804 |
+
*/
|
2805 |
function lined_array( $array ) {
|
2806 |
if ( is_array( $array ) ) {
|
2807 |
+
foreach ( $array as $array_key => $array_item ) {
|
2808 |
if ( is_array( $array_item ) ) {
|
2809 |
+
$array[ $array_key ] = lined_array( $array_item );
|
2810 |
}
|
2811 |
}
|
|
|
2812 |
$return = '';
|
2813 |
+
foreach ( $array as $array_item ) {
|
2814 |
$return .= $array_item . '<br />';
|
2815 |
}
|
2816 |
return $return;
|
2817 |
} else {
|
2818 |
if ( empty( $array ) ) {
|
2819 |
+
return '<i>' . __( 'none', 'mainwp-child' ) . '</i><br />';
|
2820 |
} else {
|
2821 |
return $array . '<br />';
|
2822 |
}
|
2823 |
}
|
2824 |
}
|
2825 |
|
2826 |
+
if ( ! empty( $scan['MALWARE'] ) && ( 'E' != $scan['MALWARE'] ) ) {
|
2827 |
+
echo '<table><tr><td><i class="fa fa-exclamation-circle fa-5x" style="color: red"></i></td><td><h1>', __( 'Warning: Possible Malware Detected!', 'mainwp-child' ), '</h1>', __( 'See details below.', 'mainwp-child' ), '</td></tr></table>';
|
2828 |
}
|
|
|
2829 |
?>
|
|
|
|
|
2830 |
<div class="postbox-container" style="width: 100%; min-width: 750px;">
|
2831 |
<div class="metabox-holder">
|
2832 |
<div class="meta-box-sortables">
|
2833 |
|
2834 |
<div id="breadcrumbslike" class="postbox">
|
2835 |
+
<div class="handlediv" title="<?php _e( 'Click to toggle', 'mainwp-child' ); ?>"><br /></div>
|
2836 |
+
<h3 class="hndle"><span><?php _e( 'Malware Detection', 'mainwp-child' ); ?></span></h3>
|
2837 |
<div class="inside">
|
2838 |
+
<label><?php _e( 'Malware', 'mainwp-child' ); ?></label>
|
2839 |
<?php
|
2840 |
+
if ( ! empty( $scan['MALWARE']['WARN'] ) ) { // Malware found.
|
2841 |
echo lined_array( $scan['MALWARE']['WARN'] );
|
2842 |
+
\backupbuddy_core::addNotification( 'malware_found', 'Malware detected on `' . $url . '`.', 'A malware scan was run on the site and detected malware.', array(), true );
|
2843 |
} else { // No malware found.
|
2844 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2845 |
+
\backupbuddy_core::addNotification( 'malware_not_found', 'No malware detected on `' . $url . '`.', 'A malware scan was run on the site and did not detect malware.' );
|
2846 |
+
}
|
2847 |
+
?>
|
2848 |
+
<br />
|
2849 |
</div>
|
2850 |
</div>
|
2851 |
|
2852 |
<div id="breadcrumbslike" class="postbox">
|
2853 |
+
<div class="handlediv" title="<?php _e( 'Click to toggle', 'mainwp-child' ); ?>"><br /></div>
|
2854 |
+
<h3 class="hndle"><span><?php _e( 'Web server details', 'mainwp-child' ); ?></span></h3>
|
2855 |
<div class="inside">
|
2856 |
+
<label><?php _e( 'Site', 'mainwp-child' ); ?></label>
|
2857 |
+
<?php
|
2858 |
+
if ( ! empty( $scan['SCAN']['SITE'] ) ) {
|
2859 |
+
echo lined_array( $scan['SCAN']['SITE'] );
|
2860 |
+
} else {
|
2861 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2862 |
+
}
|
2863 |
+
?>
|
2864 |
+
<br />
|
2865 |
+
<label><?php _e( 'Hostname', 'mainwp-child' ); ?></label>
|
2866 |
+
<?php
|
2867 |
+
if ( ! empty( $scan['SCAN']['DOMAIN'] ) ) {
|
2868 |
+
echo lined_array( $scan['SCAN']['DOMAIN'] );
|
2869 |
+
} else {
|
2870 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2871 |
+
}
|
2872 |
+
?>
|
2873 |
+
<br />
|
2874 |
+
<label><?php _e( 'IP Address', 'mainwp-child' ); ?></label>
|
2875 |
+
<?php
|
2876 |
+
if ( ! empty( $scan['SCAN']['IP'] ) ) {
|
2877 |
+
echo lined_array( $scan['SCAN']['IP'] );
|
2878 |
+
} else {
|
2879 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2880 |
+
}
|
2881 |
+
?>
|
2882 |
+
<br />
|
2883 |
+
<label><?php _e( 'System details', 'mainwp-child' ); ?></label>
|
2884 |
+
<?php
|
2885 |
+
if ( ! empty( $scan['SYSTEM']['NOTICE'] ) ) {
|
2886 |
+
echo lined_array( $scan['SYSTEM']['NOTICE'] );
|
2887 |
+
} else {
|
2888 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2889 |
+
}
|
2890 |
+
?>
|
2891 |
+
<br />
|
2892 |
+
<label><?php _e( 'Information', 'mainwp-child' ); ?></label>
|
2893 |
+
<?php
|
2894 |
+
if ( ! empty( $scan['SYSTEM']['INFO'] ) ) {
|
2895 |
+
echo lined_array( $scan['SYSTEM']['INFO'] );
|
2896 |
+
} else {
|
2897 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2898 |
+
}
|
2899 |
+
?>
|
2900 |
+
<br />
|
2901 |
</div>
|
2902 |
</div>
|
|
|
2903 |
<div id="breadcrumbslike" class="postbox">
|
2904 |
<div class="handlediv" title="Click to toggle"><br /></div>
|
2905 |
+
<h3 class="hndle"><span><?php _e( 'Web application', 'mainwp-child' ); ?></span></h3>
|
2906 |
<div class="inside">
|
2907 |
+
<label><?php _e( 'Details', 'mainwp-child' ); ?></label>
|
2908 |
+
<?php
|
2909 |
+
if ( ! empty( $scan['WEBAPP']['INFO'] ) ) {
|
2910 |
+
echo lined_array( $scan['WEBAPP']['INFO'] );
|
2911 |
+
} else {
|
2912 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2913 |
+
}
|
2914 |
+
?>
|
2915 |
+
<br />
|
2916 |
+
<label><?php _e( 'Versions', 'mainwp-child' ); ?></label>
|
2917 |
+
<?php
|
2918 |
+
if ( ! empty( $scan['WEBAPP']['VERSION'] ) ) {
|
2919 |
+
echo lined_array( $scan['WEBAPP']['VERSION'] );
|
2920 |
+
} else {
|
2921 |
+
echo '<i>',__( 'none', 'mainwp-child' ), '</i><br />';
|
2922 |
+
}
|
2923 |
+
?>
|
2924 |
+
<br />
|
2925 |
+
<label><?php _e( 'Notices', 'mainwp-child' ); ?></label>
|
2926 |
+
<?php
|
2927 |
+
if ( ! empty( $scan['WEBAPP']['NOTICE'] ) ) {
|
2928 |
+
echo lined_array( $scan['WEBAPP']['NOTICE'] );
|
2929 |
+
} else {
|
2930 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />'; }
|
2931 |
+
?>
|
2932 |
+
<br />
|
2933 |
+
<label><?php _e( 'Errors', 'mainwp-child' ); ?></label>
|
2934 |
+
<?php
|
2935 |
+
if ( ! empty( $scan['WEBAPP']['ERROR'] ) ) {
|
2936 |
+
echo lined_array( $scan['WEBAPP']['ERROR'] );
|
2937 |
+
} else {
|
2938 |
+
echo '<i>',__( 'none', 'mainwp-child' ), '</i><br />';
|
2939 |
+
}
|
2940 |
+
?>
|
2941 |
+
<br />
|
2942 |
+
<label><?php _e( 'Warnings', 'mainwp-child' ); ?></label>
|
2943 |
+
<?php
|
2944 |
+
if ( ! empty( $scan['WEBAPP']['WARN'] ) ) {
|
2945 |
+
echo lined_array( $scan['WEBAPP']['WARN'] );
|
2946 |
+
} else {
|
2947 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2948 |
+
}
|
2949 |
+
?>
|
2950 |
+
<br />
|
2951 |
</div>
|
2952 |
</div>
|
2953 |
|
2954 |
<div id="breadcrumbslike" class="postbox">
|
2955 |
+
<div class="handlediv" title="<?php _e( 'Click to toggle', 'mainwp-child' ); ?>"><br /></div>
|
2956 |
+
<h3 class="hndle"><span><?php _e( 'Links', 'mainwp-child' ); ?></span></h3>
|
2957 |
<div class="inside">
|
2958 |
+
<?php
|
2959 |
+
if ( ! empty( $scan['LINKS']['URL'] ) ) {
|
2960 |
+
echo lined_array( $scan['LINKS']['URL'] );
|
2961 |
+
} else {
|
2962 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
2963 |
+
}
|
2964 |
+
?>
|
2965 |
</div>
|
2966 |
</div>
|
2967 |
|
2968 |
<div id="breadcrumbslike" class="postbox">
|
2969 |
+
<div class="handlediv" title="<?php _e( 'Click to toggle', 'mainwp-child' ); ?>"><br /></div>
|
2970 |
+
<h3 class="hndle"><span><?php _e( 'Local Javascript', 'mainwp-child' ); ?></span></h3>
|
2971 |
<div class="inside">
|
2972 |
+
<?php
|
2973 |
+
if ( ! empty( $scan['LINKS']['JSLOCAL'] ) ) {
|
2974 |
+
echo lined_array( $scan['LINKS']['JSLOCAL'] );
|
2975 |
+
} else {
|
2976 |
+
echo '<i>', __( 'none', 'mainwp-child' ),'</i><br />';
|
2977 |
+
}
|
2978 |
+
?>
|
2979 |
</div>
|
2980 |
</div>
|
2981 |
|
2982 |
<div id="breadcrumbslike" class="postbox">
|
2983 |
+
<div class="handlediv" title="<?php _e( 'Click to toggle', 'mainwp-child' ); ?>"><br /></div>
|
2984 |
+
<h3 class="hndle"><span><?php _e( 'External Javascript', 'mainwp-child' ); ?></span></h3>
|
2985 |
<div class="inside">
|
2986 |
+
<?php
|
2987 |
+
if ( ! empty( $scan['LINKS']['JSEXTERNAL'] ) ) {
|
2988 |
+
echo lined_array( $scan['LINKS']['JSEXTERNAL'] );
|
2989 |
+
} else {
|
2990 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />'; }
|
2991 |
+
?>
|
2992 |
</div>
|
2993 |
</div>
|
2994 |
|
2995 |
<div id="breadcrumbslike" class="postbox">
|
2996 |
+
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'mainwp-child' ); ?>"><br /></div>
|
2997 |
+
<h3 class="hndle"><span><?php esc_html_e( 'Iframes Included', 'mainwp-child' ); ?></span></h3>
|
2998 |
<div class="inside">
|
2999 |
+
<?php
|
3000 |
+
if ( ! empty( $scan['LINKS']['IFRAME'] ) ) {
|
3001 |
+
echo lined_array( $scan['LINKS']['IFRAME'] );
|
3002 |
+
} else {
|
3003 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
3004 |
+
}
|
3005 |
+
?>
|
3006 |
</div>
|
3007 |
</div>
|
3008 |
|
3009 |
<div id="breadcrumbslike" class="postbox">
|
3010 |
+
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'mainwp-child' ); ?>"><br /></div>
|
3011 |
+
<h3 class="hndle"><span><?php esc_html_e( ' Blacklisting Status', 'mainwp-child' ); ?></span></h3>
|
3012 |
<div class="inside">
|
3013 |
+
<?php
|
3014 |
+
if ( ! empty( $scan['BLACKLIST']['INFO'] ) ) {
|
3015 |
+
echo lined_array( $scan['BLACKLIST']['INFO'] );
|
3016 |
+
} else {
|
3017 |
+
echo '<i>', __( 'none', 'mainwp-child' ), '</i><br />';
|
3018 |
+
}
|
3019 |
+
?>
|
3020 |
</div>
|
3021 |
</div>
|
3022 |
|
3025 |
</div>
|
3026 |
<?php
|
3027 |
|
|
|
3028 |
}
|
3029 |
$result = ob_get_clean();
|
3030 |
|
3031 |
+
return array( 'result' => $result );
|
3032 |
}
|
3033 |
|
3034 |
|
3035 |
+
/**
|
3036 |
+
* Live setup.
|
3037 |
+
*
|
3038 |
+
* @return array|array[]
|
3039 |
+
*
|
3040 |
+
* @uses iThemes_Credentials::get_password_hash()
|
3041 |
+
* @uses ITXAPI_Helper2::get_access_token()
|
3042 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3043 |
+
* @uses \pb_backupbuddy::save()
|
3044 |
+
* @uses \pb_backupbuddy::status()
|
3045 |
+
* @uses \pb_backupbuddy_destination_stash2::stashAPI()
|
3046 |
+
* @uses \pb_backupbuddy::$options
|
3047 |
+
* @uses \pb_backupbuddy_destination_live::$default_settings
|
3048 |
+
* @uses \backupbuddy_live::send_trim_settings()
|
3049 |
+
* @uses \backupbuddy_core::schedule_single_event()
|
3050 |
+
*/
|
3051 |
+
public function live_setup() {
|
3052 |
|
3053 |
$errors = array();
|
3054 |
|
3055 |
$archive_types = array(
|
3056 |
+
'db' => __( 'Database Backup', 'mainwp-child' ),
|
3057 |
+
'full' => __( 'Full Backup', 'mainwp-child' ),
|
3058 |
+
'plugins' => __( 'Plugins Backup', 'mainwp-child' ),
|
3059 |
+
'themes' => __( 'Themes Backup', 'mainwp-child' ),
|
3060 |
);
|
3061 |
|
3062 |
$archive_periods = array(
|
3066 |
'yearly',
|
3067 |
);
|
3068 |
|
|
|
3069 |
if ( ( '' == $_POST['live_username'] ) || ( '' == $_POST['live_password'] ) ) { // A field is blank.
|
3070 |
$errors[] = 'You must enter your iThemes username & password to log in to BackupBuddy Stash Live.';
|
3071 |
} else { // Username and password provided.
|
3072 |
|
3073 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/stash2/class.itx_helper2.php';
|
3074 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/stash2/init.php';
|
3075 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/init.php';
|
3076 |
+
|
3077 |
+
/** @global string $wp_version WordPress version. */
|
3078 |
global $wp_version;
|
3079 |
|
3080 |
$itxapi_username = strtolower( $_POST['live_username'] );
|
3081 |
+
$password_hash = \iThemes_Credentials::get_password_hash( $itxapi_username, $_POST['live_password'] );
|
3082 |
+
$access_token = \ITXAPI_Helper2::get_access_token( $itxapi_username, $password_hash, site_url(), $wp_version );
|
3083 |
|
3084 |
$settings = array(
|
3085 |
'itxapi_username' => $itxapi_username,
|
3086 |
'itxapi_password' => $access_token,
|
3087 |
);
|
3088 |
+
$response = \pb_backupbuddy_destination_stash2::stashAPI( $settings, 'connect' );
|
3089 |
|
3090 |
if ( ! is_array( $response ) ) { // Error message.
|
3091 |
+
$errors[] = print_r( $response, true ); // phpcs:ignore -- debug feature.
|
3092 |
} else {
|
3093 |
if ( isset( $response['error'] ) ) {
|
3094 |
$errors[] = $response['error']['message'];
|
3096 |
if ( isset( $response['token'] ) ) {
|
3097 |
$itxapi_token = $response['token'];
|
3098 |
} else {
|
3099 |
+
$errors[] = 'Error #2308832: Unexpected server response. Token missing. Check your BackupBuddy Stash Live login and try again. Detailed response: `' . print_r( $response, true ) . '`.'; // phpcs:ignore -- debug feature.
|
3100 |
}
|
3101 |
}
|
3102 |
}
|
3103 |
|
3104 |
// If we have the token then create the Live destination.
|
3105 |
if ( isset( $itxapi_token ) ) {
|
3106 |
+
if ( count( \pb_backupbuddy::$options['remote_destinations'] ) > 0 ) {
|
3107 |
+
$nextDestKey = max( array_keys( \pb_backupbuddy::$options['remote_destinations'] ) ) + 1;
|
3108 |
} else { // no destinations yet. first index.
|
3109 |
$nextDestKey = 0;
|
3110 |
}
|
3111 |
|
3112 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ] = \pb_backupbuddy_destination_live::$default_settings;
|
3113 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['itxapi_username'] = isset( $_POST['live_username'] ) ? wp_unslash( $_POST['live_username'] ) : '';
|
3114 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['itxapi_token'] = $itxapi_token;
|
3115 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['title'] = 'My BackupBuddy Stash Live';
|
3116 |
|
3117 |
// Notification email.
|
3118 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['email'] = isset( $_POST['email'] ) ? sanitize_text_field( wp_unslash( $_POST['email'] ) ) : '';
|
3119 |
|
3120 |
// Archive limits.
|
3121 |
+
foreach ( $archive_types as $archive_type => $archive_type_name ) {
|
3122 |
+
foreach ( $archive_periods as $archive_period ) {
|
3123 |
$settings_name = 'limit_' . $archive_type . '_' . $archive_period;
|
3124 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ][ $settings_name ] = isset( $_POST['live_settings'][ $settings_name ] ) ? wp_unslash( $_POST['live_settings'][ $settings_name ] ) : '';
|
3125 |
}
|
3126 |
}
|
3127 |
|
3128 |
if ( '1' == $_POST['send_snapshot_notification'] ) {
|
3129 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['send_snapshot_notification'] = isset( $_POST['send_snapshot_notification'] ) ? wp_unslash( $_POST['send_snapshot_notification'] ) : '';
|
3130 |
} else {
|
3131 |
+
\pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['send_snapshot_notification'] = '0';
|
3132 |
}
|
3133 |
|
3134 |
+
\pb_backupbuddy::save();
|
3135 |
$destination_id = $nextDestKey;
|
3136 |
|
3137 |
// Send new settings for archive limiting to Stash API.
|
3138 |
+
\backupbuddy_live::send_trim_settings();
|
|
|
|
|
3139 |
|
3140 |
// Set first run of BackupBuddy Stash Live so it begins immediately.
|
3141 |
+
$cronArgs = array();
|
3142 |
+
$schedule_result = \backupbuddy_core::schedule_single_event( time(), 'live_periodic', $cronArgs );
|
3143 |
if ( true === $schedule_result ) {
|
3144 |
+
\pb_backupbuddy::status( 'details', 'Next Live Periodic chunk step cron event scheduled.' );
|
3145 |
} else {
|
3146 |
+
\pb_backupbuddy::status( 'error', 'Next Live Periodic chunk step cron event FAILED to be scheduled.' );
|
3147 |
}
|
3148 |
+
if ( '1' != \pb_backupbuddy::$options['skip_spawn_cron_call'] ) {
|
3149 |
+
\pb_backupbuddy::status( 'details', 'Spawning cron now.' );
|
3150 |
update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item.
|
3151 |
spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit.
|
3152 |
}
|
|
|
3153 |
}
|
|
|
3154 |
} // end if user and pass set.
|
3155 |
|
|
|
3156 |
if ( 0 == count( $errors ) ) {
|
3157 |
+
\pb_backupbuddy::save();
|
3158 |
+
$data = \pb_backupbuddy::$options['remote_destinations'][ $destination_id ];
|
3159 |
+
return array(
|
3160 |
+
'destination_id' => $destination_id,
|
3161 |
+
'data' => $data,
|
3162 |
+
);
|
3163 |
} else {
|
3164 |
return array( 'errors' => $errors );
|
3165 |
}
|
|
|
3166 |
}
|
3167 |
|
3168 |
+
/**
|
3169 |
+
* Live save settings.
|
3170 |
+
*
|
3171 |
+
* @return int[]|string[] Return 1 on success or ERROR message on failure.
|
3172 |
+
*
|
3173 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3174 |
+
* @uses \pb_backupbuddy::$options
|
3175 |
+
* @uses \pb_backupbuddy::save()
|
3176 |
+
* @uses \backupbuddy_live::send_trim_settings()
|
3177 |
+
* @uses \backupbuddy_live::getLiveID()
|
3178 |
+
* @uses \backupbuddy_live::send_trim_settings()
|
3179 |
+
*/
|
3180 |
+
public function live_save_settings() {
|
3181 |
+
$data = isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : array();
|
3182 |
+
$new_destination_id = isset( $_POST['destination_id'] ) ? sanitize_text_field( wp_unslash( $_POST['destination_id'] ) ) : '';
|
3183 |
+
|
3184 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php';
|
3185 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/live.php';
|
3186 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php';
|
3187 |
+
|
3188 |
+
$destination_id = \backupbuddy_live::getLiveID();
|
3189 |
+
$destination_settings = isset( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ? \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] : array();
|
3190 |
+
|
3191 |
+
$check_current = ! empty( $destination_settings ) ? true : false;
|
3192 |
|
3193 |
$error = '';
|
3194 |
+
if ( $new_destination_id && is_array( $data ) ) {
|
3195 |
+
$itxapi_username = isset( $destination_settings['itxapi_username'] ) ? $destination_settings['itxapi_username'] : '';
|
3196 |
+
$itxapi_token = isset( $destination_settings['itxapi_token'] ) ? $destination_settings['itxapi_token'] : '';
|
3197 |
+
$destination_settings = array_merge( $destination_settings, $data );
|
3198 |
$destination_settings['itxapi_username'] = $itxapi_username;
|
3199 |
+
$destination_settings['itxapi_token'] = $itxapi_token;
|
3200 |
+
\pb_backupbuddy::$options['remote_destinations'][ $new_destination_id ] = $destination_settings;
|
3201 |
|
3202 |
+
if ( $check_current && $destination_id != $new_destination_id ) {
|
3203 |
+
unset( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] );
|
3204 |
}
|
3205 |
|
3206 |
+
\pb_backupbuddy::save();
|
3207 |
+
set_transient( 'backupbuddy_live_jump', array( 'daily_init', array() ), 60 * 60 * 48 ); // Tells Live process to restart from the beginning (if mid-process) so new settigns apply.
|
|
|
3208 |
|
3209 |
+
\backupbuddy_live::send_trim_settings();
|
3210 |
+
return array( 'ok' => 1 );
|
3211 |
} else {
|
3212 |
$error = 'Invalid data. Please check and try again.';
|
3213 |
}
|
3214 |
+
return array( 'error' => $error );
|
3215 |
}
|
3216 |
|
3217 |
+
/**
|
3218 |
+
* Live action disconnect.
|
3219 |
+
*
|
3220 |
+
* @return array $return Return 1 on success or ERROR message on failure.
|
3221 |
+
*
|
3222 |
+
* @uses \pb_backupbuddy::$options
|
3223 |
+
* @uses \pb_backupbuddy::save()
|
3224 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3225 |
+
*/
|
3226 |
+
public function live_action_disconnect() {
|
3227 |
+
$error = '';
|
3228 |
+
$liveDestinationID = isset( $_POST['destination_id'] ) ? sanitize_text_field( wp_unslash( $_POST['destination_id'] ) ) : '';
|
3229 |
|
3230 |
$return = array();
|
3231 |
+
if ( $liveDestinationID ) {
|
3232 |
+
if ( isset( \pb_backupbuddy::$options['remote_destinations'][ $liveDestinationID ] ) ) {
|
3233 |
// Clear destination settings.
|
3234 |
+
unset( \pb_backupbuddy::$options['remote_destinations'][ $liveDestinationID ] );
|
3235 |
+
\pb_backupbuddy::save();
|
3236 |
// Clear cached Live credentials.
|
3237 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/init.php';
|
3238 |
+
delete_transient( \pb_backupbuddy_destination_live::LIVE_ACTION_TRANSIENT_NAME );
|
3239 |
} else {
|
3240 |
$error = 'Error: destination not found.';
|
3241 |
}
|
3244 |
$error = 'Error: Empty destination id.';
|
3245 |
}
|
3246 |
|
3247 |
+
if ( ! empty( $error ) ) {
|
3248 |
$return['error'] = $error;
|
3249 |
+
}
|
3250 |
|
3251 |
return $return;
|
3252 |
}
|
3253 |
|
3254 |
+
/**
|
3255 |
+
* Live action.
|
3256 |
+
*
|
3257 |
+
* @return array Return results array.
|
3258 |
+
*
|
3259 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3260 |
+
* @uses \pb_backupbuddy::$options
|
3261 |
+
* @uses \pb_backupbuddy::_GET()
|
3262 |
+
* @uses \backupbuddy_live_periodic::get_stats()
|
3263 |
+
* @uses \backupbuddy_live::getLiveID()
|
3264 |
+
* @uses \backupbuddy_live_periodic::get_destination_settings()
|
3265 |
+
* @uses \backupbuddy_core::getLogDirectory()
|
3266 |
+
* @uses \backupbuddy_api::runLiveSnapshot()
|
3267 |
+
* @uses \backupbuddy_api::setLiveStatus()
|
3268 |
+
*/
|
3269 |
+
public function live_action() {
|
3270 |
+
$action = isset( $_POST['live_action'] ) ? sanitize_text_field( wp_unslash( $_POST['live_action'] ) ) : '';
|
3271 |
+
$error = '';
|
3272 |
+
$message = '';
|
3273 |
|
3274 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php';
|
3275 |
+
$state = \backupbuddy_live_periodic::get_stats();
|
3276 |
|
3277 |
+
$destination_id = \backupbuddy_live::getLiveID();
|
3278 |
+
$destination = \backupbuddy_live_periodic::get_destination_settings();
|
3279 |
|
3280 |
if ( 'clear_log' == $action ) {
|
3281 |
+
$sumLogFile = \backupbuddy_core::getLogDirectory() . 'status-live_periodic_' . \pb_backupbuddy::$options['log_serial'] . '.txt';
|
3282 |
+
unlink( $sumLogFile );
|
3283 |
if ( file_exists( $sumLogFile ) ) {
|
3284 |
+
$error = 'Error #893489322: Unable to clear log file `' . $sumLogFile . '`. Check permissions or manually delete.';
|
3285 |
} else {
|
3286 |
$message = 'Log file cleared.';
|
3287 |
}
|
3288 |
+
} elseif ( 'create_snapshot' == $action ) { // < 100% backed up _OR_ ( we are on a step other than daily_init and the last_activity is more recent than the php runtime ).
|
3289 |
+
if ( true === \backupbuddy_api::runLiveSnapshot() ) {
|
3290 |
+
$message = '<h3>' . __( 'Verifying everything is up to date before Snapshot', 'mainwp-child' ) . '</h3><p class="description" style="max-width: 700px; display: inline-block;">' . __( 'Please wait while we verify your backup is completely up to date before we create the Snapshot. This may take a few minutes...', 'mainwp-child' ) . '</p>';
|
3291 |
+
require \pb_backupbuddy::plugin_path() . '/destinations/live/_manual_snapshot.php';
|
3292 |
+
}
|
3293 |
+
} elseif ( 'pause_periodic' == $action ) {
|
3294 |
+
$pause_continuous = '';
|
3295 |
+
$pause_periodic = true;
|
3296 |
+
\backupbuddy_api::setLiveStatus( $pause_continuous, $pause_periodic );
|
3297 |
+
$destination = \pb_backupbuddy::$options['remote_destinations'][ $destination_id ]; // Update local var.
|
3298 |
+
$message = __( 'Live File Backup paused. It may take a moment for current processes to finish.', 'mainwp-child' );
|
3299 |
+
include \pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php';
|
3300 |
+
} elseif ( 'resume_periodic' == $action ) {
|
3301 |
+
$launchNowText = ' ' . __( 'Unpaused but not running now.', 'mainwp-child' );
|
3302 |
+
$start_run = false;
|
3303 |
+
if ( '1' != \pb_backupbuddy::_GET( 'skip_run_live_now' ) ) {
|
|
|
|
|
3304 |
$launchNowText = '';
|
3305 |
+
$start_run = true;
|
3306 |
+
}
|
3307 |
+
$pause_continuous = '';
|
3308 |
+
$pause_periodic = false;
|
3309 |
+
\backupbuddy_api::setLiveStatus( $pause_continuous, $pause_periodic, $start_run );
|
3310 |
+
$message = __( 'Live File Backup has resumed.', 'mainwp-child' ) . $launchNowText;
|
3311 |
+
include \pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php';
|
3312 |
+
} elseif ( 'pause_continuous' == $action ) {
|
3313 |
+
$pause_continuous = true;
|
3314 |
+
$pause_periodic = '';
|
3315 |
+
\backupbuddy_api::setLiveStatus( $pause_continuous, $pause_periodic );
|
3316 |
+
$destination = \pb_backupbuddy::$options['remote_destinations'][ $destination_id ];
|
3317 |
+
include \pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php'; // Recalculate stats.
|
3318 |
+
$message = __( 'Live Database Backup paused.', 'mainwp-child' );
|
3319 |
+
} elseif ( 'resume_continuous' == $action ) {
|
3320 |
+
$pause_continuous = false;
|
3321 |
+
$pause_periodic = '';
|
3322 |
+
\backupbuddy_api::setLiveStatus( $pause_continuous, $pause_periodic );
|
3323 |
+
$destination = \pb_backupbuddy::$options['remote_destinations'][ $destination_id ]; // Update local var.
|
3324 |
+
include \pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php'; // Recalculate stats.
|
3325 |
+
$message = __( 'Live Database Backup resumed.', 'mainwp-child' );
|
3326 |
} else {
|
3327 |
$error = 'Error #1000. Invalid request.';
|
3328 |
}
|
3329 |
|
3330 |
+
return array(
|
3331 |
+
'ok' => 1,
|
3332 |
+
'_error' => $error,
|
3333 |
+
'_message' => $message,
|
3334 |
+
);
|
3335 |
}
|
3336 |
|
3337 |
|
3338 |
+
/**
|
3339 |
+
* Download troubleshooting.
|
3340 |
+
*
|
3341 |
+
* @return array Return results array.
|
3342 |
+
*
|
3343 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3344 |
+
* @uses \backupbuddy_live_troubleshooting::run()
|
3345 |
+
* @uses \backupbuddy_live_troubleshooting::get_raw_results()
|
3346 |
+
* @uses \backupbuddy_core::backup_prefix()
|
3347 |
+
*/
|
3348 |
+
public function download_troubleshooting() {
|
3349 |
+
require \pb_backupbuddy::plugin_path() . '/destinations/live/_troubleshooting.php';
|
3350 |
+
\backupbuddy_live_troubleshooting::run();
|
3351 |
+
$output = "**File best viewed with wordwrap OFF**\n\n" . print_r( backupbuddy_live_troubleshooting::get_raw_results(), true ); // phpcs:ignore -- debug feature.
|
3352 |
+
$backup_prefix = \backupbuddy_core::backup_prefix();
|
3353 |
+
return array(
|
3354 |
+
'output' => $output,
|
3355 |
+
'backup_prefix' => $backup_prefix,
|
3356 |
+
);
|
3357 |
}
|
3358 |
|
3359 |
+
/**
|
3360 |
+
* Get live backups.
|
3361 |
+
*
|
3362 |
+
* @return array[]|string[] Return backup list.
|
3363 |
+
*
|
3364 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3365 |
+
* @uses \pb_backupbuddy::$options
|
3366 |
+
* @uses \pb_backupbuddy_destination_stash2::_formatSettings()
|
3367 |
+
* @uses \pb_backupbuddy_destination_stash2::listFiles()
|
3368 |
+
* @uses \pb_backupbuddy::$format::date()
|
3369 |
+
* @uses \pb_backupbuddy::$format::localize_time()
|
3370 |
+
* @uses \pb_backupbuddy::$format::time_ago()
|
3371 |
+
* @uses \pb_backupbuddy::$format::file_size()
|
3372 |
+
* @uses \backupbuddy_core::startsWith()
|
3373 |
+
* @uses \backupbuddy_core::getBackupTypeFromFile()
|
3374 |
+
* @uses \backupbuddy_core::pretty_backup_type()
|
3375 |
+
* @uses \backupbuddy_core::pretty_backup_type()
|
3376 |
+
*/
|
3377 |
+
public function get_live_backups() {
|
3378 |
+
$destination_id = isset( $_POST['destination_id'] ) ? sanitize_text_field( wp_unslash( $_POST['destination_id'] ) ) : '';
|
3379 |
// Load required files.
|
3380 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/s32/init.php';
|
3381 |
|
3382 |
+
if ( ! isset( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) {
|
3383 |
return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' );
|
3384 |
}
|
3385 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/stash2/init.php';
|
3386 |
+
$settings = &\pb_backupbuddy::$options['remote_destinations'][ $destination_id ];
|
3387 |
+
$settings = \pb_backupbuddy_destination_stash2::_formatSettings( $settings );
|
3388 |
|
3389 |
+
$destination = \pb_backupbuddy::$options['remote_destinations'][ $destination_id ];
|
3390 |
|
3391 |
if ( 'live' == $destination['type'] ) {
|
3392 |
+
$remotePath = 'snapshot-';
|
3393 |
+
$site_only = true;
|
3394 |
} else {
|
3395 |
// Get list of files for this site.
|
3396 |
+
$remotePath = 'backup-';
|
3397 |
+
$site_only = true;
|
3398 |
}
|
3399 |
|
3400 |
+
$files = \pb_backupbuddy_destination_stash2::listFiles( $settings, '', $site_only ); // 2nd param was $remotePath.
|
3401 |
if ( ! is_array( $files ) ) {
|
3402 |
return array( 'error' => 'Error #892329c: ' . $files );
|
3403 |
}
|
3404 |
|
3405 |
$backup_list_temp = array();
|
3406 |
+
foreach ( (array) $files as $file ) {
|
3407 |
|
3408 |
+
if ( ( '' != $remotePath ) && ( ! \backupbuddy_core::startsWith( basename( $file['filename'] ), $remotePath ) ) ) { // Only show backups for this site unless set to show all.
|
3409 |
continue;
|
3410 |
}
|
3411 |
|
3412 |
$last_modified = $file['uploaded_timestamp'];
|
3413 |
+
$size = (float) $file['size'];
|
3414 |
+
$backup_type = \backupbuddy_core::getBackupTypeFromFile( $file['filename'], $quiet = false, $skip_fileoptions = true );
|
3415 |
|
3416 |
// Generate array of table rows.
|
3417 |
+
while ( isset( $backup_list_temp[ $last_modified ] ) ) { // Avoid collisions.
|
3418 |
$last_modified += 0.1;
|
3419 |
}
|
3420 |
|
3421 |
if ( 'live' == $destination['type'] ) {
|
3422 |
+
$backup_list_temp[ $last_modified ] = array(
|
3423 |
+
array( base64_encode( $file['url'] ), '<span class="backupbuddy-stash-file-list-title">' . \pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $last_modified ) ) . ' <span class="description">(' . \pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)</span></span><br><span title="' . $file['filename'] . '">' . basename( $file['filename'] ) . '</span>' ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
3424 |
+
\pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $last_modified ) ) . '<br /><span class="description">(' . \pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)</span>',
|
3425 |
+
\pb_backupbuddy::$format->file_size( $size ),
|
3426 |
+
\backupbuddy_core::pretty_backup_type( $backup_type ),
|
3427 |
);
|
3428 |
} else {
|
3429 |
+
$backup_list_temp[ $last_modified ] = array(
|
3430 |
+
array( base64_encode( $file['url'] ), '<span title="' . $file['filename'] . '">' . basename( $file['filename'] ) . '</span>' ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- to compatible http encoding.
|
3431 |
+
\pb_backupbuddy::$format->date( \pb_backupbuddy::$format->localize_time( $last_modified ) ) . '<br /><span class="description">(' . \pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)</span>',
|
3432 |
+
\pb_backupbuddy::$format->file_size( $size ),
|
3433 |
+
\backupbuddy_core::pretty_backup_type( $backup_type ),
|
3434 |
);
|
3435 |
}
|
|
|
3436 |
}
|
3437 |
|
3438 |
krsort( $backup_list_temp );
|
3439 |
$backup_list = array();
|
3440 |
+
foreach ( $backup_list_temp as $backup_item ) {
|
3441 |
$backup_list[ $backup_item[0][0] ] = $backup_item;
|
3442 |
}
|
3443 |
unset( $backup_list_temp );
|
3445 |
return array( 'backup_list' => $backup_list );
|
3446 |
}
|
3447 |
|
3448 |
+
/**
|
3449 |
+
* Copy file to local.
|
3450 |
+
*
|
3451 |
+
* @return int[]|string[] Return 1 on success and ERROR message on failure.
|
3452 |
+
*
|
3453 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3454 |
+
* @uses \pb_backupbuddy::$options
|
3455 |
+
* @uses \pb_backupbuddy::status()
|
3456 |
+
* @uses \pb_backupbuddy_destination_stash2::_formatSettings()
|
3457 |
+
* @uses \backupbuddy_core::schedule_single_event()
|
3458 |
+
*
|
3459 |
+
*/
|
3460 |
+
public function copy_file_to_local() {
|
3461 |
+
|
3462 |
+
$file = isset( $_POST['cpy_file'] ) ? base64_decode( wp_unslash( $_POST['cpy_file'] ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
3463 |
+
$destination_id = isset( $_POST['destination_id'] ) ? sanitize_text_field( wp_unslash( $_POST['destination_id'] ) ) : '';
|
3464 |
|
3465 |
// Load required files.
|
3466 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/s32/init.php';
|
3467 |
+
if ( ! isset( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) {
|
3468 |
return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' );
|
3469 |
}
|
3470 |
|
3471 |
+
$settings = &\pb_backupbuddy::$options['remote_destinations'][ $destination_id ];
|
3472 |
+
$settings = \pb_backupbuddy_destination_stash2::_formatSettings( $settings );
|
3473 |
|
3474 |
+
\pb_backupbuddy::status( 'details', 'Scheduling Cron for creating Stash copy.' );
|
3475 |
+
\backupbuddy_core::schedule_single_event( time(), 'process_remote_copy', array( 'stash2', $file, $settings ) );
|
3476 |
+
if ( '1' != \pb_backupbuddy::$options['skip_spawn_cron_call'] ) {
|
3477 |
update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item.
|
3478 |
spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit.
|
3479 |
}
|
3480 |
return array( 'ok' => 1 );
|
|
|
3481 |
}
|
3482 |
|
3483 |
+
/**
|
3484 |
+
* Delete backup file.
|
3485 |
+
*
|
3486 |
+
* @return int[]|string[] Return 1 on success and ERROR message on failure.
|
3487 |
+
*
|
3488 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3489 |
+
* @uses \pb_backupbuddy::$options
|
3490 |
+
* @uses \pb_backupbuddy_destination_stash2::_formatSettings()
|
3491 |
+
* @uses \pb_backupbuddy_destination_stash2::strrpos_count()
|
3492 |
+
* @uses \pb_backupbuddy_destination_stash2::deleteFiles()
|
3493 |
+
*/
|
3494 |
+
public function delete_file_backup() {
|
3495 |
// Handle deletion.
|
3496 |
+
$files = isset( $_POST['items'] ) ? wp_unslash( $_POST['items'] ) : array();
|
3497 |
+
$destination_id = isset( $_POST['destination_id'] ) ? sanitize_text_field( wp_unslash( $_POST['destination_id'] ) ) : '';
|
3498 |
|
3499 |
// Load required files.
|
3500 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/s32/init.php';
|
3501 |
+
if ( ! isset( \pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) {
|
3502 |
return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' );
|
3503 |
}
|
3504 |
|
3505 |
+
$settings = &\pb_backupbuddy::$options['remote_destinations'][ $destination_id ];
|
3506 |
+
$settings = \pb_backupbuddy_destination_stash2::_formatSettings( $settings );
|
3507 |
|
3508 |
$deleteFiles = array();
|
3509 |
+
foreach ( (array) $files as $file ) {
|
3510 |
+
$file = base64_decode( $file ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
3511 |
|
3512 |
+
$startPos = \pb_backupbuddy_destination_stash2::strrpos_count( $file, '/', 2 ) + 1; // next to last slash.
|
3513 |
+
$file = substr( $file, $startPos );
|
3514 |
+
if ( false !== strstr( $file, '?' ) ) {
|
3515 |
$file = substr( $file, 0, strpos( $file, '?' ) );
|
3516 |
}
|
3517 |
$deleteFiles[] = $file;
|
3518 |
}
|
3519 |
+
$response = \pb_backupbuddy_destination_stash2::deleteFiles( $settings, $deleteFiles );
|
3520 |
|
3521 |
if ( true === $response ) {
|
3522 |
$msg = 'Deleted ' . implode( ', ', $deleteFiles ) . '.';
|
3524 |
$msg = 'Failed to delete one or more files. Details: `' . $response . '`.';
|
3525 |
}
|
3526 |
|
3527 |
+
return array(
|
3528 |
+
'ok' => 1,
|
3529 |
+
'msg' => $msg,
|
3530 |
+
);
|
3531 |
}
|
3532 |
|
3533 |
+
/**
|
3534 |
+
* Get live stats.
|
3535 |
+
*
|
3536 |
+
* @return array|string[] Return json encoded results or ERROR message on failure.
|
3537 |
+
*
|
3538 |
+
* @uses \backupbuddy_api::getLiveStats()
|
3539 |
+
* @uses \backupbuddy_core::detectLikelyHighestExecutionTime()
|
3540 |
+
* @uses \backupbuddy_core::schedule_single_event()
|
3541 |
+
* @uses \backupbuddy_live::getLiveID();
|
3542 |
+
* @uses \pb_backupbuddy::plugin_path()
|
3543 |
+
* @uses \pb_backupbuddy::$options
|
3544 |
+
* @uses \pb_backupbuddy::status()
|
3545 |
+
*/
|
3546 |
+
public function get_live_stats() {
|
3547 |
|
3548 |
// Check if running PHP 5.3+.
|
3549 |
$php_minimum = 5.3;
|
3550 |
if ( version_compare( PHP_VERSION, $php_minimum, '<' ) ) { // Server's PHP is insufficient.
|
3551 |
+
return array( 'error' => '-1' );
|
3552 |
}
|
3553 |
|
3554 |
+
$stats = \backupbuddy_api::getLiveStats();
|
3555 |
+
|
3556 |
+
if ( false === $stats ) { // Live is disconnected.
|
3557 |
+
return array( 'error' => '-1' );
|
3558 |
}
|
3559 |
|
3560 |
// If there is more to do and too long of time has passed since activity then try to jumpstart the process at the beginning.
|
3561 |
if ( ( ( 0 == $stats['files_total'] ) || ( $stats['files_sent'] < $stats['files_total'] ) ) && ( 'wait_on_transfers' != $stats['current_function'] ) ) { // ( Files to send not yet calculated OR more remain to send ) AND not on the wait_on_transfers step.
|
3562 |
$time_since_last_activity = microtime( true ) - $stats['last_periodic_activity'];
|
3563 |
|
3564 |
+
if ( $time_since_last_activity >= 30 ) { // More than 30 seconds since last activity.
|
|
|
|
|
3565 |
|
3566 |
// Detect max PHP execution time. If TESTED value is higher than PHP value then go with that since we want to err on not overlapping processes here.
|
3567 |
+
$detected_execution = \backupbuddy_core::detectLikelyHighestExecutionTime();
|
3568 |
|
3569 |
+
if ( $time_since_last_activity > ( $detected_execution + \backupbuddy_constants::TIMED_OUT_PROCESS_RESUME_WIGGLE_ROOM ) ) { // Enough time has passed to assume timed out.
|
3570 |
|
3571 |
+
require_once \pb_backupbuddy::plugin_path() . '/destinations/live/live.php';
|
3572 |
+
$liveID = \backupbuddy_live::getLiveID();
|
3573 |
+
if ( false === $liveID ) {
|
3574 |
die( '-1' );
|
3575 |
}
|
3576 |
+
if ( '1' != \pb_backupbuddy::$options['remote_destinations'][ $liveID ]['pause_periodic'] ) { // Only proceed if NOT paused.
|
3577 |
|
3578 |
+
\pb_backupbuddy::status( 'warning', 'BackupBuddy Stash Live process appears timed out while user it viewing Live page. Forcing run now.' );
|
3579 |
|
3580 |
+
$cronArgs = array();
|
3581 |
+
$schedule_result = \backupbuddy_core::schedule_single_event( time(), 'live_periodic', $cronArgs );
|
3582 |
if ( true === $schedule_result ) {
|
3583 |
+
\pb_backupbuddy::status( 'details', 'Next Live Periodic chunk step cron event scheduled.' );
|
3584 |
} else {
|
3585 |
+
\pb_backupbuddy::status( 'error', 'Next Live Periodic chunk step cron event FAILED to be scheduled.' );
|
3586 |
}
|
3587 |
+
if ( '1' != \pb_backupbuddy::$options['skip_spawn_cron_call'] ) {
|
3588 |
+
\pb_backupbuddy::status( 'details', 'Spawning cron now.' );
|
3589 |
update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item.
|
3590 |
spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit.
|
3591 |
}
|
3592 |
}
|
|
|
3593 |
}
|
3594 |
}
|
|
|
3595 |
}
|
3596 |
|
3597 |
+
return array( 'result' => wp_json_encode( $stats ) );
|
3598 |
}
|
3599 |
|
3600 |
+
/**
|
3601 |
+
* Save license settings.
|
3602 |
+
*
|
3603 |
+
* @return bool|int[] Return 1 on success and FALSE on failure.
|
3604 |
+
*/
|
3605 |
+
public function save_license_settings() {
|
3606 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : false;
|
3607 |
+
if ( is_array( $settings ) && isset( $GLOBALS['ithemes-updater-settings'] ) ) {
|
3608 |
$GLOBALS['ithemes-updater-settings']->update_options( $settings );
|
3609 |
+
return array( 'ok' => 1 );
|
3610 |
}
|
3611 |
return false;
|
3612 |
}
|
3613 |
|
3614 |
+
/**
|
3615 |
+
* Load product license.
|
3616 |
+
*
|
3617 |
+
* @return array Return results array.
|
3618 |
+
*
|
3619 |
+
* @uses Ithemes_Updater_Packages::get_full_details()
|
3620 |
+
* @uses Ithemes_Updater_Functions::get_package_name()
|
3621 |
+
*/
|
3622 |
+
public function load_products_license() {
|
3623 |
+
$packages = array();
|
3624 |
$packages_name = array();
|
3625 |
+
if ( isset( $GLOBALS['ithemes_updater_path'] ) ) {
|
3626 |
|
3627 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/functions.php';
|
3628 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/api.php';
|
3629 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/keys.php';
|
3630 |
|
3631 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/packages.php';
|
3632 |
|
3633 |
+
$details = \Ithemes_Updater_Packages::get_full_details();
|
3634 |
+
$packages = isset( $details['packages'] ) ? $details['packages'] : array();
|
3635 |
+
if ( is_array( $packages ) ) {
|
3636 |
foreach ( $packages as $path => $data ) {
|
3637 |
+
$packages_name[ $path ] = \Ithemes_Updater_Functions::get_package_name( $data['package'] );
|
3638 |
}
|
3639 |
}
|
|
|
3640 |
}
|
3641 |
+
return array(
|
3642 |
+
'ok' => 1,
|
3643 |
+
'packages' => $packages,
|
3644 |
+
'packages_name' => $packages_name,
|
3645 |
+
);
|
3646 |
}
|
3647 |
|
3648 |
+
/**
|
3649 |
+
* Activate package.
|
3650 |
+
*
|
3651 |
+
* @return array $return Return response array.
|
3652 |
+
*
|
3653 |
+
* @uses Ithemes_Updater_API::activate_package()
|
3654 |
+
* @uses Ithemes_Updater_Functions::get_package_name()
|
3655 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_error_explanation()
|
3656 |
+
*/
|
3657 |
+
public function activate_package() {
|
3658 |
+
|
3659 |
+
$username = isset( $_POST['username'] ) ? sanitize_text_field( wp_unslash( $_POST['username'] ) ) : '';
|
3660 |
+
$password = isset( $_POST['password'] ) ? wp_unslash( $_POST['password'] ) : '';
|
3661 |
+
$packages = isset( $_POST['packages'] ) ? wp_unslash( $_POST['packages'] ) : '';
|
3662 |
|
3663 |
$return = array( 'ok' => 1 );
|
3664 |
+
if ( isset( $GLOBALS['ithemes_updater_path'] ) ) {
|
3665 |
|
3666 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/functions.php';
|
3667 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/api.php';
|
3668 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/keys.php';
|
3669 |
|
3670 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/packages.php';
|
3671 |
|
3672 |
+
$response = \Ithemes_Updater_API::activate_package( $username, $password, $packages );
|
|
|
3673 |
|
3674 |
if ( is_wp_error( $response ) ) {
|
3675 |
+
$errors[] = $this->get_error_explanation( $response );
|
3676 |
$return['errors'] = $errors;
|
3677 |
return $return;
|
3678 |
}
|
3679 |
|
3680 |
if ( empty( $response['packages'] ) ) {
|
3681 |
+
$errors[] = __( 'An unknown server error occurred. Please try to license your products again at another time.', 'mainwp-child' );
|
3682 |
$return['errors'] = $errors;
|
3683 |
return $return;
|
3684 |
}
|
3686 |
uksort( $response['packages'], 'strnatcasecmp' );
|
3687 |
|
3688 |
$success = array();
|
3689 |
+
$warn = array();
|
3690 |
+
$fail = array();
|
3691 |
|
3692 |
foreach ( $response['packages'] as $package => $data ) {
|
3693 |
+
if ( preg_match( '/ \|\|\| \d+$/', $package ) ) {
|
3694 |
continue;
|
3695 |
+
}
|
3696 |
|
3697 |
+
$name = \Ithemes_Updater_Functions::get_package_name( $package );
|
3698 |
|
3699 |
+
if ( ! empty( $data['key'] ) ) {
|
3700 |
$success[] = $name;
|
3701 |
+
} elseif ( ! empty( $data['status'] ) && ( 'expired' == $data['status'] ) ) {
|
3702 |
+
$warn[ $name ] = __( 'Your product subscription has expired', 'mainwp-child' );
|
3703 |
+
} else {
|
3704 |
+
$fail[ $name ] = $data['error']['message'];
|
3705 |
+
}
|
3706 |
}
|
3707 |
|
|
|
3708 |
if ( ! empty( $success ) ) {
|
3709 |
+
$messages[] = wp_sprintf( __( 'Successfully licensed %l.', 'mainwp-child' ), $success );
|
3710 |
$return['messages'] = $messages;
|
3711 |
}
|
3712 |
|
3713 |
if ( ! empty( $fail ) ) {
|
3714 |
+
foreach ( $fail as $name => $reason ) {
|
3715 |
+
$errors[] = sprintf( __( 'Unable to license %1$s. Reason: %2$s', 'mainwp-child' ), $name, $reason );
|
3716 |
+
}
|
3717 |
$return['errors'] = $errors;
|
3718 |
}
|
3719 |
|
3720 |
if ( ! empty( $warn ) ) {
|
3721 |
+
foreach ( $warn as $name => $reason ) {
|
3722 |
+
$soft_errors[] = sprintf( __( 'Unable to license %1$s. Reason: %2$s', 'mainwp-child' ), $name, $reason );
|
3723 |
+
}
|
3724 |
$return['soft_errors'] = $soft_errors;
|
3725 |
}
|
|
|
3726 |
}
|
3727 |
return $return;
|
3728 |
}
|
3729 |
|
3730 |
+
/**
|
3731 |
+
* Deactivate package.
|
3732 |
+
*
|
3733 |
+
* @param array $data Data array.
|
3734 |
+
*
|
3735 |
+
* @return array return$ Return response array.
|
3736 |
+
*
|
3737 |
+
* @uses Ithemes_Updater_API::deactivate_package()
|
3738 |
+
* @uses Ithemes_Updater_Functions::get_package_name()
|
3739 |
+
* @uses MainWP_Child_Back_Up_Buddy::get_error_explanation()
|
3740 |
+
*/
|
3741 |
+
public function deactivate_package( $data ) {
|
3742 |
+
|
3743 |
+
$username = isset( $_POST['username'] ) ? sanitize_text_field( wp_unslash( $_POST['username'] ) ) : '';
|
3744 |
+
$password = isset( $_POST['password'] ) ? wp_unslash( $_POST['password'] ) : '';
|
3745 |
+
$packages = isset( $_POST['packages'] ) ? wp_unslash( $_POST['packages'] ) : '';
|
3746 |
|
3747 |
$return = array( 'ok' => 1 );
|
3748 |
|
3749 |
+
if ( isset( $GLOBALS['ithemes_updater_path'] ) ) {
|
3750 |
|
3751 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/functions.php';
|
3752 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/api.php';
|
3753 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/keys.php';
|
3754 |
|
3755 |
+
require_once $GLOBALS['ithemes_updater_path'] . '/packages.php';
|
3756 |
|
3757 |
+
$response = \Ithemes_Updater_API::deactivate_package( $username, $password, $packages );
|
3758 |
|
3759 |
if ( is_wp_error( $response ) ) {
|
3760 |
+
$errors[] = $this->get_error_explanation( $response );
|
3761 |
$return['errors'] = $errors;
|
3762 |
return $return;
|
3763 |
}
|
3764 |
|
3765 |
if ( empty( $response['packages'] ) ) {
|
3766 |
+
$errors[] = __( 'An unknown server error occurred. Please try to remove licenses from your products again at another time.', 'it-l10n-mainwp-backupbuddy' );
|
3767 |
$return['errors'] = $errors;
|
3768 |
return $return;
|
3769 |
}
|
3770 |
|
|
|
3771 |
uksort( $response['packages'], 'strnatcasecmp' );
|
3772 |
|
3773 |
$success = array();
|
3774 |
+
$fail = array();
|
3775 |
|
3776 |
foreach ( $response['packages'] as $package => $data ) {
|
3777 |
+
if ( preg_match( '/ \|\|\| \d+$/', $package ) ) {
|
3778 |
continue;
|
3779 |
+
}
|
3780 |
|
3781 |
+
$name = \Ithemes_Updater_Functions::get_package_name( $package );
|
3782 |
|
3783 |
+
if ( isset( $data['status'] ) && ( 'inactive' == $data['status'] ) ) {
|
3784 |
$success[] = $name;
|
3785 |
+
} elseif ( isset( $data['error'] ) && isset( $data['error']['message'] ) ) {
|
3786 |
+
$fail[ $name ] = $data['error']['message'];
|
3787 |
+
} else {
|
3788 |
+
$fail[ $name ] = __( 'Unknown server error.', 'it-l10n-mainwp-backupbuddy' );
|
3789 |
+
}
|
3790 |
}
|
3791 |
|
|
|
3792 |
if ( ! empty( $success ) ) {
|
3793 |
+
$messages[] = wp_sprintf( _n( 'Successfully removed license from %l.', 'Successfully removed licenses from %l.', count( $success ), 'it-l10n-mainwp-backupbuddy' ), $success );
|
3794 |
$return['messages'] = $messages;
|
3795 |
}
|
3796 |
|
3797 |
if ( ! empty( $fail ) ) {
|
3798 |
+
foreach ( $fail as $name => $reason ) {
|
3799 |
$errors[] = sprintf( __( 'Unable to remove license from %1$s. Reason: %2$s', 'it-l10n-mainwp-backupbuddy' ), $name, $reason );
|
3800 |
+
}
|
3801 |
$return['errors'] = $errors;
|
3802 |
|
3803 |
}
|
|
|
3804 |
}
|
3805 |
return $return;
|
3806 |
}
|
3807 |
|
3808 |
+
/**
|
3809 |
+
* Get error code.
|
3810 |
+
*
|
3811 |
+
* @param $error Returned error to get code for: Bad_Login, Username_Unknown, Username_Invalid, Package_Unknown,
|
3812 |
+
* Too_Many_Sites, Generate_Failed.
|
3813 |
+
* @param string $package Ithemes package.
|
3814 |
+
*
|
3815 |
+
* @return string $message Return ERROR message to display.
|
3816 |
+
*
|
3817 |
+
* @uses Ithemes_Updater_Functions::get_package_name()
|
3818 |
+
*/
|
3819 |
+
private function get_error_explanation( $error, $package = '' ) {
|
3820 |
+
$code = $error->get_error_code();
|
3821 |
+
$package_name = \Ithemes_Updater_Functions::get_package_name( $package );
|
3822 |
+
$message = '';
|
3823 |
+
|
3824 |
+
switch ( $code ) {
|
3825 |
case 'ITXAPI_Updater_Bad_Login':
|
3826 |
$message = __( 'Incorrect password. Please make sure that you are supplying your iThemes membership username and password details.', 'it-l10n-mainwp-backupbuddy' );
|
3827 |
break;
|
3836 |
$message = sprintf( __( '%1$s could not be licensed since the membership account is out of available licenses for this product. You can unlicense the product on other sites or upgrade your membership to one with a higher number of licenses in order to increase the amount of available licenses.', 'it-l10n-mainwp-backupbuddy' ), $package_name );
|
3837 |
break;
|
3838 |
case 'ITXAPI_License_Key_Generate_Failed':
|
3839 |
+
$message = sprintf( __( '%1$s could not be licensed due to an internal error. Please try to license %2$s again at a later time. If this problem continues, please contact iThemes support.', 'it-l10n-mainwp-backupbuddy' ), $package_name );
|
3840 |
break;
|
3841 |
}
|
3842 |
|
3843 |
if ( empty( $message ) ) {
|
3844 |
+
if ( ! empty( $package ) ) {
|
3845 |
$message = sprintf( __( 'An unknown error relating to the %1$s product occurred. Please contact iThemes support. Error details: %2$s', 'it-l10n-mainwp-backupbuddy' ), $package_name, $error->get_error_message() . " ($code)" );
|
3846 |
+
} else {
|
3847 |
$message = sprintf( __( 'An unknown error occurred. Please contact iThemes support. Error details: %s', 'it-l10n-mainwp-backupbuddy' ), $error->get_error_message() . " ($code)" );
|
3848 |
+
}
|
3849 |
}
|
3850 |
|
3851 |
return $message;
|
3854 |
|
3855 |
|
3856 |
}
|
|
class/class-mainwp-child-back-up-wordpress.php
CHANGED
@@ -1,7 +1,11 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
5 |
*
|
6 |
* Credits
|
7 |
*
|
@@ -9,66 +13,122 @@
|
|
9 |
* Plugin URI: http://bwp.hmn.md/
|
10 |
* Author: Human Made Limited
|
11 |
* Author URI: http://hmn.md/
|
12 |
-
*
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
* Extension URL: https://mainwp.com/extension/backupwordpress/
|
17 |
-
*
|
18 |
-
*/
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
public static $instance = null;
|
22 |
-
public $is_plugin_installed = false;
|
23 |
-
static function Instance() {
|
24 |
-
if ( null === MainWP_Child_Back_Up_Wordpress::$instance ) {
|
25 |
-
MainWP_Child_Back_Up_Wordpress::$instance = new MainWP_Child_Back_Up_Wordpress();
|
26 |
-
}
|
27 |
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
}
|
30 |
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
if ( is_plugin_active( 'backupwordpress/backupwordpress.php' ) ) {
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
}
|
|
|
39 |
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
public function init() {
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
if (
|
|
|
|
|
48 |
|
49 |
-
|
50 |
|
51 |
-
if ( get_option( 'mainwp_backupwordpress_hide_plugin' )
|
52 |
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
53 |
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
54 |
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
55 |
-
|
56 |
}
|
57 |
}
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
if ( isset( $_POST['mainwpsignature'] ) ) {
|
66 |
return $value;
|
67 |
}
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
if ( isset( $value->response['backupwordpress/backupwordpress.php'] ) ) {
|
73 |
unset( $value->response['backupwordpress/backupwordpress.php'] );
|
74 |
}
|
@@ -76,15 +136,39 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
76 |
return $value;
|
77 |
}
|
78 |
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
$information = array();
|
81 |
-
if ( ! self::
|
82 |
$information['error'] = 'NO_BACKUPWORDPRESS';
|
83 |
MainWP_Helper::write( $information );
|
84 |
}
|
85 |
-
|
86 |
if ( isset( $_POST['mwp_action'] ) ) {
|
87 |
-
|
|
|
88 |
case 'set_showhide':
|
89 |
$information = $this->set_showhide();
|
90 |
break;
|
@@ -124,7 +208,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
124 |
case 'exclude_remove_rule':
|
125 |
$information = $this->hmbkp_remove_exclude_rule();
|
126 |
break;
|
127 |
-
|
128 |
$information = $this->general_exclude_add_rule();
|
129 |
break;
|
130 |
}
|
@@ -132,16 +216,25 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
132 |
MainWP_Helper::write( $information );
|
133 |
}
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
if ( empty( $schedule_id ) ) {
|
139 |
$information = array( 'error' => 'Empty schedule id' );
|
140 |
MainWP_Helper::write( $information );
|
141 |
} else {
|
142 |
-
$schedule_id = sanitize_text_field(
|
143 |
-
HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
|
144 |
-
if ( ! HM\BackUpWordPress\Schedules::get_instance()->get_schedule( $schedule_id ) ) {
|
145 |
$information = array( 'result' => 'NOTFOUND' );
|
146 |
MainWP_Helper::write( $information );
|
147 |
}
|
@@ -149,38 +242,56 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
149 |
|
150 |
return $schedule_id;
|
151 |
}
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
return $information;
|
162 |
}
|
163 |
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
private function get_sync_data() {
|
166 |
-
|
167 |
-
|
168 |
|
169 |
-
HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
|
170 |
-
$schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
|
171 |
$backups_time = array();
|
172 |
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
}
|
184 |
|
185 |
$lasttime_backup = 0;
|
186 |
if ( ! empty( $backups_time ) ) {
|
@@ -192,51 +303,82 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
192 |
return $return;
|
193 |
}
|
194 |
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
241 |
MainWP_Helper::update_option( 'mainwp_backupwordpress_hide_plugin', $hide );
|
242 |
$information['result'] = 'SUCCESS';
|
@@ -244,9 +386,16 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
244 |
return $information;
|
245 |
}
|
246 |
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
$schedule_id = $this->check_schedule();
|
249 |
-
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field(
|
250 |
|
251 |
if ( $schedule ) {
|
252 |
$schedule->cancel( true );
|
@@ -258,13 +407,19 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
258 |
return $information;
|
259 |
}
|
260 |
|
261 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
$schedule_id = $this->check_schedule();
|
263 |
-
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field(
|
264 |
|
265 |
-
|
266 |
-
|
267 |
-
if (method_exists($schedule, 'get_running_backup_filename' )) {
|
268 |
if ( $schedule->get_running_backup_filename() && file_exists( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ) ) {
|
269 |
unlink( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() );
|
270 |
}
|
@@ -273,67 +428,88 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
273 |
}
|
274 |
} else {
|
275 |
$status = $schedule->get_status();
|
276 |
-
// Delete the running backup
|
277 |
-
if ( $status->get_backup_filename() && file_exists( trailingslashit( HM\BackUpWordPress\Path::get_path() ) . $status->get_backup_filename() ) ) {
|
278 |
-
unlink( trailingslashit( HM\BackUpWordPress\Path::get_path() ) . $status->get_backup_filename() );
|
279 |
}
|
280 |
if ( file_exists( $status->get_status_filepath() ) ) {
|
281 |
unlink( $status->get_status_filepath() );
|
282 |
}
|
283 |
-
|
284 |
}
|
285 |
|
286 |
-
HM\BackUpWordPress\Path::get_instance()->cleanup();
|
287 |
|
288 |
-
if ($status
|
289 |
$information['scheduleStatus'] = $schedule->get_status();
|
290 |
} else {
|
291 |
$information['scheduleStatus'] = $status->get_status();
|
292 |
}
|
293 |
|
294 |
-
$information['result']
|
295 |
|
296 |
return $information;
|
297 |
}
|
298 |
|
299 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
$schedule_id = $this->check_schedule();
|
301 |
-
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field(
|
302 |
|
303 |
-
if (method_exists($schedule, 'get_running_backup_filename' )) {
|
304 |
$information['scheduleStatus'] = $schedule->get_status();
|
305 |
} else {
|
306 |
-
$status
|
307 |
$information['scheduleStatus'] = $status->get_status();
|
308 |
}
|
309 |
|
310 |
-
$information['result']
|
311 |
|
312 |
return $information;
|
313 |
}
|
314 |
|
315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
$schedule_id = $this->check_schedule();
|
317 |
-
if (function_exists('hmbkp_run_schedule_async')) {
|
318 |
-
hmbkp_run_schedule_async($schedule_id);
|
319 |
-
}
|
320 |
-
HM\BackUpWordPress\Path::get_instance()->cleanup();
|
321 |
-
// Fixes an issue on servers which only allow a single session per client
|
322 |
session_write_close();
|
323 |
$task = new \HM\Backdrop\Task( '\HM\BackUpWordPress\run_schedule_async', $schedule_id );
|
324 |
$task->schedule();
|
325 |
-
} else
|
326 |
-
return array( 'error' => __('Error while trying to trigger the schedule', 'mainwp-child') );
|
|
|
327 |
return array( 'result' => 'SUCCESS' );
|
328 |
}
|
329 |
|
330 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
|
332 |
-
$scheduleIds = isset( $_POST['schedule_ids'] ) ? $_POST['schedule_ids'] : array();
|
333 |
-
HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
|
334 |
|
335 |
$all_schedules_ids = array();
|
336 |
-
$schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
|
337 |
foreach ( $schedules as $sch ) {
|
338 |
$all_schedules_ids[] = $sch->get_id();
|
339 |
}
|
@@ -343,23 +519,23 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
343 |
}
|
344 |
|
345 |
foreach ( $all_schedules_ids as $schedule_id ) {
|
346 |
-
if ( ! HM\BackUpWordPress\Schedules::get_instance()->get_schedule( $schedule_id ) ) {
|
347 |
continue;
|
348 |
}
|
349 |
|
350 |
-
$schedule
|
351 |
-
$started_ago = method_exists($schedule, 'get_schedule_running_start_time') ?
|
352 |
-
$out
|
353 |
'b' => $this->get_backupslist_html( $schedule ),
|
354 |
'count' => count( $schedule->get_backups() ),
|
355 |
'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ),
|
356 |
'started_ago' => human_time_diff( $started_ago ),
|
357 |
);
|
358 |
|
359 |
-
if (method_exists($schedule, 'get_running_backup_filename' )) {
|
360 |
$out['scheduleStatus'] = $schedule->get_status();
|
361 |
} else {
|
362 |
-
$status
|
363 |
$out['scheduleStatus'] = $status->get_status();
|
364 |
}
|
365 |
|
@@ -368,14 +544,14 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
368 |
|
369 |
$send_back_schedules = array();
|
370 |
|
371 |
-
$schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
|
372 |
foreach ( $schedules as $schedule ) {
|
373 |
$sch_id = $schedule->get_id();
|
374 |
if ( ! in_array( $sch_id, $scheduleIds ) ) {
|
375 |
$current_option = get_option( 'hmbkp_schedule_' . $sch_id );
|
376 |
if ( is_array( $current_option ) ) {
|
377 |
-
unset( $current_option['excludes'] );
|
378 |
-
$started_ago
|
379 |
$send_back_schedules[ $sch_id ] = array(
|
380 |
'options' => $current_option,
|
381 |
'b' => $this->get_backupslist_html( $schedule ),
|
@@ -384,20 +560,21 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
384 |
'scheduleStatus' => $schedule->get_status(),
|
385 |
'started_ago' => human_time_diff( $started_ago ),
|
386 |
);
|
387 |
-
if (method_exists($schedule, 'get_running_backup_filename' )) {
|
388 |
$send_back_schedules['scheduleStatus'] = $schedule->get_status();
|
389 |
} else {
|
390 |
-
$status
|
391 |
$send_back_schedules['scheduleStatus'] = $status->get_status();
|
392 |
}
|
393 |
}
|
394 |
}
|
395 |
}
|
396 |
|
397 |
-
if (function_exists('HM\BackUpWordPress\Backup::get_home_path'))
|
398 |
-
$backups_path = str_replace( HM\BackUpWordPress\Backup::get_home_path(), '', hmbkp_path() );
|
399 |
-
else
|
400 |
-
$backups_path = str_replace( HM\BackUpWordPress\Path::get_home_path(), '', HM\BackUpWordPress\Path::get_path() );
|
|
|
401 |
|
402 |
$information['backups_path'] = $backups_path;
|
403 |
$information['send_back_schedules'] = $send_back_schedules;
|
@@ -406,80 +583,81 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
406 |
return $information;
|
407 |
}
|
408 |
|
409 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
410 |
if ( ! isset( $_POST['hmbkp_backuparchive'] ) || empty( $_POST['hmbkp_backuparchive'] ) ) {
|
411 |
return array( 'error' => __( 'Invalid data. Please check and try again.', 'mainwp-child' ) );
|
412 |
}
|
413 |
|
414 |
$schedule_id = $this->check_schedule();
|
415 |
|
416 |
-
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field(
|
417 |
|
418 |
-
$deleted = $schedule->delete_backup(base64_decode(
|
419 |
|
420 |
if ( is_wp_error( $deleted ) ) {
|
421 |
return array( 'error' => $deleted->get_error_message() );
|
422 |
}
|
423 |
|
424 |
-
$ret =
|
425 |
'result' => 'SUCCESS',
|
426 |
'b' => $this->get_backupslist_html( $schedule ),
|
427 |
'count' => count( $schedule->get_backups() ),
|
428 |
'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ),
|
429 |
);
|
430 |
-
if (method_exists($schedule, 'get_running_backup_filename' )) {
|
431 |
$ret['scheduleStatus'] = $schedule->get_status();
|
432 |
} else {
|
433 |
-
$status
|
434 |
$ret['scheduleStatus'] = $status->get_status();
|
435 |
}
|
436 |
return $ret;
|
437 |
}
|
438 |
|
439 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
440 |
ob_start();
|
441 |
?>
|
442 |
<table class="widefat">
|
443 |
-
|
444 |
<thead>
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
<th scope="col"><?php esc_html_e( 'Actions', 'mainwp-backupwordpress-extension' ); ?></th>
|
452 |
-
|
453 |
-
</tr>
|
454 |
-
|
455 |
</thead>
|
456 |
-
|
457 |
<tbody>
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
$schedule->delete_old_backups();
|
462 |
-
|
463 |
foreach ( $schedule->get_backups() as $file ) {
|
464 |
-
|
465 |
if ( ! file_exists( $file ) ) {
|
466 |
continue;
|
467 |
}
|
468 |
-
|
469 |
$this->hmbkp_get_backup_row( $file, $schedule );
|
470 |
-
|
471 |
}
|
472 |
-
} else {
|
473 |
-
|
474 |
<tr>
|
475 |
-
<td class="hmbkp-no-backups"
|
476 |
-
colspan="4"><?php esc_html_e( 'This is where your backups will appear once you have some.', 'mainwp-backupwordpress-extension' ); ?></td>
|
477 |
</tr>
|
478 |
-
|
479 |
<?php } ?>
|
480 |
-
|
481 |
</tbody>
|
482 |
-
|
483 |
</table>
|
484 |
<?php
|
485 |
$html = ob_get_clean();
|
@@ -487,523 +665,446 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
487 |
return $html;
|
488 |
}
|
489 |
|
490 |
-
|
491 |
-
|
492 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
493 |
if ( ( 'database' === $schedule->get_type() ) || $schedule->is_site_size_cached() ) {
|
494 |
-
return sprintf( '(<code title="' . __( 'Backups will be compressed and should be smaller than this.', 'mainwp-
|
495 |
}
|
496 |
} else {
|
497 |
-
$site_size = new HM\BackUpWordPress\Site_Size( $schedule->get_type(), $schedule->get_excludes() );
|
498 |
if ( ( 'database' === $schedule->get_type() ) || $site_size->is_site_size_cached() ) {
|
499 |
-
return sprintf( '(<code title="' . __( 'Backups will be compressed and should be smaller than this.', '
|
500 |
}
|
501 |
}
|
502 |
|
503 |
-
return sprintf( '(<code class="calculating" title="' . __( 'this shouldn\'t take long…', 'mainwp-
|
504 |
-
|
505 |
}
|
506 |
|
507 |
-
|
508 |
-
|
509 |
-
|
|
|
|
|
|
|
|
|
|
|
510 |
$offset = get_option( 'gmt_offset' ) * 3600;
|
511 |
-
|
512 |
?>
|
513 |
-
|
514 |
<tr class="hmbkp_manage_backups_row">
|
515 |
-
|
516 |
<th scope="row">
|
517 |
-
<?php echo esc_html( date_i18n( get_option( 'date_format' ) . ' - ' . get_option( 'time_format' ),
|
518 |
</th>
|
519 |
-
|
520 |
<td class="code">
|
521 |
-
<?php echo esc_html( size_format(
|
522 |
</td>
|
523 |
-
|
524 |
-
<td><?php echo function_exists('hmbkp_human_get_type') ? esc_html( hmbkp_human_get_type( $file, $schedule ) ) : esc_html( HM\BackUpWordPress\human_get_type( $file, $schedule)); ?></td>
|
525 |
-
|
526 |
<td>
|
527 |
-
|
528 |
-
|
529 |
if ( hmbkp_is_path_accessible( hmbkp_path() ) ) {
|
530 |
?>
|
531 |
-
<a href="#"
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
if (HM\BackUpWordPress\is_path_accessible(HM\BackUpWordPress\Path::get_path())) {
|
537 |
?>
|
538 |
-
<a href="#"
|
539 |
-
|
540 |
-
|
541 |
-
<?php };
|
542 |
}
|
543 |
?>
|
544 |
-
|
545 |
-
<a href="#"
|
546 |
-
onclick="event.preventDefault(); mainwp_backupwp_delete_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);"
|
547 |
-
class="delete-action"><?php esc_html_e( 'Delete', 'backupwordpress' ); ?></a>
|
548 |
-
|
549 |
</td>
|
550 |
-
|
551 |
</tr>
|
|
|
|
|
552 |
|
553 |
-
|
554 |
-
|
555 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
556 |
|
557 |
$schedule_id = $this->check_schedule();
|
558 |
-
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field(
|
559 |
|
560 |
$new_version = true;
|
561 |
-
if (method_exists($schedule, 'get_running_backup_filename' )) {
|
562 |
-
$new_version
|
563 |
-
$user_excludes
|
564 |
-
$root_dir
|
565 |
$is_size_calculated = $schedule->is_site_size_being_calculated();
|
566 |
} else {
|
567 |
-
$excludes
|
568 |
-
$user_excludes
|
569 |
-
$root_dir
|
570 |
-
$is_size_calculated = HM\BackUpWordPress\Site_Size::is_site_size_being_calculated();
|
571 |
}
|
572 |
|
573 |
ob_start();
|
574 |
|
575 |
?>
|
576 |
<div class="hmbkp-exclude-settings">
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
<p><?php esc_html_e( 'We automatically detect and ignore common <abbr title="Version Control Systems">VCS</abbr> folders and other backup plugin folders.', 'backupwordpress' ); ?></p>
|
585 |
-
|
586 |
-
<table class="widefat">
|
587 |
-
|
588 |
-
<tbody>
|
589 |
-
<?php foreach ( $user_excludes as $key => $exclude ) : ?>
|
590 |
-
|
591 |
-
<?php $exclude_path = new SplFileInfo( trailingslashit( $root_dir ) . ltrim( str_ireplace( $root_dir, '', $exclude ), '/' ) ); ?>
|
592 |
-
|
593 |
-
<tr>
|
594 |
-
|
595 |
-
<th scope="row">
|
596 |
-
|
597 |
-
<?php if ( $exclude_path->isFile() ) { ?>
|
598 |
-
|
599 |
-
<div class="dashicons dashicons-media-default"></div>
|
600 |
-
|
601 |
-
<?php } elseif ( $exclude_path->isDir() ) { ?>
|
602 |
-
|
603 |
-
<div class="dashicons dashicons-portfolio"></div>
|
604 |
-
|
605 |
-
<?php } ?>
|
606 |
-
|
607 |
-
</th>
|
608 |
-
|
609 |
-
<td>
|
610 |
-
<code>
|
611 |
-
<?php echo esc_html( str_ireplace( $root_dir, '', $exclude ) ); ?>
|
612 |
-
</code>
|
613 |
-
|
614 |
-
</td>
|
615 |
-
|
616 |
-
<td>
|
617 |
-
<?php
|
618 |
-
if ($new_version)
|
619 |
-
$is_default_rule = ( in_array( $exclude, $excludes->get_default_excludes() ) ) || ( HM\BackUpWordPress\Path::get_path() === trailingslashit( HM\BackUpWordPress\Path::get_root() ) . untrailingslashit( $exclude ) );
|
620 |
-
else
|
621 |
-
$is_default_rule = ( in_array( $exclude, $schedule->backup->default_excludes() ) ) || ( hmbkp_path() === untrailingslashit( $exclude ) ) ;
|
622 |
-
|
623 |
-
if ( $is_default_rule ) : ?>
|
624 |
-
<?php esc_html_e( 'Default rule', 'backupwordpress' ); ?>
|
625 |
-
|
626 |
-
<?php elseif ( defined( 'HMBKP_EXCLUDE' ) && false !== strpos( HMBKP_EXCLUDE, $exclude ) ) : ?>
|
627 |
-
|
628 |
-
<?php esc_html_e( 'Defined in wp-config.php', 'backupwordpress' ); ?>
|
629 |
-
|
630 |
-
<?php else : ?>
|
631 |
-
|
632 |
-
<a href="#"
|
633 |
-
onclick="event.preventDefault(); mainwp_backupwp_remove_exclude_rule('<?php esc_attr_e( $exclude ); ?>', this);"
|
634 |
-
class="delete-action"><?php esc_html_e( 'Stop excluding', 'backupwordpress' ); ?></a>
|
635 |
-
|
636 |
-
<?php endif; ?>
|
637 |
-
|
638 |
-
</td>
|
639 |
-
|
640 |
-
</tr>
|
641 |
-
|
642 |
-
<?php endforeach; ?>
|
643 |
-
|
644 |
-
</tbody>
|
645 |
-
|
646 |
-
</table>
|
647 |
-
|
648 |
-
<?php //endif; ?>
|
649 |
-
|
650 |
-
<h3 id="directory-listing"><?php esc_html_e( 'Your Site', 'backupwordpress' ); ?></h3>
|
651 |
-
|
652 |
-
<p><?php esc_html_e( 'Here\'s a directory listing of all files on your site, you can browse through and exclude files or folders that you don\'t want included in your backup.', 'backupwordpress' ); ?></p>
|
653 |
-
|
654 |
<?php
|
655 |
-
// The directory to display
|
656 |
$directory = $root_dir;
|
657 |
|
658 |
if ( isset( $browse_dir ) ) {
|
659 |
|
660 |
-
$untrusted_directory =
|
661 |
|
662 |
-
// Only allow real sub directories of the site root to be browsed
|
663 |
if ( false !== strpos( $untrusted_directory, $root_dir ) && is_dir( $untrusted_directory ) ) {
|
664 |
$directory = $untrusted_directory;
|
665 |
}
|
666 |
}
|
667 |
|
668 |
-
// Kick off a recursive filesize scan
|
669 |
-
if ($new_version) {
|
670 |
-
|
671 |
-
$site_size = new HM\BackUpWordPress\Site_Size;
|
672 |
-
|
673 |
$exclude_string = implode( '|', $excludes->get_excludes_for_regex() );
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
} else {
|
679 |
-
$files
|
680 |
$exclude_string = $schedule->backup->exclude_string( 'regex' );
|
681 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
682 |
|
683 |
-
|
684 |
-
|
685 |
-
<table class="widefat">
|
686 |
-
<thead>
|
687 |
-
<tr>
|
688 |
-
<th></th>
|
689 |
-
<th scope="col"><?php esc_html_e( 'Name', 'backupwordpress' ); ?></th>
|
690 |
-
<th scope="col" class="column-format"><?php esc_html_e( 'Size', 'backupwordpress' ); ?></th>
|
691 |
-
<th scope="col"
|
692 |
-
class="column-format"><?php esc_html_e( 'Permissions', 'backupwordpress' ); ?></th>
|
693 |
-
<th scope="col" class="column-format"><?php esc_html_e( 'Type', 'backupwordpress' ); ?></th>
|
694 |
-
<th scope="col" class="column-format"><?php esc_html_e( 'Status', 'backupwordpress' ); ?></th>
|
695 |
-
</tr>
|
696 |
-
|
697 |
-
<tr>
|
698 |
-
|
699 |
-
<th scope="row">
|
700 |
-
<div class="dashicons dashicons-admin-home"></div>
|
701 |
-
</th>
|
702 |
-
|
703 |
-
<th scope="col">
|
704 |
-
|
705 |
-
<?php if ( $root_dir !== $directory ) {
|
706 |
-
// echo esc_url( remove_query_arg( 'hmbkp_directory_browse' ) );
|
707 |
-
?>
|
708 |
-
<a href="#"
|
709 |
-
onclick="event.preventDefault(); mainwp_backupwp_directory_browse('', this)"><?php echo esc_html( $root_dir ); ?></a>
|
710 |
-
<code>/</code>
|
711 |
-
|
712 |
-
<?php $parents = array_filter( explode( '/', str_replace( trailingslashit( $root_dir ), '', trailingslashit( dirname( $directory ) ) ) ) );
|
713 |
-
|
714 |
-
foreach ( $parents as $directory_basename ) { ?>
|
715 |
-
|
716 |
-
<a href="#"
|
717 |
-
onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo urlencode( substr( $directory, 0, strpos( $directory, $directory_basename ) ) . $directory_basename ); ?>', this)"><?php echo esc_html( $directory_basename ); ?></a>
|
718 |
-
<code>/</code>
|
719 |
-
|
720 |
-
<?php } ?>
|
721 |
-
|
722 |
-
<?php echo esc_html( basename( $directory ) ); ?>
|
723 |
-
|
724 |
-
<?php } else { ?>
|
725 |
-
|
726 |
-
<?php echo esc_html( $root_dir ); ?>
|
727 |
-
|
728 |
-
<?php } ?>
|
729 |
-
|
730 |
-
</th>
|
731 |
-
|
732 |
-
<td class="column-filesize">
|
733 |
-
|
734 |
-
<?php if ( $is_size_calculated ) : ?>
|
735 |
-
|
736 |
-
<span class="spinner "></span>
|
737 |
-
|
738 |
-
<?php
|
739 |
-
else :
|
740 |
-
|
741 |
-
$root = new SplFileInfo( $root_dir );
|
742 |
-
|
743 |
-
if ($new_version) {
|
744 |
-
$size = $site_size->filesize( $root );
|
745 |
-
} else {
|
746 |
-
$size = $schedule->filesize( $root, true );
|
747 |
-
}
|
748 |
-
|
749 |
-
if ( false !== $size ) {
|
750 |
-
|
751 |
-
$size = size_format( $size );
|
752 |
-
|
753 |
-
if ( ! $size ) {
|
754 |
-
$size = '0 B';
|
755 |
-
}
|
756 |
-
?>
|
757 |
-
|
758 |
-
<code>
|
759 |
-
|
760 |
-
<?php echo esc_html( $size ); ?>
|
761 |
-
|
762 |
-
<a class="dashicons dashicons-update"
|
763 |
-
href="<?php echo esc_attr( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', urlencode( $root_dir ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?>"><span><?php esc_html_e( 'Refresh', 'backupwordpress' ); ?></span></a>
|
764 |
-
|
765 |
-
</code>
|
766 |
-
|
767 |
-
|
768 |
-
<?php } ?>
|
769 |
|
770 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
771 |
|
772 |
-
|
773 |
-
|
774 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
775 |
|
776 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
777 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
778 |
<?php
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
esc_html_e( 'Folder', 'backupwordpress' );
|
783 |
-
}
|
784 |
?>
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
}
|
805 |
} else {
|
806 |
-
|
807 |
-
$is_excluded = true;
|
808 |
-
}
|
809 |
}
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
<?php if ( $is_unreadable ) { ?>
|
821 |
-
|
822 |
-
<div class="dashicons dashicons-dismiss"></div>
|
823 |
-
|
824 |
-
<?php } elseif ( $file->isFile() ) { ?>
|
825 |
-
|
826 |
-
<div class="dashicons dashicons-media-default"></div>
|
827 |
-
|
828 |
-
<?php } elseif ( $file->isDir() ) { ?>
|
829 |
-
|
830 |
-
<div class="dashicons dashicons-portfolio"></div>
|
831 |
-
|
832 |
<?php } ?>
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
}
|
876 |
-
?>
|
877 |
-
|
878 |
-
</td>
|
879 |
-
|
880 |
-
<td class="column-format column-filesize">
|
881 |
-
|
882 |
-
<?php if ( $file->isDir() && $is_size_calculated ) : ?>
|
883 |
-
|
884 |
-
<span class="spinner"></span>
|
885 |
-
|
886 |
-
<?php
|
887 |
-
else :
|
888 |
-
if ($new_version) {
|
889 |
-
$size = $site_size->filesize( $file );
|
890 |
-
} else {
|
891 |
-
$size = $schedule->filesize( $file );
|
892 |
-
}
|
893 |
-
|
894 |
-
if ( false !== $size ) {
|
895 |
-
|
896 |
-
$size = size_format( $size );
|
897 |
-
|
898 |
-
if ( ! $size ) {
|
899 |
-
$size = '0 B';
|
900 |
-
} ?>
|
901 |
-
|
902 |
-
<code>
|
903 |
-
|
904 |
-
<?php echo esc_html( $size ); ?>
|
905 |
-
|
906 |
-
<?php if ( $file->isDir() ) { ?>
|
907 |
-
|
908 |
-
<a title="<?php esc_attr_e( 'Recalculate the size of this directory', 'backupwordpress' ); ?>"
|
909 |
-
class="dashicons dashicons-update"
|
910 |
-
href="<?php echo esc_attr( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', urlencode( wp_normalize_path( $file->getPathname() ) ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?>"><span><?php esc_html_e( 'Refresh', 'backupwordpress' ); ?></span></a>
|
911 |
-
|
912 |
-
<?php } ?>
|
913 |
-
|
914 |
-
</code>
|
915 |
-
|
916 |
-
|
917 |
-
<?php } else { ?>
|
918 |
-
|
919 |
-
<code>--</code>
|
920 |
-
|
921 |
-
<?php }
|
922 |
-
endif;
|
923 |
-
?>
|
924 |
-
|
925 |
-
</td>
|
926 |
-
|
927 |
-
<td>
|
928 |
-
<?php echo esc_html( substr( sprintf( '%o', $file->getPerms() ), - 4 ) ); ?>
|
929 |
-
</td>
|
930 |
-
|
931 |
-
<td>
|
932 |
-
|
933 |
-
<?php if ( $file->isLink() ) : ?>
|
934 |
-
|
935 |
-
<span
|
936 |
-
title="<?php echo esc_attr( wp_normalize_path( $file->GetRealPath() ) ); ?>"><?php esc_html_e( 'Symlink', 'backupwordpress' ); ?></span>
|
937 |
-
|
938 |
-
<?php elseif ( $file->isDir() ) :
|
939 |
-
|
940 |
-
esc_html_e( 'Folder', 'backupwordpress' );
|
941 |
-
|
942 |
-
else :
|
943 |
-
|
944 |
-
esc_html_e( 'File', 'backupwordpress' );
|
945 |
-
|
946 |
-
endif;
|
947 |
-
?>
|
948 |
-
|
949 |
-
</td>
|
950 |
-
|
951 |
-
<td class="column-format">
|
952 |
-
|
953 |
-
<?php if ( $is_unreadable ) : ?>
|
954 |
-
|
955 |
-
<strong
|
956 |
-
title="<?php esc_attr_e( 'Unreadable files won\'t be backed up.', 'backupwordpress' ); ?>"><?php esc_html_e( 'Unreadable', 'backupwordpress' ); ?></strong>
|
957 |
-
|
958 |
-
<?php elseif ( $is_excluded ) : ?>
|
959 |
-
|
960 |
-
<strong><?php esc_html_e( 'Excluded', 'backupwordpress' ); ?></strong>
|
961 |
-
|
962 |
-
<?php
|
963 |
-
else :
|
964 |
-
|
965 |
-
$exclude_path = $file->getPathname();
|
966 |
-
|
967 |
-
// Excluded directories need to be trailingslashed
|
968 |
-
if ( $file->isDir() ) {
|
969 |
-
$exclude_path = trailingslashit( wp_normalize_path( $file->getPathname() ) );
|
970 |
-
}
|
971 |
-
|
972 |
-
?>
|
973 |
-
|
974 |
-
<a href="#"
|
975 |
-
onclick="event.preventDefault(); mainwp_backupwp_exclude_add_rule('<?php echo urlencode( $exclude_path ); ?>', this)"
|
976 |
-
class="button-secondary"><?php esc_html_e( 'Exclude →', 'backupwordpress' ); ?></a>
|
977 |
-
|
978 |
-
<?php endif; ?>
|
979 |
-
|
980 |
-
</td>
|
981 |
-
|
982 |
-
</tr>
|
983 |
-
|
984 |
-
<?php } ?>
|
985 |
-
</tbody>
|
986 |
-
</table>
|
987 |
-
|
988 |
-
<?php } ?>
|
989 |
-
|
990 |
-
<p class="submit">
|
991 |
-
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_edit_exclude_done()"
|
992 |
-
class="button-primary"><?php esc_html_e( 'Done', 'backupwordpress' ); ?></a>
|
993 |
-
</p>
|
994 |
-
|
995 |
-
</div>
|
996 |
-
|
997 |
-
<?php
|
998 |
-
$output = ob_get_clean();
|
999 |
-
$information['e'] = $output;
|
1000 |
-
|
1001 |
-
return $information;
|
1002 |
-
|
1003 |
}
|
1004 |
|
1005 |
-
|
1006 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1007 |
$out = array();
|
1008 |
$return = $this->get_excluded( $browse_dir );
|
1009 |
$out['e'] = $return['e'];
|
@@ -1012,22 +1113,29 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
1012 |
return $out;
|
1013 |
}
|
1014 |
|
1015 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1016 |
|
1017 |
if ( ! isset( $_POST['exclude_pathname'] ) || empty( $_POST['exclude_pathname'] ) ) {
|
1018 |
-
return array( 'error' => __( '
|
1019 |
}
|
1020 |
|
1021 |
$schedule_id = $this->check_schedule();
|
1022 |
-
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $schedule_id ) );
|
1023 |
|
1024 |
-
$exclude_rule =
|
1025 |
|
1026 |
$schedule->set_excludes( $exclude_rule, true );
|
1027 |
|
1028 |
$schedule->save();
|
1029 |
|
1030 |
-
$current_path =
|
1031 |
|
1032 |
if ( empty( $current_path ) ) {
|
1033 |
$current_path = null;
|
@@ -1035,32 +1143,39 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
1035 |
|
1036 |
$return = $this->get_excluded( $current_path );
|
1037 |
$out['e'] = $return['e'];
|
1038 |
-
$out['current_browse_dir'] = $_POST['browse_dir'];
|
1039 |
|
1040 |
return $out;
|
1041 |
-
|
1042 |
}
|
1043 |
|
1044 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1045 |
|
1046 |
if ( ! isset( $_POST['remove_rule'] ) || empty( $_POST['remove_rule'] ) ) {
|
1047 |
-
return array( 'error' => __( '
|
1048 |
}
|
1049 |
|
1050 |
$schedule_id = $this->check_schedule();
|
1051 |
-
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $schedule_id ) );
|
1052 |
|
1053 |
-
$excludes
|
1054 |
-
$exclude_rule_to_remove = stripslashes( sanitize_text_field( $_POST['remove_rule'] ) );
|
1055 |
|
1056 |
-
if (method_exists($excludes, 'get_user_excludes')) {
|
1057 |
$schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) );
|
1058 |
-
} else
|
1059 |
$schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) );
|
|
|
1060 |
|
1061 |
$schedule->save();
|
1062 |
|
1063 |
-
$current_path =
|
1064 |
|
1065 |
if ( empty( $current_path ) ) {
|
1066 |
$current_path = null;
|
@@ -1069,79 +1184,83 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
1069 |
$return = $this->get_excluded( $current_path );
|
1070 |
|
1071 |
$out['e'] = $return['e'];
|
1072 |
-
$out['current_browse_dir'] = $_POST['browse_dir'];
|
1073 |
|
1074 |
return $out;
|
1075 |
}
|
1076 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1077 |
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
foreach ( $exclude_paths as $excl_rule ) {
|
1087 |
-
$excl_rule = trim($excl_rule);
|
1088 |
-
$excl_rule = trim($excl_rule, '/');
|
1089 |
-
|
1090 |
-
if (empty($excl_rule))
|
1091 |
-
continue;
|
1092 |
-
|
1093 |
-
$exclude_rule = ABSPATH . $excl_rule;
|
1094 |
-
$path = realpath($exclude_rule);
|
1095 |
-
// If it exist
|
1096 |
-
if($path !== false)
|
1097 |
-
{
|
1098 |
-
$schedule->set_excludes( $exclude_rule, true );
|
1099 |
-
$schedule->save();
|
1100 |
-
}
|
1101 |
-
}
|
1102 |
-
}
|
1103 |
-
|
1104 |
-
|
1105 |
-
$un_exclude_paths = urldecode( $_POST['un_exclude_paths'] );
|
1106 |
-
$un_exclude_paths = explode("\n", $un_exclude_paths);
|
1107 |
|
1108 |
-
|
1109 |
-
|
1110 |
-
$exclude_rule_to_remove = trim($exclude_rule_to_remove);
|
1111 |
-
$exclude_rule_to_remove = trim($exclude_rule_to_remove, '/');
|
1112 |
|
1113 |
-
|
1114 |
-
|
|
|
|
|
1115 |
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
} else {
|
1120 |
-
$schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) );
|
1121 |
-
}
|
1122 |
-
$schedule->save();
|
1123 |
-
}
|
1124 |
-
}
|
1125 |
|
1126 |
-
|
1127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1128 |
|
|
|
|
|
1129 |
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1134 |
|
1135 |
if ( ! is_array( $options ) || empty( $options ) || empty( $sch_id ) ) {
|
1136 |
-
return array( 'error' => '
|
1137 |
}
|
1138 |
|
1139 |
-
// $current_value = get_option( 'hmbkp_schedule_' . $sch_id );
|
1140 |
-
// if ( is_array( $current_value ) && isset( $current_value['excludes'] ) ) {
|
1141 |
-
// // do not update 'excludes' value
|
1142 |
-
// $options['excludes'] = $current_value['excludes'];
|
1143 |
-
// }
|
1144 |
-
|
1145 |
$filter_opts = array(
|
1146 |
'type',
|
1147 |
'email',
|
@@ -1162,16 +1281,16 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
1162 |
}
|
1163 |
|
1164 |
update_option( 'hmbkp_schedule_' . $sch_id, $options );
|
1165 |
-
|
1166 |
$out['result'] = 'SUCCESS';
|
1167 |
} else {
|
1168 |
$out['result'] = 'NOTCHANGE';
|
1169 |
}
|
1170 |
|
1171 |
-
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) );
|
1172 |
|
1173 |
if ( ! empty( $options['reoccurrence'] ) && ! empty( $options['schedule_start_time'] ) ) {
|
1174 |
-
// Calculate the start time depending on the recurrence
|
1175 |
$start_time = $options['schedule_start_time'];
|
1176 |
if ( $start_time ) {
|
1177 |
$schedule->set_schedule_start_time( $start_time );
|
@@ -1186,18 +1305,26 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
1186 |
return $out;
|
1187 |
}
|
1188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1189 |
public function save_all_schedules() {
|
1190 |
-
$schedules = isset( $_POST['all_schedules'] ) ? maybe_unserialize( base64_decode( $_POST['all_schedules'] ) ) : false;
|
1191 |
|
1192 |
if ( ! is_array( $schedules ) || empty( $schedules ) ) {
|
1193 |
-
return array( 'error' => '
|
1194 |
}
|
1195 |
|
1196 |
$out = array();
|
1197 |
-
foreach($schedules as $sch_id => $sch) {
|
1198 |
-
if ( empty($sch_id) || !isset( $sch['options'] ) || ! is_array( $sch['options'] ) )
|
1199 |
continue;
|
1200 |
-
|
|
|
1201 |
$filter_opts = array(
|
1202 |
'type',
|
1203 |
'email',
|
@@ -1217,10 +1344,10 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
1217 |
update_option( 'hmbkp_schedule_' . $sch_id, $options );
|
1218 |
}
|
1219 |
|
1220 |
-
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) );
|
1221 |
|
1222 |
if ( ! empty( $options['reoccurrence'] ) && ! empty( $options['schedule_start_time'] ) ) {
|
1223 |
-
// Calculate the start time depending on the recurrence
|
1224 |
$start_time = $options['schedule_start_time'];
|
1225 |
if ( $start_time ) {
|
1226 |
$schedule->set_schedule_start_time( $start_time );
|
@@ -1232,19 +1359,30 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
1232 |
}
|
1233 |
$out['result'] = 'SUCCESS';
|
1234 |
}
|
1235 |
-
|
1236 |
return $out;
|
1237 |
}
|
1238 |
|
1239 |
-
|
1240 |
-
|
|
|
|
|
|
|
|
|
|
|
1241 |
return false;
|
1242 |
}
|
1243 |
|
1244 |
return true;
|
1245 |
}
|
1246 |
|
1247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1248 |
public function all_plugins( $plugins ) {
|
1249 |
foreach ( $plugins as $key => $value ) {
|
1250 |
$plugin_slug = basename( $key, '.php' );
|
@@ -1256,8 +1394,24 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
1256 |
return $plugins;
|
1257 |
}
|
1258 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1259 |
public function remove_menu() {
|
|
|
|
|
|
|
|
|
|
|
|
|
1260 |
global $submenu;
|
|
|
1261 |
if ( isset( $submenu['tools.php'] ) ) {
|
1262 |
foreach ( $submenu['tools.php'] as $index => $item ) {
|
1263 |
if ( 'backupwordpress' === $item[2] ) {
|
@@ -1267,11 +1421,10 @@ class MainWP_Child_Back_Up_Wordpress {
|
|
1267 |
}
|
1268 |
}
|
1269 |
|
1270 |
-
$pos = stripos( $_SERVER['REQUEST_URI'], 'tools.php?page=backupwordpress' );
|
1271 |
if ( false !== $pos ) {
|
1272 |
-
|
1273 |
exit();
|
1274 |
}
|
1275 |
}
|
1276 |
}
|
1277 |
-
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* MainWP BackUpWordPress
|
4 |
+
*
|
5 |
+
* MainWP BackUpWordPress Extension handler.
|
6 |
+
* Extension URL: https://mainwp.com/extension/backupwordpress/
|
7 |
+
*
|
8 |
+
* @package MainWP\Child
|
9 |
*
|
10 |
* Credits
|
11 |
*
|
13 |
* Plugin URI: http://bwp.hmn.md/
|
14 |
* Author: Human Made Limited
|
15 |
* Author URI: http://hmn.md/
|
16 |
+
* Licence: GPL-2+
|
17 |
+
*/
|
18 |
+
|
19 |
+
namespace MainWP\Child;
|
|
|
|
|
|
|
20 |
|
21 |
+
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions, Generic.Metrics.CyclomaticComplexity -- required to achieve desired results, pull request solutions appreciated.
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Class MainWP_Child_Back_Up_WordPress
|
25 |
+
*
|
26 |
+
* MainWP BackUpWordPress Extension handler.
|
27 |
+
*/
|
28 |
+
class MainWP_Child_Back_Up_WordPress {
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Public static variable to hold the single instance of the class.
|
32 |
+
*
|
33 |
+
* @var mixed Default null
|
34 |
+
*/
|
35 |
public static $instance = null;
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
/**
|
38 |
+
* Public variable to hold the infomration if the BackUpWordPress plugin is installed on the child site.
|
39 |
+
*
|
40 |
+
* @var bool If BackUpWordPress intalled, return true, if not, return false.
|
41 |
+
*/
|
42 |
+
public $is_plugin_installed = false;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Method instance()
|
46 |
+
*
|
47 |
+
* Create a public static instance.
|
48 |
+
*
|
49 |
+
* @return mixed Class instance.
|
50 |
+
*/
|
51 |
+
public static function instance() {
|
52 |
+
if ( null === self::$instance ) {
|
53 |
+
self::$instance = new self();
|
54 |
+
}
|
55 |
+
return self::$instance;
|
56 |
}
|
57 |
|
58 |
+
/**
|
59 |
+
* MainWP_Child_Back_Up_WordPress constructor.
|
60 |
+
*
|
61 |
+
* Run any time the class is called.
|
62 |
+
*
|
63 |
+
* @uses is_plugin_active() Determines whether a plugin is active.
|
64 |
+
* @see https://developer.wordpress.org/reference/functions/is_plugin_active/
|
65 |
+
*/
|
66 |
+
public function __construct() {
|
67 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
68 |
if ( is_plugin_active( 'backupwordpress/backupwordpress.php' ) ) {
|
69 |
+
$this->is_plugin_installed = true;
|
70 |
+
if ( version_compare( phpversion(), '5.3', '>=' ) ) {
|
71 |
+
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
72 |
+
}
|
73 |
}
|
74 |
+
}
|
75 |
|
76 |
+
/**
|
77 |
+
* Method init()
|
78 |
+
*
|
79 |
+
* Initiate action hooks.
|
80 |
+
*
|
81 |
+
* @uses get_option() Retrieves an option value based on an option name.
|
82 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
83 |
+
*
|
84 |
+
* @return void
|
85 |
+
*/
|
86 |
public function init() {
|
87 |
+
if ( version_compare( phpversion(), '5.3', '<' ) ) {
|
88 |
+
return;
|
89 |
+
}
|
90 |
|
91 |
+
if ( ! $this->is_plugin_installed ) {
|
92 |
+
return;
|
93 |
+
}
|
94 |
|
95 |
+
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
|
96 |
|
97 |
+
if ( 'hide' === get_option( 'mainwp_backupwordpress_hide_plugin' ) ) {
|
98 |
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
99 |
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
100 |
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
101 |
+
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );
|
102 |
}
|
103 |
}
|
104 |
|
105 |
+
/**
|
106 |
+
* Remove the BackUpWordPress plugin update notice when the plugin is hidden.
|
107 |
+
*
|
108 |
+
* @param array $slugs Array containing installed plugins slugs.
|
109 |
+
*
|
110 |
+
* @return array $slugs Array containing installed plugins slugs.
|
111 |
+
*/
|
112 |
+
public function hide_update_notice( $slugs ) {
|
113 |
+
$slugs[] = 'backupwordpress/backupwordpress.php';
|
114 |
+
return $slugs;
|
115 |
+
}
|
116 |
|
117 |
+
/**
|
118 |
+
* Remove the BackUpWordPress plugin update notice when the plugin is hidden.
|
119 |
+
*
|
120 |
+
* @param object $value Object containing update information.
|
121 |
+
*
|
122 |
+
* @return object $value Object containing update information.
|
123 |
+
*/
|
124 |
+
public function remove_update_nag( $value ) {
|
125 |
if ( isset( $_POST['mainwpsignature'] ) ) {
|
126 |
return $value;
|
127 |
}
|
128 |
|
129 |
+
if ( ! MainWP_Helper::is_updates_screen() ) {
|
130 |
+
return $value;
|
131 |
+
}
|
132 |
if ( isset( $value->response['backupwordpress/backupwordpress.php'] ) ) {
|
133 |
unset( $value->response['backupwordpress/backupwordpress.php'] );
|
134 |
}
|
136 |
return $value;
|
137 |
}
|
138 |
|
139 |
+
/**
|
140 |
+
* Fire off certain BackUpWordPress plugin actions.
|
141 |
+
*
|
142 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
143 |
+
*
|
144 |
+
* @uses MainWP_Child_Back_Up_WordPress::is_activated() Check if the plugin is activated.
|
145 |
+
*
|
146 |
+
* @uses MainWP_Child_Back_Up_WordPress::set_showhide() Hide or unhide the BackUpWordPress plugin.
|
147 |
+
* @uses MainWP_Child_Back_Up_WordPress::delete_schedule() Delete backup schedule.
|
148 |
+
* @uses MainWP_Child_Back_Up_WordPress::hmbkp_request_cancel_backup() Cancel backup process.
|
149 |
+
* @uses MainWP_Child_Back_Up_WordPress::get_backup_status() Get the bacukp process status.
|
150 |
+
* @uses MainWP_Child_Back_Up_WordPress::reload_backups() Reload backups.
|
151 |
+
* @uses MainWP_Child_Back_Up_WordPress::hmbkp_request_delete_backup() Delete backup.
|
152 |
+
* @uses MainWP_Child_Back_Up_WordPress::run_schedule() Run schedules.
|
153 |
+
* @uses MainWP_Child_Back_Up_WordPress::save_all_schedules() Save all schedules.
|
154 |
+
* @uses MainWP_Child_Back_Up_WordPress::update_schedule() Update schedule.
|
155 |
+
* @uses MainWP_Child_Back_Up_WordPress::get_excluded() Get excluded files.
|
156 |
+
* @uses MainWP_Child_Back_Up_WordPress::directory_browse() Browse directory.
|
157 |
+
* @uses MainWP_Child_Back_Up_WordPress::hmbkp_add_exclude_rule() Add exclusion rule.
|
158 |
+
* @uses MainWP_Child_Back_Up_WordPress::hmbkp_remove_exclude_rule() Remove exclusion rule.
|
159 |
+
* @uses MainWP_Child_Back_Up_WordPress::general_exclude_add_rule() General exclusion rules.
|
160 |
+
*
|
161 |
+
* @return void
|
162 |
+
*/
|
163 |
+
public function action() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
164 |
$information = array();
|
165 |
+
if ( ! self::is_activated() ) {
|
166 |
$information['error'] = 'NO_BACKUPWORDPRESS';
|
167 |
MainWP_Helper::write( $information );
|
168 |
}
|
|
|
169 |
if ( isset( $_POST['mwp_action'] ) ) {
|
170 |
+
$mwp_action = ! empty( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
171 |
+
switch ( $mwp_action ) {
|
172 |
case 'set_showhide':
|
173 |
$information = $this->set_showhide();
|
174 |
break;
|
208 |
case 'exclude_remove_rule':
|
209 |
$information = $this->hmbkp_remove_exclude_rule();
|
210 |
break;
|
211 |
+
case 'general_exclude_add_rule':
|
212 |
$information = $this->general_exclude_add_rule();
|
213 |
break;
|
214 |
}
|
216 |
MainWP_Helper::write( $information );
|
217 |
}
|
218 |
|
219 |
+
/**
|
220 |
+
* Check schedule and get the ID.
|
221 |
+
*
|
222 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
223 |
+
*
|
224 |
+
* @uses sanitize_text_field() Sanitizes a string from user input or from the database.
|
225 |
+
* @see https://developer.wordpress.org/reference/functions/sanitize_text_field/
|
226 |
+
*
|
227 |
+
* @return int Schedule ID.
|
228 |
+
*/
|
229 |
+
public function check_schedule() {
|
230 |
+
$schedule_id = ( isset( $_POST['schedule_id'] ) && ! empty( $_POST['schedule_id'] ) ) ? sanitize_text_field( wp_unslash( $_POST['schedule_id'] ) ) : '';
|
231 |
if ( empty( $schedule_id ) ) {
|
232 |
$information = array( 'error' => 'Empty schedule id' );
|
233 |
MainWP_Helper::write( $information );
|
234 |
} else {
|
235 |
+
$schedule_id = sanitize_text_field( rawurldecode( $schedule_id ) );
|
236 |
+
\HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
|
237 |
+
if ( ! \HM\BackUpWordPress\Schedules::get_instance()->get_schedule( $schedule_id ) ) {
|
238 |
$information = array( 'result' => 'NOTFOUND' );
|
239 |
MainWP_Helper::write( $information );
|
240 |
}
|
242 |
|
243 |
return $schedule_id;
|
244 |
}
|
245 |
+
|
246 |
+
/**
|
247 |
+
* Sync the BackUpWordPress plugin settings.
|
248 |
+
*
|
249 |
+
* @param array $information Array containing the sync information.
|
250 |
+
* @param array $data Array containing the BackUpWordPress plugin data to be synced.
|
251 |
+
*
|
252 |
+
* @uses MainWP_Child_Back_Up_WordPress::get_sync_data() Get synced BackUpWordPress data.
|
253 |
+
*
|
254 |
+
* @return array $information Array containing the sync information.
|
255 |
+
*/
|
256 |
+
public function sync_others_data( $information, $data = array() ) {
|
257 |
+
if ( isset( $data['syncBackUpWordPress'] ) && $data['syncBackUpWordPress'] ) {
|
258 |
+
try {
|
259 |
+
$information['syncBackUpWordPress'] = $this->get_sync_data();
|
260 |
+
} catch ( \Exception $e ) {
|
261 |
+
// ok!
|
262 |
+
}
|
263 |
+
}
|
264 |
return $information;
|
265 |
}
|
266 |
|
267 |
+
/**
|
268 |
+
* Get synced BackUpWordPress data.
|
269 |
+
*
|
270 |
+
* @uses MainWP_Helper::check_classes_exists() Check if requested class exists.
|
271 |
+
* @uses MainWP_Helper::check_methods() Check if requested method exists.
|
272 |
+
*
|
273 |
+
* @used-by MainWP_Child_Back_Up_WordPress::sync_others_data() Sync the BackUpWordPress plugin settings.
|
274 |
+
*
|
275 |
+
* @return array Return an array containing the synced data.
|
276 |
+
*/
|
277 |
private function get_sync_data() {
|
278 |
+
MainWP_Helper::check_classes_exists( '\HM\BackUpWordPress\Schedules' );
|
279 |
+
MainWP_Helper::check_methods( '\HM\BackUpWordPress\Schedules', array( 'get_instance', 'refresh_schedules', 'get_schedules' ) );
|
280 |
|
281 |
+
\HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
|
282 |
+
$schedules = \HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
|
283 |
$backups_time = array();
|
284 |
|
285 |
+
if ( is_array( $schedules ) && count( $schedules ) ) {
|
286 |
+
foreach ( $schedules as $sche ) {
|
287 |
+
if ( true === MainWP_Helper::check_methods( $sche, array( 'get_backups' ), true ) ) {
|
288 |
+
$existing_backup = $sche->get_backups();
|
289 |
+
if ( ! empty( $existing_backup ) ) {
|
290 |
+
$backups_time = array_merge( $backups_time, array_keys( $existing_backup ) );
|
291 |
+
}
|
292 |
+
}
|
293 |
+
}
|
294 |
+
}
|
|
|
295 |
|
296 |
$lasttime_backup = 0;
|
297 |
if ( ! empty( $backups_time ) ) {
|
303 |
return $return;
|
304 |
}
|
305 |
|
306 |
+
/**
|
307 |
+
* Add support for the reporting system.
|
308 |
+
*
|
309 |
+
* @uses has_action() Check if any action has been registered for a hook.
|
310 |
+
* @see https://developer.wordpress.org/reference/functions/has_action/
|
311 |
+
*
|
312 |
+
* @uses MainWP_Child_Back_Up_WordPress::do_reports_log() Add BackUpWordPress data to the reports database table.
|
313 |
+
*/
|
314 |
+
public function do_site_stats() {
|
315 |
+
if ( has_action( 'mainwp_child_reports_log' ) ) {
|
316 |
+
do_action( 'mainwp_child_reports_log', 'backupwordpress' );
|
317 |
+
} else {
|
318 |
+
$this->do_reports_log( 'backupwordpress' );
|
319 |
+
}
|
320 |
+
}
|
321 |
+
|
322 |
+
/**
|
323 |
+
* Add BackUpWordPress data to the reports database table.
|
324 |
+
*
|
325 |
+
* @param string $ext Current extension.
|
326 |
+
*
|
327 |
+
* @uses MainWP_Helper::check_classes_exists() Check if the requested class exists.
|
328 |
+
* @uses MainWP_Helper::check_methods() Check if the requested method exists.
|
329 |
+
* @uses MainWP_Utility::update_lasttime_backup() Get the last backup timestamp.
|
330 |
+
*
|
331 |
+
* @used-by MainWP_Child_Back_Up_WordPress::do_site_stats() Add support for the reporting system.
|
332 |
+
*/
|
333 |
+
public function do_reports_log( $ext = '' ) {
|
334 |
+
if ( 'backupwordpress' !== $ext ) {
|
335 |
+
return;
|
336 |
+
}
|
337 |
+
if ( ! $this->is_plugin_installed ) {
|
338 |
+
return;
|
339 |
+
}
|
340 |
+
|
341 |
+
try {
|
342 |
+
MainWP_Helper::check_classes_exists( '\HM\BackUpWordPress\Schedules' );
|
343 |
+
MainWP_Helper::check_methods( '\HM\BackUpWordPress\Schedules', array( 'get_instance', 'refresh_schedules', 'get_schedules' ) );
|
344 |
+
|
345 |
+
// Refresh the schedules from the database to make sure we have the latest changes.
|
346 |
+
\HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
|
347 |
+
$schedules = \HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
|
348 |
+
if ( is_array( $schedules ) && count( $schedules ) > 0 ) {
|
349 |
+
$check = current( $schedules );
|
350 |
+
MainWP_Helper::check_methods( $check, array( 'get_backups', 'get_type' ) );
|
351 |
+
|
352 |
+
foreach ( $schedules as $schedule ) {
|
353 |
+
foreach ( $schedule->get_backups() as $file ) {
|
354 |
+
$backup_type = $schedule->get_type();
|
355 |
+
$message = 'BackupWordpres backup ' . $backup_type . ' finished';
|
356 |
+
$destination = 'N/A';
|
357 |
+
if ( file_exists( $file ) ) {
|
358 |
+
$date = filemtime( $file );
|
359 |
+
if ( ! empty( $date ) ) {
|
360 |
+
do_action( 'mainwp_reports_backupwordpress_backup', $destination, $message, 'finished', $backup_type, $date );
|
361 |
+
MainWP_Utility::update_lasttime_backup( 'backupwordpress', $date ); // to support backup before update feature.
|
362 |
+
}
|
363 |
+
}
|
364 |
+
}
|
365 |
+
}
|
366 |
+
}
|
367 |
+
} catch ( \Exception $e ) {
|
368 |
+
// ok!
|
369 |
+
}
|
370 |
+
}
|
371 |
+
|
372 |
+
/**
|
373 |
+
* Hide or unhide the BackUpWordPress plugin.
|
374 |
+
*
|
375 |
+
* @uses MainWP_Helper::update_option() Update database option by option name.
|
376 |
+
*
|
377 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
378 |
+
*
|
379 |
+
* @return array Action result.
|
380 |
+
*/
|
381 |
+
public function set_showhide() {
|
382 |
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
383 |
MainWP_Helper::update_option( 'mainwp_backupwordpress_hide_plugin', $hide );
|
384 |
$information['result'] = 'SUCCESS';
|
386 |
return $information;
|
387 |
}
|
388 |
|
389 |
+
/**
|
390 |
+
* Delete schedule.
|
391 |
+
*
|
392 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
393 |
+
*
|
394 |
+
* @return array Action result.
|
395 |
+
*/
|
396 |
+
public function delete_schedule() {
|
397 |
$schedule_id = $this->check_schedule();
|
398 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
399 |
|
400 |
if ( $schedule ) {
|
401 |
$schedule->cancel( true );
|
407 |
return $information;
|
408 |
}
|
409 |
|
410 |
+
/**
|
411 |
+
* Cancel the backup process.
|
412 |
+
*
|
413 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
414 |
+
*
|
415 |
+
* @return array Action result.
|
416 |
+
*/
|
417 |
+
public function hmbkp_request_cancel_backup() {
|
418 |
$schedule_id = $this->check_schedule();
|
419 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
420 |
|
421 |
+
// Delete the running backup.
|
422 |
+
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
|
|
423 |
if ( $schedule->get_running_backup_filename() && file_exists( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ) ) {
|
424 |
unlink( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() );
|
425 |
}
|
428 |
}
|
429 |
} else {
|
430 |
$status = $schedule->get_status();
|
431 |
+
// Delete the running backup.
|
432 |
+
if ( $status->get_backup_filename() && file_exists( trailingslashit( \HM\BackUpWordPress\Path::get_path() ) . $status->get_backup_filename() ) ) {
|
433 |
+
unlink( trailingslashit( \HM\BackUpWordPress\Path::get_path() ) . $status->get_backup_filename() );
|
434 |
}
|
435 |
if ( file_exists( $status->get_status_filepath() ) ) {
|
436 |
unlink( $status->get_status_filepath() );
|
437 |
}
|
|
|
438 |
}
|
439 |
|
440 |
+
\HM\BackUpWordPress\Path::get_instance()->cleanup();
|
441 |
|
442 |
+
if ( null === $status ) {
|
443 |
$information['scheduleStatus'] = $schedule->get_status();
|
444 |
} else {
|
445 |
$information['scheduleStatus'] = $status->get_status();
|
446 |
}
|
447 |
|
448 |
+
$information['result'] = 'SUCCESS';
|
449 |
|
450 |
return $information;
|
451 |
}
|
452 |
|
453 |
+
/**
|
454 |
+
* Get the backup process status.
|
455 |
+
*
|
456 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
457 |
+
*
|
458 |
+
* @return array Action result.
|
459 |
+
*/
|
460 |
+
public function get_backup_status() {
|
461 |
$schedule_id = $this->check_schedule();
|
462 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
463 |
|
464 |
+
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
465 |
$information['scheduleStatus'] = $schedule->get_status();
|
466 |
} else {
|
467 |
+
$status = $schedule->get_status();
|
468 |
$information['scheduleStatus'] = $status->get_status();
|
469 |
}
|
470 |
|
471 |
+
$information['result'] = 'SUCCESS';
|
472 |
|
473 |
return $information;
|
474 |
}
|
475 |
|
476 |
+
/**
|
477 |
+
* Run schedule.
|
478 |
+
*
|
479 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
480 |
+
*
|
481 |
+
* @return array Action result.
|
482 |
+
*/
|
483 |
+
public function run_schedule() {
|
484 |
$schedule_id = $this->check_schedule();
|
485 |
+
if ( function_exists( 'hmbkp_run_schedule_async' ) ) {
|
486 |
+
hmbkp_run_schedule_async( $schedule_id );
|
487 |
+
} elseif ( function_exists( '\HM\BackUpWordPress\run_schedule_async' ) ) {
|
488 |
+
\HM\BackUpWordPress\Path::get_instance()->cleanup();
|
489 |
+
// Fixes an issue on servers which only allow a single session per client.
|
490 |
session_write_close();
|
491 |
$task = new \HM\Backdrop\Task( '\HM\BackUpWordPress\run_schedule_async', $schedule_id );
|
492 |
$task->schedule();
|
493 |
+
} else {
|
494 |
+
return array( 'error' => __( 'Error while trying to trigger the schedule', 'mainwp-child' ) );
|
495 |
+
}
|
496 |
return array( 'result' => 'SUCCESS' );
|
497 |
}
|
498 |
|
499 |
+
/**
|
500 |
+
* Reload backups.
|
501 |
+
*
|
502 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
503 |
+
*
|
504 |
+
* @return array Action result.
|
505 |
+
*/
|
506 |
+
public function reload_backups() {
|
507 |
|
508 |
+
$scheduleIds = isset( $_POST['schedule_ids'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['schedule_ids'] ) ) : array();
|
509 |
+
\HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
|
510 |
|
511 |
$all_schedules_ids = array();
|
512 |
+
$schedules = \HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
|
513 |
foreach ( $schedules as $sch ) {
|
514 |
$all_schedules_ids[] = $sch->get_id();
|
515 |
}
|
519 |
}
|
520 |
|
521 |
foreach ( $all_schedules_ids as $schedule_id ) {
|
522 |
+
if ( ! \HM\BackUpWordPress\Schedules::get_instance()->get_schedule( $schedule_id ) ) {
|
523 |
continue;
|
524 |
}
|
525 |
|
526 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
527 |
+
$started_ago = method_exists( $schedule, 'get_schedule_running_start_time' ) ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time();
|
528 |
+
$out = array(
|
529 |
'b' => $this->get_backupslist_html( $schedule ),
|
530 |
'count' => count( $schedule->get_backups() ),
|
531 |
'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ),
|
532 |
'started_ago' => human_time_diff( $started_ago ),
|
533 |
);
|
534 |
|
535 |
+
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
536 |
$out['scheduleStatus'] = $schedule->get_status();
|
537 |
} else {
|
538 |
+
$status = $schedule->get_status();
|
539 |
$out['scheduleStatus'] = $status->get_status();
|
540 |
}
|
541 |
|
544 |
|
545 |
$send_back_schedules = array();
|
546 |
|
547 |
+
$schedules = \HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
|
548 |
foreach ( $schedules as $schedule ) {
|
549 |
$sch_id = $schedule->get_id();
|
550 |
if ( ! in_array( $sch_id, $scheduleIds ) ) {
|
551 |
$current_option = get_option( 'hmbkp_schedule_' . $sch_id );
|
552 |
if ( is_array( $current_option ) ) {
|
553 |
+
unset( $current_option['excludes'] );
|
554 |
+
$started_ago = method_exists( $schedule, 'get_schedule_running_start_time' ) ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time();
|
555 |
$send_back_schedules[ $sch_id ] = array(
|
556 |
'options' => $current_option,
|
557 |
'b' => $this->get_backupslist_html( $schedule ),
|
560 |
'scheduleStatus' => $schedule->get_status(),
|
561 |
'started_ago' => human_time_diff( $started_ago ),
|
562 |
);
|
563 |
+
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
564 |
$send_back_schedules['scheduleStatus'] = $schedule->get_status();
|
565 |
} else {
|
566 |
+
$status = $schedule->get_status();
|
567 |
$send_back_schedules['scheduleStatus'] = $status->get_status();
|
568 |
}
|
569 |
}
|
570 |
}
|
571 |
}
|
572 |
|
573 |
+
if ( function_exists( '\HM\BackUpWordPress\Backup::get_home_path' ) ) {
|
574 |
+
$backups_path = str_replace( \HM\BackUpWordPress\Backup::get_home_path(), '', hmbkp_path() );
|
575 |
+
} else {
|
576 |
+
$backups_path = str_replace( \HM\BackUpWordPress\Path::get_home_path(), '', \HM\BackUpWordPress\Path::get_path() );
|
577 |
+
}
|
578 |
|
579 |
$information['backups_path'] = $backups_path;
|
580 |
$information['send_back_schedules'] = $send_back_schedules;
|
583 |
return $information;
|
584 |
}
|
585 |
|
586 |
+
/**
|
587 |
+
* Delete backup.
|
588 |
+
*
|
589 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
590 |
+
*
|
591 |
+
* @return array Action result.
|
592 |
+
*/
|
593 |
+
public function hmbkp_request_delete_backup() {
|
594 |
if ( ! isset( $_POST['hmbkp_backuparchive'] ) || empty( $_POST['hmbkp_backuparchive'] ) ) {
|
595 |
return array( 'error' => __( 'Invalid data. Please check and try again.', 'mainwp-child' ) );
|
596 |
}
|
597 |
|
598 |
$schedule_id = $this->check_schedule();
|
599 |
|
600 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
601 |
|
602 |
+
$deleted = isset( $_POST['hmbkp_backuparchive'] ) ? $schedule->delete_backup( base64_decode( rawurldecode( wp_unslash( $_POST['hmbkp_backuparchive'] ) ) ) ) : false; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
603 |
|
604 |
if ( is_wp_error( $deleted ) ) {
|
605 |
return array( 'error' => $deleted->get_error_message() );
|
606 |
}
|
607 |
|
608 |
+
$ret = array(
|
609 |
'result' => 'SUCCESS',
|
610 |
'b' => $this->get_backupslist_html( $schedule ),
|
611 |
'count' => count( $schedule->get_backups() ),
|
612 |
'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ),
|
613 |
);
|
614 |
+
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
615 |
$ret['scheduleStatus'] = $schedule->get_status();
|
616 |
} else {
|
617 |
+
$status = $schedule->get_status();
|
618 |
$ret['scheduleStatus'] = $status->get_status();
|
619 |
}
|
620 |
return $ret;
|
621 |
}
|
622 |
|
623 |
+
/**
|
624 |
+
* Get backups list HTML.
|
625 |
+
*
|
626 |
+
* @param object $schedule Object containing the schedule data.
|
627 |
+
*
|
628 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
629 |
+
*
|
630 |
+
* @return array Action result.
|
631 |
+
*/
|
632 |
+
public function get_backupslist_html( $schedule ) {
|
633 |
ob_start();
|
634 |
?>
|
635 |
<table class="widefat">
|
|
|
636 |
<thead>
|
637 |
+
<tr>
|
638 |
+
<th scope="col"><?php function_exists( 'hmbkp_backups_number' ) ? hmbkp_backups_number( $schedule ) : ( function_exists( 'backups_number' ) ? backups_number( $schedule ) : '' ); ?></th>
|
639 |
+
<th scope="col"><?php esc_html_e( 'Size', 'mainwp-child' ); ?></th>
|
640 |
+
<th scope="col"><?php esc_html_e( 'Type', 'mainwp-child' ); ?></th>
|
641 |
+
<th scope="col"><?php esc_html_e( 'Actions', 'mainwp-child' ); ?></th>
|
642 |
+
</tr>
|
|
|
|
|
|
|
|
|
643 |
</thead>
|
|
|
644 |
<tbody>
|
645 |
+
<?php
|
646 |
+
if ( $schedule->get_backups() ) {
|
|
|
647 |
$schedule->delete_old_backups();
|
|
|
648 |
foreach ( $schedule->get_backups() as $file ) {
|
|
|
649 |
if ( ! file_exists( $file ) ) {
|
650 |
continue;
|
651 |
}
|
|
|
652 |
$this->hmbkp_get_backup_row( $file, $schedule );
|
|
|
653 |
}
|
654 |
+
} else {
|
655 |
+
?>
|
656 |
<tr>
|
657 |
+
<td class="hmbkp-no-backups" colspan="4"><?php esc_html_e( 'This is where your backups will appear once you have some.', 'mainwp-child' ); ?></td>
|
|
|
658 |
</tr>
|
|
|
659 |
<?php } ?>
|
|
|
660 |
</tbody>
|
|
|
661 |
</table>
|
662 |
<?php
|
663 |
$html = ob_get_clean();
|
665 |
return $html;
|
666 |
}
|
667 |
|
668 |
+
/**
|
669 |
+
* Get the site size text.
|
670 |
+
*
|
671 |
+
* @param \HM\BackUpWordPress\Scheduled_Backup $schedule Object containing the schedule data.
|
672 |
+
*
|
673 |
+
* @return string Site size text.
|
674 |
+
*/
|
675 |
+
public function hmbkp_get_site_size_text( \HM\BackUpWordPress\Scheduled_Backup $schedule ) {
|
676 |
+
if ( method_exists( $schedule, 'is_site_size_cached' ) ) {
|
677 |
if ( ( 'database' === $schedule->get_type() ) || $schedule->is_site_size_cached() ) {
|
678 |
+
return sprintf( '(<code title="' . __( 'Backups will be compressed and should be smaller than this.', 'mainwp-child' ) . '">%s</code>)', esc_attr( $schedule->get_formatted_site_size() ) );
|
679 |
}
|
680 |
} else {
|
681 |
+
$site_size = new \HM\BackUpWordPress\Site_Size( $schedule->get_type(), $schedule->get_excludes() );
|
682 |
if ( ( 'database' === $schedule->get_type() ) || $site_size->is_site_size_cached() ) {
|
683 |
+
return sprintf( '(<code title="' . __( 'Backups will be compressed and should be smaller than this.', 'mainwp-child' ) . '">%s</code>)', esc_attr( $site_size->get_formatted_site_size() ) );
|
684 |
}
|
685 |
}
|
686 |
|
687 |
+
return sprintf( '(<code class="calculating" title="' . __( 'this shouldn\'t take long…', 'mainwp-child' ) . '">' . __( 'calculating the size of your backup…', 'mainwp-child' ) . '</code>)' );
|
|
|
688 |
}
|
689 |
|
690 |
+
/**
|
691 |
+
* Get the backup table row HTML.
|
692 |
+
*
|
693 |
+
* @param resource $file Backup file.
|
694 |
+
* @param \HM\BackUpWordPress\Scheduled_Backup $schedule Object containing the schedule data.
|
695 |
+
*/
|
696 |
+
public function hmbkp_get_backup_row( $file, \HM\BackUpWordPress\Scheduled_Backup $schedule ) {
|
697 |
+
$encoded_file = rawurlencode( base64_encode( $file ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
698 |
$offset = get_option( 'gmt_offset' ) * 3600;
|
|
|
699 |
?>
|
|
|
700 |
<tr class="hmbkp_manage_backups_row">
|
|
|
701 |
<th scope="row">
|
702 |
+
<?php echo esc_html( date_i18n( get_option( 'date_format' ) . ' - ' . get_option( 'time_format' ), filemtime( $file ) + $offset ) ); ?>
|
703 |
</th>
|
|
|
704 |
<td class="code">
|
705 |
+
<?php echo esc_html( size_format( filesize( $file ) ) ); ?>
|
706 |
</td>
|
707 |
+
<td><?php echo function_exists( 'hmbkp_human_get_type' ) ? esc_html( hmbkp_human_get_type( $file, $schedule ) ) : esc_html( \HM\BackUpWordPress\human_get_type( $file, $schedule ) ); ?></td>
|
|
|
|
|
708 |
<td>
|
709 |
+
<?php
|
710 |
+
if ( function_exists( 'hmbkp_is_path_accessible' ) ) {
|
711 |
if ( hmbkp_is_path_accessible( hmbkp_path() ) ) {
|
712 |
?>
|
713 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_download_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);" class="download-action"><?php esc_html_e( 'Download', 'mainwp-child' ); ?></a> |
|
714 |
+
<?php
|
715 |
+
};
|
716 |
+
} elseif ( function_exists( '\HM\BackUpWordPress\is_path_accessible' ) ) {
|
717 |
+
if ( \HM\BackUpWordPress\is_path_accessible( \HM\BackUpWordPress\Path::get_path() ) ) {
|
|
|
718 |
?>
|
719 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_download_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);" class="download-action"><?php esc_html_e( 'Download', 'maiwnp-child' ); ?></a> |
|
720 |
+
<?php
|
721 |
+
};
|
|
|
722 |
}
|
723 |
?>
|
724 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_delete_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);" class="delete-action"><?php esc_html_e( 'Delete', 'mainwp-child' ); ?></a>
|
|
|
|
|
|
|
|
|
725 |
</td>
|
|
|
726 |
</tr>
|
727 |
+
<?php
|
728 |
+
}
|
729 |
|
730 |
+
/**
|
731 |
+
* Get excluded files.
|
732 |
+
*
|
733 |
+
* @param string $browse_dir Browse directory path.
|
734 |
+
*
|
735 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
736 |
+
*
|
737 |
+
* @return array Action result.
|
738 |
+
*/
|
739 |
+
public function get_excluded( $browse_dir = null ) {
|
740 |
|
741 |
$schedule_id = $this->check_schedule();
|
742 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
743 |
|
744 |
$new_version = true;
|
745 |
+
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
746 |
+
$new_version = false;
|
747 |
+
$user_excludes = array_diff( $schedule->get_excludes(), $schedule->backup->default_excludes() );
|
748 |
+
$root_dir = $schedule->backup->get_root();
|
749 |
$is_size_calculated = $schedule->is_site_size_being_calculated();
|
750 |
} else {
|
751 |
+
$excludes = $schedule->get_excludes();
|
752 |
+
$user_excludes = $excludes->get_user_excludes();
|
753 |
+
$root_dir = \HM\BackUpWordPress\Path::get_root();
|
754 |
+
$is_size_calculated = \HM\BackUpWordPress\Site_Size::is_site_size_being_calculated();
|
755 |
}
|
756 |
|
757 |
ob_start();
|
758 |
|
759 |
?>
|
760 |
<div class="hmbkp-exclude-settings">
|
761 |
+
<h3><?php esc_html_e( 'Currently Excluded', 'mainwp-child' ); ?></h3>
|
762 |
+
<p><?php esc_html_e( 'We automatically detect and ignore common <abbr title="Version Control Systems">VCS</abbr> folders and other backup plugin folders.', 'mainwp-child' ); ?></p>
|
763 |
+
<?php
|
764 |
+
$this->render_table_excluded( $root_dir, $schedule, $excludes, $user_excludes, $new_version )
|
765 |
+
?>
|
766 |
+
<h3 id="directory-listing"><?php esc_html_e( 'Your Site', 'mainwp-child' ); ?></h3>
|
767 |
+
<p><?php esc_html_e( 'Here\'s a directory listing of all files on your site, you can browse through and exclude files or folders that you don\'t want included in your backup.', 'mainwp-child' ); ?></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
768 |
<?php
|
|
|
769 |
$directory = $root_dir;
|
770 |
|
771 |
if ( isset( $browse_dir ) ) {
|
772 |
|
773 |
+
$untrusted_directory = rawurldecode( $browse_dir );
|
774 |
|
775 |
+
// Only allow real sub directories of the site root to be browsed.
|
776 |
if ( false !== strpos( $untrusted_directory, $root_dir ) && is_dir( $untrusted_directory ) ) {
|
777 |
$directory = $untrusted_directory;
|
778 |
}
|
779 |
}
|
780 |
|
781 |
+
// Kick off a recursive filesize scan.
|
782 |
+
if ( $new_version ) {
|
783 |
+
$site_size = new \HM\BackUpWordPress\Site_Size();
|
|
|
|
|
784 |
$exclude_string = implode( '|', $excludes->get_excludes_for_regex() );
|
785 |
+
if ( function_exists( '\HM\BackUpWordPress\list_directory_by_total_filesize' ) ) {
|
786 |
+
$files = \HM\BackUpWordPress\list_directory_by_total_filesize( $directory, $excludes );
|
787 |
+
}
|
|
|
788 |
} else {
|
789 |
+
$files = $schedule->list_directory_by_total_filesize( $directory );
|
790 |
$exclude_string = $schedule->backup->exclude_string( 'regex' );
|
791 |
}
|
792 |
+
if ( $files ) {
|
793 |
+
$this->render_table_files( $files, $schedule, $directory, $root_dir, $new_version, $site_size, $is_size_calculated );
|
794 |
+
}
|
795 |
+
?>
|
796 |
+
<p class="submit">
|
797 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_edit_exclude_done()" class="button-primary"><?php esc_html_e( 'Done', 'mainwp-child' ); ?></a>
|
798 |
+
</p>
|
799 |
+
</div>
|
800 |
+
<?php
|
801 |
+
$output = ob_get_clean();
|
802 |
+
$information['e'] = $output;
|
803 |
|
804 |
+
return $information;
|
805 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
806 |
|
807 |
+
/**
|
808 |
+
* Render table of the excluded items.
|
809 |
+
*
|
810 |
+
* @param string $root_dir Root directory.
|
811 |
+
* @param object $schedule Object containng the schedule data.
|
812 |
+
* @param object $excludes Files to exclude.
|
813 |
+
* @param object $user_excludes Excluded by user.
|
814 |
+
* @param string $new_version New version.
|
815 |
+
*/
|
816 |
+
private function render_table_excluded( $root_dir, $schedule, $excludes, $user_excludes, $new_version ) {
|
817 |
+
?>
|
818 |
+
<table class="widefat">
|
819 |
+
<tbody>
|
820 |
+
<?php foreach ( $user_excludes as $key => $exclude ) : ?>
|
821 |
+
<?php $exclude_path = new \SplFileInfo( trailingslashit( $root_dir ) . ltrim( str_ireplace( $root_dir, '', $exclude ), '/' ) ); ?>
|
822 |
+
<tr>
|
823 |
+
<th scope="row">
|
824 |
+
<?php if ( $exclude_path->isFile() ) { ?>
|
825 |
+
<div class="dashicons dashicons-media-default"></div>
|
826 |
+
<?php } elseif ( $exclude_path->isDir() ) { ?>
|
827 |
+
<div class="dashicons dashicons-portfolio"></div>
|
828 |
+
<?php } ?>
|
829 |
+
</th>
|
830 |
+
<td>
|
831 |
+
<code><?php echo esc_html( str_ireplace( $root_dir, '', $exclude ) ); ?></code>
|
832 |
+
</td>
|
833 |
+
<td>
|
834 |
+
<?php
|
835 |
+
if ( $new_version ) {
|
836 |
+
$is_default_rule = ( in_array( $exclude, $excludes->get_default_excludes() ) ) || ( \HM\BackUpWordPress\Path::get_path() === trailingslashit( \HM\BackUpWordPress\Path::get_root() ) . untrailingslashit( $exclude ) );
|
837 |
+
} else {
|
838 |
+
$is_default_rule = ( in_array( $exclude, $schedule->backup->default_excludes() ) ) || ( hmbkp_path() === untrailingslashit( $exclude ) );
|
839 |
+
}
|
840 |
+
if ( $is_default_rule ) :
|
841 |
+
?>
|
842 |
+
<?php esc_html_e( 'Default rule', 'mainwp-child' ); ?>
|
843 |
+
<?php elseif ( defined( 'HMBKP_EXCLUDE' ) && false !== strpos( HMBKP_EXCLUDE, $exclude ) ) : ?>
|
844 |
+
<?php esc_html_e( 'Defined in wp-config.php', 'mainwp-child' ); ?>
|
845 |
+
<?php else : ?>
|
846 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_remove_exclude_rule('<?php esc_attr_e( $exclude ); ?>', this);" class="delete-action"><?php esc_html_e( 'Stop excluding', 'mainwp-child' ); ?></a>
|
847 |
+
<?php endif; ?>
|
848 |
+
</td>
|
849 |
+
</tr>
|
850 |
+
<?php endforeach; ?>
|
851 |
+
</tbody>
|
852 |
+
</table>
|
853 |
+
<?php
|
854 |
+
}
|
855 |
|
856 |
+
/**
|
857 |
+
* Render the files table.
|
858 |
+
*
|
859 |
+
* @param object $files Backup files.
|
860 |
+
* @param object $schedule Object containng the schedule data.
|
861 |
+
* @param string $directory Backups directory.
|
862 |
+
* @param string $root_dir Site root directory.
|
863 |
+
* @param string $new_version New version.
|
864 |
+
* @param int $site_size Site size.
|
865 |
+
* @param bool $is_size_calculated Check if the size is calculated.
|
866 |
+
*/
|
867 |
+
private function render_table_files( $files, $schedule, $directory, $root_dir, $new_version, $site_size, $is_size_calculated ) {
|
868 |
+
?>
|
869 |
+
<table class="widefat">
|
870 |
+
<thead>
|
871 |
+
<?php
|
872 |
+
$this->render_table_header_files( $root_dir, $directory, $schedule, $new_version, $site_size, $is_size_calculated );
|
873 |
+
?>
|
874 |
+
</thead>
|
875 |
+
<tbody>
|
876 |
+
<?php
|
877 |
+
$this->render_table_body_files( $files, $schedule, $root_dir, $new_version, $site_size, $is_size_calculated );
|
878 |
+
?>
|
879 |
+
</tbody>
|
880 |
+
</table>
|
881 |
+
<?php
|
882 |
+
}
|
883 |
|
884 |
+
/**
|
885 |
+
* Render the backup table header.
|
886 |
+
*
|
887 |
+
* @param string $root_dir Site root directory.
|
888 |
+
* @param string $directory Backups directory.
|
889 |
+
* @param object $schedule Object containng the schedule data.
|
890 |
+
* @param string $new_version New version.
|
891 |
+
* @param int $site_size Site size.
|
892 |
+
* @param bool $is_size_calculated Check if the size is calculated.
|
893 |
+
*/
|
894 |
+
private function render_table_header_files( $root_dir, $directory, $schedule, $new_version, $site_size, $is_size_calculated ) {
|
895 |
+
?>
|
896 |
+
<tr>
|
897 |
+
<th></th>
|
898 |
+
<th scope="col"><?php esc_html_e( 'Name', 'mainwp-child' ); ?></th>
|
899 |
+
<th scope="col" class="column-format"><?php esc_html_e( 'Size', 'mainwp-child' ); ?></th>
|
900 |
+
<th scope="col"
|
901 |
+
class="column-format"><?php esc_html_e( 'Permissions', 'mainwp-child' ); ?></th>
|
902 |
+
<th scope="col" class="column-format"><?php esc_html_e( 'Type', 'mainwp-child' ); ?></th>
|
903 |
+
<th scope="col" class="column-format"><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
904 |
+
</tr>
|
905 |
+
<tr>
|
906 |
+
<th scope="row">
|
907 |
+
<div class="dashicons dashicons-admin-home"></div>
|
908 |
+
</th>
|
909 |
+
<th scope="col">
|
910 |
+
<?php
|
911 |
+
if ( $root_dir !== $directory ) {
|
912 |
+
?>
|
913 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse( '', this )"><?php echo esc_html( $root_dir ); ?></a>
|
914 |
+
<code>/</code>
|
915 |
+
<?php
|
916 |
+
$parents = array_filter( explode( '/', str_replace( trailingslashit( $root_dir ), '', trailingslashit( dirname( $directory ) ) ) ) );
|
917 |
+
foreach ( $parents as $directory_basename ) {
|
918 |
+
?>
|
919 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo rawurlencode( substr( $directory, 0, strpos( $directory, $directory_basename ) ) . $directory_basename ); ?>', this)"><?php echo esc_html( $directory_basename ); ?></a>
|
920 |
+
<code>/</code>
|
921 |
+
<?php } ?>
|
922 |
+
<?php echo esc_html( basename( $directory ) ); ?>
|
923 |
+
<?php } else { ?>
|
924 |
+
<?php echo esc_html( $root_dir ); ?>
|
925 |
+
<?php } ?>
|
926 |
+
</th>
|
927 |
+
<td class="column-filesize">
|
928 |
+
<?php if ( $is_size_calculated ) : ?>
|
929 |
+
<span class="spinner"></span>
|
930 |
+
<?php
|
931 |
+
else :
|
932 |
+
$root = new \SplFileInfo( $root_dir );
|
933 |
+
if ( $new_version ) {
|
934 |
+
$size = $site_size->filesize( $root );
|
935 |
+
} else {
|
936 |
+
$size = $schedule->filesize( $root, true );
|
937 |
+
}
|
938 |
+
if ( false !== $size ) {
|
939 |
+
$size = size_format( $size );
|
940 |
+
if ( ! $size ) {
|
941 |
+
$size = '0 B';
|
942 |
+
}
|
943 |
+
?>
|
944 |
+
<code>
|
945 |
+
<?php echo esc_html( $size ); ?>
|
946 |
+
<a class="dashicons dashicons-update" href="<?php echo esc_attr( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', rawurlencode( $root_dir ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?>"><span><?php esc_html_e( 'Refresh', 'mainwp-child' ); ?></span></a>
|
947 |
+
</code>
|
948 |
+
<?php } ?>
|
949 |
+
<?php endif; ?>
|
950 |
+
<td>
|
951 |
+
<?php echo esc_html( substr( sprintf( '%o', fileperms( $root_dir ) ), - 4 ) ); ?>
|
952 |
+
</td>
|
953 |
+
<td>
|
954 |
+
<?php
|
955 |
+
if ( is_link( $root_dir ) ) {
|
956 |
+
esc_html_e( 'Symlink', 'mainwp-child' );
|
957 |
+
} elseif ( is_dir( $root_dir ) ) {
|
958 |
+
esc_html_e( 'Folder', 'mainwp-child' );
|
959 |
+
}
|
960 |
+
?>
|
961 |
+
</td>
|
962 |
+
<td></td>
|
963 |
+
</tr>
|
964 |
+
<?php
|
965 |
+
}
|
966 |
|
967 |
+
/**
|
968 |
+
* Render the backup table body.
|
969 |
+
*
|
970 |
+
* @param object $files Backup files.
|
971 |
+
* @param object $schedule Object containng the schedule data.
|
972 |
+
* @param string $root_dir Site root directory.
|
973 |
+
* @param string $new_version New version.
|
974 |
+
* @param int $site_size Site size.
|
975 |
+
* @param bool $is_size_calculated Check if the size is calculated.
|
976 |
+
*/
|
977 |
+
private function render_table_body_files( $files, $schedule, $root_dir, $new_version, $site_size, $is_size_calculated ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
978 |
+
|
979 |
+
foreach ( $files as $size => $file ) {
|
980 |
+
$is_excluded = false;
|
981 |
+
$is_unreadable = false;
|
982 |
+
// Check if the file is excluded.
|
983 |
+
if ( $new_version ) {
|
984 |
+
if ( $exclude_string && preg_match( '(' . $exclude_string . ')', str_ireplace( trailingslashit( $root_dir ), '', wp_normalize_path( $file->getPathname() ) ) ) ) {
|
985 |
+
$is_excluded = true;
|
986 |
+
}
|
987 |
+
} else {
|
988 |
+
if ( $exclude_string && preg_match( '(' . $exclude_string . ')', str_ireplace( trailingslashit( $root_dir ), '', \HM\BackUpWordPress\Backup::conform_dir( $file->getPathname() ) ) ) ) {
|
989 |
+
$is_excluded = true;
|
990 |
+
}
|
991 |
+
}
|
992 |
+
// Skip unreadable files.
|
993 |
+
if ( ! realpath( $file->getPathname() ) || ! $file->isReadable() ) {
|
994 |
+
$is_unreadable = true;
|
995 |
+
}
|
996 |
+
?>
|
997 |
+
<tr>
|
998 |
+
<td>
|
999 |
+
<?php if ( $is_unreadable ) { ?>
|
1000 |
+
<div class="dashicons dashicons-dismiss"></div>
|
1001 |
+
<?php } elseif ( $file->isFile() ) { ?>
|
1002 |
+
<div class="dashicons dashicons-media-default"></div>
|
1003 |
+
<?php } elseif ( $file->isDir() ) { ?>
|
1004 |
+
<div class="dashicons dashicons-portfolio"></div>
|
1005 |
+
<?php } ?>
|
1006 |
+
</td>
|
1007 |
+
<td>
|
1008 |
+
<?php
|
1009 |
+
if ( $new_version ) {
|
1010 |
+
if ( $is_unreadable ) {
|
1011 |
+
?>
|
1012 |
+
<code class="strikethrough" title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
1013 |
+
<?php } elseif ( $file->isFile() ) { ?>
|
1014 |
+
<code title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
1015 |
+
<?php } elseif ( $file->isDir() ) { ?>
|
1016 |
+
<code title="<?php echo esc_attr( $file->getRealPath() ); ?>"><a href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo rawurlencode( wp_normalize_path( $file->getPathname() ) ); ?>', this)"><?php echo esc_html( $file->getBasename() ); ?></a></code>
|
1017 |
<?php
|
1018 |
+
}
|
1019 |
+
} else {
|
1020 |
+
if ( $is_unreadable ) {
|
|
|
|
|
1021 |
?>
|
1022 |
+
<code class="strikethrough" title="<?php echo esc_attr( $file->getRealPath() ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
1023 |
+
<?php } elseif ( $file->isFile() ) { ?>
|
1024 |
+
<code title="<?php echo esc_attr( $file->getRealPath() ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
1025 |
+
<?php
|
1026 |
+
} elseif ( $file->isDir() ) {
|
1027 |
+
?>
|
1028 |
+
<code title="<?php echo esc_attr( $file->getRealPath() ); ?>"><a href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo rawurlencode( $file->getPathname() ); ?>', this)"><?php echo esc_html( $file->getBasename() ); ?></a></code>
|
1029 |
+
<?php
|
1030 |
+
}
|
1031 |
+
}
|
1032 |
+
?>
|
1033 |
+
</td>
|
1034 |
+
<td class="column-format column-filesize">
|
1035 |
+
<?php if ( $file->isDir() && $is_size_calculated ) : ?>
|
1036 |
+
<span class="spinner"></span>
|
1037 |
+
<?php
|
1038 |
+
else :
|
1039 |
+
if ( $new_version ) {
|
1040 |
+
$size = $site_size->filesize( $file );
|
|
|
1041 |
} else {
|
1042 |
+
$size = $schedule->filesize( $file );
|
|
|
|
|
1043 |
}
|
1044 |
+
if ( false !== $size ) {
|
1045 |
+
$size = size_format( $size );
|
1046 |
+
if ( ! $size ) {
|
1047 |
+
$size = '0 B';
|
1048 |
+
}
|
1049 |
+
?>
|
1050 |
+
<code>
|
1051 |
+
<?php echo esc_html( $size ); ?>
|
1052 |
+
<?php if ( $file->isDir() ) { ?>
|
1053 |
+
<a title="<?php esc_attr_e( 'Recalculate the size of this directory', 'maiwnp-child' ); ?>" class="dashicons dashicons-update" href="<?php echo esc_attr( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', rawurlencode( wp_normalize_path( $file->getPathname() ) ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?>"><span><?php esc_html_e( 'Refresh', 'mainwp-child' ); ?></span></a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1054 |
<?php } ?>
|
1055 |
+
</code>
|
1056 |
+
<?php } else { ?>
|
1057 |
+
<code>--</code>
|
1058 |
+
<?php
|
1059 |
+
}
|
1060 |
+
endif;
|
1061 |
+
?>
|
1062 |
+
</td>
|
1063 |
+
<td>
|
1064 |
+
<?php echo esc_html( substr( sprintf( '%o', $file->getPerms() ), - 4 ) ); ?>
|
1065 |
+
</td>
|
1066 |
+
<td>
|
1067 |
+
<?php if ( $file->isLink() ) : ?>
|
1068 |
+
<span title="<?php echo esc_attr( wp_normalize_path( $file->GetRealPath() ) ); ?>"><?php esc_html_e( 'Symlink', 'mainwp-child' ); ?></span>
|
1069 |
+
<?php
|
1070 |
+
elseif ( $file->isDir() ) :
|
1071 |
+
esc_html_e( 'Folder', 'mainwp-child' );
|
1072 |
+
else :
|
1073 |
+
esc_html_e( 'File', 'mainwp-child' );
|
1074 |
+
endif;
|
1075 |
+
?>
|
1076 |
+
</td>
|
1077 |
+
<td class="column-format">
|
1078 |
+
<?php if ( $is_unreadable ) : ?>
|
1079 |
+
<strong title="<?php esc_attr_e( 'Unreadable files won\'t be backed up.', 'mainwp-child' ); ?>"><?php esc_html_e( 'Unreadable', 'mainwp-child' ); ?></strong>
|
1080 |
+
<?php elseif ( $is_excluded ) : ?>
|
1081 |
+
<strong><?php esc_html_e( 'Excluded', 'mainwp-child' ); ?></strong>
|
1082 |
+
<?php
|
1083 |
+
else :
|
1084 |
+
$exclude_path = $file->getPathname();
|
1085 |
+
|
1086 |
+
// Excluded directories need to be trailingslashed.
|
1087 |
+
if ( $file->isDir() ) {
|
1088 |
+
$exclude_path = trailingslashit( wp_normalize_path( $file->getPathname() ) );
|
1089 |
+
}
|
1090 |
+
?>
|
1091 |
+
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_exclude_add_rule('<?php echo rawurlencode( $exclude_path ); ?>', this)" class="button-secondary"><?php esc_html_e( 'Exclude →', 'mainwp-child' ); ?></a>
|
1092 |
+
<?php endif; ?>
|
1093 |
+
</td>
|
1094 |
+
</tr>
|
1095 |
+
<?php
|
1096 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1097 |
}
|
1098 |
|
1099 |
+
/**
|
1100 |
+
* Browse the directory.
|
1101 |
+
*
|
1102 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
1103 |
+
*
|
1104 |
+
* @return array Action result.
|
1105 |
+
*/
|
1106 |
+
public function directory_browse() {
|
1107 |
+
$browse_dir = isset( $_POST['browse_dir'] ) ? wp_unslash( $_POST['browse_dir'] ) : '';
|
1108 |
$out = array();
|
1109 |
$return = $this->get_excluded( $browse_dir );
|
1110 |
$out['e'] = $return['e'];
|
1113 |
return $out;
|
1114 |
}
|
1115 |
|
1116 |
+
/**
|
1117 |
+
* Add exclusion rule.
|
1118 |
+
*
|
1119 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
1120 |
+
*
|
1121 |
+
* @return array Action result.
|
1122 |
+
*/
|
1123 |
+
public function hmbkp_add_exclude_rule() {
|
1124 |
|
1125 |
if ( ! isset( $_POST['exclude_pathname'] ) || empty( $_POST['exclude_pathname'] ) ) {
|
1126 |
+
return array( 'error' => __( 'Empty exclude directory path.', 'mainwp-child' ) );
|
1127 |
}
|
1128 |
|
1129 |
$schedule_id = $this->check_schedule();
|
1130 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $schedule_id ) );
|
1131 |
|
1132 |
+
$exclude_rule = isset( $_POST['exclude_pathname'] ) ? rawurldecode( wp_unslash( $_POST['exclude_pathname'] ) ) : '';
|
1133 |
|
1134 |
$schedule->set_excludes( $exclude_rule, true );
|
1135 |
|
1136 |
$schedule->save();
|
1137 |
|
1138 |
+
$current_path = isset( $_POST['browse_dir'] ) ? rawurldecode( wp_unslash( $_POST['browse_dir'] ) ) : '';
|
1139 |
|
1140 |
if ( empty( $current_path ) ) {
|
1141 |
$current_path = null;
|
1143 |
|
1144 |
$return = $this->get_excluded( $current_path );
|
1145 |
$out['e'] = $return['e'];
|
1146 |
+
$out['current_browse_dir'] = isset( $_POST['browse_dir'] ) ? wp_unslash( $_POST['browse_dir'] ) : '';
|
1147 |
|
1148 |
return $out;
|
|
|
1149 |
}
|
1150 |
|
1151 |
+
/**
|
1152 |
+
* Remove exclusion rule.
|
1153 |
+
*
|
1154 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
1155 |
+
*
|
1156 |
+
* @return array Action result.
|
1157 |
+
*/
|
1158 |
+
public function hmbkp_remove_exclude_rule() {
|
1159 |
|
1160 |
if ( ! isset( $_POST['remove_rule'] ) || empty( $_POST['remove_rule'] ) ) {
|
1161 |
+
return array( 'error' => __( 'Empty exclude directory path.', 'mainwp-child' ) );
|
1162 |
}
|
1163 |
|
1164 |
$schedule_id = $this->check_schedule();
|
1165 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $schedule_id ) );
|
1166 |
|
1167 |
+
$excludes = $schedule->get_excludes();
|
1168 |
+
$exclude_rule_to_remove = stripslashes( sanitize_text_field( wp_unslash( $_POST['remove_rule'] ) ) );
|
1169 |
|
1170 |
+
if ( method_exists( $excludes, 'get_user_excludes' ) ) {
|
1171 |
$schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) );
|
1172 |
+
} else {
|
1173 |
$schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) );
|
1174 |
+
}
|
1175 |
|
1176 |
$schedule->save();
|
1177 |
|
1178 |
+
$current_path = isset( $_POST['browse_dir'] ) ? rawurldecode( wp_unslash( $_POST['browse_dir'] ) ) : '';
|
1179 |
|
1180 |
if ( empty( $current_path ) ) {
|
1181 |
$current_path = null;
|
1184 |
$return = $this->get_excluded( $current_path );
|
1185 |
|
1186 |
$out['e'] = $return['e'];
|
1187 |
+
$out['current_browse_dir'] = isset( $_POST['browse_dir'] ) ? wp_unslash( $_POST['browse_dir'] ) : '';
|
1188 |
|
1189 |
return $out;
|
1190 |
}
|
1191 |
|
1192 |
+
/**
|
1193 |
+
* General exclusion rules.
|
1194 |
+
*
|
1195 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
1196 |
+
*
|
1197 |
+
* @return array Action result.
|
1198 |
+
*/
|
1199 |
+
public function general_exclude_add_rule() {
|
1200 |
+
|
1201 |
+
$sch_id = $this->check_schedule();
|
1202 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) );
|
1203 |
+
|
1204 |
+
$exclude_paths = isset( $_POST['exclude_paths'] ) ? rawurldecode( wp_unslash( $_POST['exclude_paths'] ) ) : '';
|
1205 |
+
$exclude_paths = explode( "\n", $exclude_paths );
|
1206 |
+
if ( is_array( $exclude_paths ) && count( $exclude_paths ) > 0 ) {
|
1207 |
+
foreach ( $exclude_paths as $excl_rule ) {
|
1208 |
+
$excl_rule = trim( $excl_rule );
|
1209 |
+
$excl_rule = trim( $excl_rule, '/' );
|
1210 |
+
|
1211 |
+
if ( empty( $excl_rule ) ) {
|
1212 |
+
continue;
|
1213 |
+
}
|
1214 |
|
1215 |
+
$exclude_rule = ABSPATH . $excl_rule;
|
1216 |
+
$path = realpath( $exclude_rule );
|
1217 |
+
if ( false !== $path ) {
|
1218 |
+
$schedule->set_excludes( $exclude_rule, true );
|
1219 |
+
$schedule->save();
|
1220 |
+
}
|
1221 |
+
}
|
1222 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1223 |
|
1224 |
+
$un_exclude_paths = isset( $_POST['un_exclude_paths'] ) ? rawurldecode( wp_unslash( $_POST['un_exclude_paths'] ) ) : '';
|
1225 |
+
$un_exclude_paths = explode( "\n", $un_exclude_paths );
|
|
|
|
|
1226 |
|
1227 |
+
if ( is_array( $un_exclude_paths ) && count( get_user_excludes ) > 0 ) {
|
1228 |
+
foreach ( $un_exclude_paths as $exclude_rule_to_remove ) {
|
1229 |
+
$exclude_rule_to_remove = trim( $exclude_rule_to_remove );
|
1230 |
+
$exclude_rule_to_remove = trim( $exclude_rule_to_remove, '/' );
|
1231 |
|
1232 |
+
if ( empty( $exclude_rule_to_remove ) ) {
|
1233 |
+
continue;
|
1234 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1235 |
|
1236 |
+
$excludes = $schedule->get_excludes();
|
1237 |
+
if ( method_exists( $excludes, 'get_user_excludes' ) ) {
|
1238 |
+
$schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) );
|
1239 |
+
} else {
|
1240 |
+
$schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) );
|
1241 |
+
}
|
1242 |
+
$schedule->save();
|
1243 |
+
}
|
1244 |
+
}
|
1245 |
|
1246 |
+
return array( 'result' => 'SUCCESS' );
|
1247 |
+
}
|
1248 |
|
1249 |
+
/**
|
1250 |
+
* Update backup schedule.
|
1251 |
+
*
|
1252 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
1253 |
+
*
|
1254 |
+
* @return array Action result.
|
1255 |
+
*/
|
1256 |
+
public function update_schedule() {
|
1257 |
+
$sch_id = isset( $_POST['schedule_id'] ) ? sanitize_text_field( rawurldecode( wp_unslash( $_POST['schedule_id'] ) ) ) : 0;
|
1258 |
+
$options = isset( $_POST['options'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['options'] ) ) ) : false; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
1259 |
|
1260 |
if ( ! is_array( $options ) || empty( $options ) || empty( $sch_id ) ) {
|
1261 |
+
return array( 'error' => __( 'Schedule data', 'mainwp-child' ) );
|
1262 |
}
|
1263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1264 |
$filter_opts = array(
|
1265 |
'type',
|
1266 |
'email',
|
1281 |
}
|
1282 |
|
1283 |
update_option( 'hmbkp_schedule_' . $sch_id, $options );
|
1284 |
+
delete_transient( 'hmbkp_schedules' );
|
1285 |
$out['result'] = 'SUCCESS';
|
1286 |
} else {
|
1287 |
$out['result'] = 'NOTCHANGE';
|
1288 |
}
|
1289 |
|
1290 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) );
|
1291 |
|
1292 |
if ( ! empty( $options['reoccurrence'] ) && ! empty( $options['schedule_start_time'] ) ) {
|
1293 |
+
// Calculate the start time depending on the recurrence.
|
1294 |
$start_time = $options['schedule_start_time'];
|
1295 |
if ( $start_time ) {
|
1296 |
$schedule->set_schedule_start_time( $start_time );
|
1305 |
return $out;
|
1306 |
}
|
1307 |
|
1308 |
+
/**
|
1309 |
+
* Save all backup schedules.
|
1310 |
+
*
|
1311 |
+
* @used-by MainWP_Child_Back_Up_WordPress::action() Fire off certain BackUpWordPress plugin actions.
|
1312 |
+
*
|
1313 |
+
* @return array Action result.
|
1314 |
+
*/
|
1315 |
public function save_all_schedules() {
|
1316 |
+
$schedules = isset( $_POST['all_schedules'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['all_schedules'] ) ) ) : false; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
1317 |
|
1318 |
if ( ! is_array( $schedules ) || empty( $schedules ) ) {
|
1319 |
+
return array( 'error' => __( 'Schedule data', 'mainwp-child' ) );
|
1320 |
}
|
1321 |
|
1322 |
$out = array();
|
1323 |
+
foreach ( $schedules as $sch_id => $sch ) {
|
1324 |
+
if ( empty( $sch_id ) || ! isset( $sch['options'] ) || ! is_array( $sch['options'] ) ) {
|
1325 |
continue;
|
1326 |
+
}
|
1327 |
+
$options = $sch['options'];
|
1328 |
$filter_opts = array(
|
1329 |
'type',
|
1330 |
'email',
|
1344 |
update_option( 'hmbkp_schedule_' . $sch_id, $options );
|
1345 |
}
|
1346 |
|
1347 |
+
$schedule = new \HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) );
|
1348 |
|
1349 |
if ( ! empty( $options['reoccurrence'] ) && ! empty( $options['schedule_start_time'] ) ) {
|
1350 |
+
// Calculate the start time depending on the recurrence.
|
1351 |
$start_time = $options['schedule_start_time'];
|
1352 |
if ( $start_time ) {
|
1353 |
$schedule->set_schedule_start_time( $start_time );
|
1359 |
}
|
1360 |
$out['result'] = 'SUCCESS';
|
1361 |
}
|
1362 |
+
delete_transient( 'hmbkp_schedules' );
|
1363 |
return $out;
|
1364 |
}
|
1365 |
|
1366 |
+
/**
|
1367 |
+
* Check if the BacupWordPress plugin is activated.
|
1368 |
+
*
|
1369 |
+
* @return bool Return true if the plugin is activated, false if not.
|
1370 |
+
*/
|
1371 |
+
public static function is_activated() {
|
1372 |
+
if ( ! defined( 'HMBKP_PLUGIN_PATH' ) || ! class_exists( '\HM\BackUpWordPress\Plugin' ) ) {
|
1373 |
return false;
|
1374 |
}
|
1375 |
|
1376 |
return true;
|
1377 |
}
|
1378 |
|
1379 |
+
/**
|
1380 |
+
* Remove the BackupWordPress plugin from the list of all plugins when the plugin is hidden.
|
1381 |
+
*
|
1382 |
+
* @param array $plugins Array containing all installed plugins.
|
1383 |
+
*
|
1384 |
+
* @return array $plugins Array containing all installed plugins without the BackupWordPress.
|
1385 |
+
*/
|
1386 |
public function all_plugins( $plugins ) {
|
1387 |
foreach ( $plugins as $key => $value ) {
|
1388 |
$plugin_slug = basename( $key, '.php' );
|
1394 |
return $plugins;
|
1395 |
}
|
1396 |
|
1397 |
+
/**
|
1398 |
+
* Remove the BackupWordPress menu item when the plugin is hidden.
|
1399 |
+
*
|
1400 |
+
* @uses wp_safe_redirect() Performs a safe (local) redirect, using wp_redirect().
|
1401 |
+
* @see https://developer.wordpress.org/reference/functions/wp_safe_redirect/
|
1402 |
+
*
|
1403 |
+
* @uses get_option() Retrieves an option value based on an option name.
|
1404 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
1405 |
+
*/
|
1406 |
public function remove_menu() {
|
1407 |
+
|
1408 |
+
/**
|
1409 |
+
* Submenu array.
|
1410 |
+
*
|
1411 |
+
* @global object
|
1412 |
+
*/
|
1413 |
global $submenu;
|
1414 |
+
|
1415 |
if ( isset( $submenu['tools.php'] ) ) {
|
1416 |
foreach ( $submenu['tools.php'] as $index => $item ) {
|
1417 |
if ( 'backupwordpress' === $item[2] ) {
|
1421 |
}
|
1422 |
}
|
1423 |
|
1424 |
+
$pos = isset( $_SERVER['REQUEST_URI'] ) ? stripos( wp_unslash( $_SERVER['REQUEST_URI'] ), 'tools.php?page=backupwordpress' ) : false;
|
1425 |
if ( false !== $pos ) {
|
1426 |
+
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
1427 |
exit();
|
1428 |
}
|
1429 |
}
|
1430 |
}
|
|
class/class-mainwp-child-back-wp-up.php
CHANGED
@@ -1,11 +1,13 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
|
|
|
|
4 |
*
|
5 |
* Credits
|
6 |
*
|
7 |
* Plugin-Name: BackWPup
|
8 |
-
* Plugin
|
9 |
* Author: Inpsyde GmbH
|
10 |
* Author URI: http://inpsyde.com
|
11 |
* License: GPLv3
|
@@ -14,252 +16,342 @@
|
|
14 |
* The code is used for the MainWP BackWPup Extension
|
15 |
* Extension URL: https://mainwp.com/extension/backwpup/
|
16 |
*
|
17 |
-
|
|
|
18 |
|
19 |
-
|
20 |
-
define( 'MAINWP_BACKWPUP_DEVELOPMENT', false );
|
21 |
-
}
|
22 |
|
|
|
|
|
|
|
|
|
|
|
23 |
class MainWP_Child_Back_WP_Up {
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
try {
|
72 |
|
73 |
if ( is_plugin_active( 'backwpup-pro/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php' ) ) {
|
74 |
$file_path1 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php';
|
75 |
$file_path2 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/Pro/class-pro.php';
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
require_once
|
84 |
-
require_once( $file_path2 );
|
85 |
$this->is_backwpup_installed = true;
|
86 |
$this->is_backwpup_pro = true;
|
87 |
-
}
|
88 |
$file_path = plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php';
|
89 |
-
MainWP_Helper::check_files_exists(array( $file_path ));
|
90 |
-
require_once
|
91 |
$this->is_backwpup_installed = true;
|
92 |
}
|
93 |
|
94 |
-
if ($this->is_backwpup_installed) {
|
95 |
-
MainWP_Helper::check_classes_exists('BackWPup');
|
96 |
-
MainWP_Helper::check_methods('get_instance');
|
97 |
-
BackWPup::get_instance();
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
|
102 |
}
|
103 |
-
} catch ( Exception $e) {
|
104 |
-
// do not exit()
|
105 |
$this->is_backwpup_installed = false;
|
106 |
}
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
-
|
114 |
-
}
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
} else {
|
125 |
-
MainWP_Helper::write( array( 'error' => 'Missing information array inside fatal_error' ) );
|
126 |
-
}
|
127 |
-
}
|
128 |
|
129 |
-
|
|
|
|
|
130 |
|
131 |
-
|
|
|
|
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
break;
|
141 |
-
|
142 |
-
case 'backwpup_insert_or_update_jobs':
|
143 |
-
$information = $this->insert_or_update_jobs();
|
144 |
-
break;
|
145 |
-
|
146 |
-
case 'backwpup_insert_or_update_jobs_global':
|
147 |
-
$information = $this->insert_or_update_jobs_global();
|
148 |
-
break;
|
149 |
-
|
150 |
-
case 'backwpup_get_child_tables':
|
151 |
-
$information = $this->get_child_tables();
|
152 |
-
break;
|
153 |
-
|
154 |
-
case 'backwpup_get_job_files':
|
155 |
-
$information = $this->get_job_files();
|
156 |
-
break;
|
157 |
-
|
158 |
-
case 'backwpup_destination_email_check_email':
|
159 |
-
$information = $this->destination_email_check_email();
|
160 |
-
break;
|
161 |
-
|
162 |
-
case 'backwpup_backup_now':
|
163 |
-
$information = $this->backup_now();
|
164 |
-
break;
|
165 |
-
|
166 |
-
case 'backwpup_ajax_working':
|
167 |
-
$information = $this->ajax_working();
|
168 |
-
break;
|
169 |
-
|
170 |
-
case 'backwpup_backup_abort':
|
171 |
-
$information = $this->backup_abort();
|
172 |
-
break;
|
173 |
-
|
174 |
-
case 'backwpup_tables':
|
175 |
-
$information = $this->tables();
|
176 |
-
break;
|
177 |
-
|
178 |
-
case 'backwpup_view_log':
|
179 |
-
$information = $this->view_log();
|
180 |
-
break;
|
181 |
-
|
182 |
-
case 'backwpup_delete_log':
|
183 |
-
$information = $this->delete_log();
|
184 |
-
break;
|
185 |
-
|
186 |
-
case 'backwpup_delete_job':
|
187 |
-
$information = $this->delete_job();
|
188 |
-
break;
|
189 |
-
|
190 |
-
case 'backwpup_delete_backup':
|
191 |
-
$information = $this->delete_backup();
|
192 |
-
break;
|
193 |
-
|
194 |
-
case 'backwpup_information':
|
195 |
-
$information = $this->information();
|
196 |
-
break;
|
197 |
-
|
198 |
-
case 'backwpup_wizard_system_scan':
|
199 |
-
$information = $this->wizard_system_scan();
|
200 |
-
break;
|
201 |
-
|
202 |
-
case 'backwpup_is_pro':
|
203 |
-
$information = array( 'is_pro' => $this->is_backwpup_pro );
|
204 |
-
break;
|
205 |
-
|
206 |
-
case 'backwpup_show_hide':
|
207 |
-
$information = $this->show_hide();
|
208 |
-
break;
|
209 |
-
|
210 |
-
default:
|
211 |
-
$information = array( 'error' => __( 'Wrong action.', $this->plugin_translate ) );
|
212 |
-
}
|
213 |
-
}
|
214 |
-
|
215 |
-
MainWP_Child_Back_WP_Up::$information = $information;
|
216 |
-
exit();
|
217 |
-
}
|
218 |
-
|
219 |
-
public function init() {
|
220 |
-
|
221 |
-
if (!$this->is_backwpup_installed)
|
222 |
-
return;
|
223 |
-
|
224 |
-
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
|
225 |
-
|
226 |
-
if ( get_option( 'mainwp_backwpup_hide_plugin' ) === 'hide' ) {
|
227 |
-
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
228 |
-
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
229 |
-
}
|
230 |
-
}
|
231 |
-
|
232 |
-
function do_site_stats() {
|
233 |
-
if (has_action('mainwp_child_reports_log')) {
|
234 |
-
do_action( 'mainwp_child_reports_log', 'backwpup');
|
235 |
-
} else {
|
236 |
-
$this->do_reports_log('backwpup');
|
237 |
-
}
|
238 |
-
}
|
239 |
-
// ok
|
240 |
-
public function do_reports_log($ext = '') {
|
241 |
-
if ( $ext !== 'backwpup' ) return;
|
242 |
-
if (!$this->is_backwpup_installed)
|
243 |
-
return;
|
244 |
|
245 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
|
247 |
-
|
248 |
-
|
249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
|
251 |
-
|
252 |
|
|
|
|
|
|
|
|
|
253 |
$log_folder = get_site_option( 'backwpup_cfg_logfolder' );
|
254 |
-
$log_folder = BackWPup_File::get_absolute_path( $log_folder );
|
255 |
$log_folder = untrailingslashit( $log_folder );
|
256 |
|
257 |
-
//load logs
|
258 |
$logfiles = array();
|
259 |
-
|
260 |
-
|
|
|
261 |
$log_file = $log_folder . '/' . $file;
|
262 |
-
if ( is_file( $log_file ) && is_readable( $log_file ) &&
|
263 |
$logfiles[] = $file;
|
264 |
}
|
265 |
}
|
@@ -268,752 +360,986 @@ class MainWP_Child_Back_WP_Up {
|
|
268 |
|
269 |
$log_items = array();
|
270 |
foreach ( $logfiles as $mtime => $logfile ) {
|
271 |
-
$meta = BackWPup_Job::read_logheader( $log_folder . '/' . $logfile );
|
272 |
-
if (!isset($meta['logtime']) || $meta['logtime'] < $lasttime_logged)
|
273 |
continue;
|
|
|
274 |
|
275 |
-
if (isset($meta['errors']) && !empty($meta['errors'])) {
|
276 |
-
continue;
|
277 |
}
|
278 |
|
279 |
-
$log_items[$mtime]
|
280 |
-
$log_items[$mtime]['file'] = $logfile;
|
281 |
}
|
282 |
|
283 |
-
if ( !empty( $log_items ) ) {
|
284 |
$job_types = array(
|
285 |
-
'DBDUMP'
|
286 |
-
'FILE'
|
287 |
-
'WPEXP'
|
288 |
-
'WPPLUGIN' => __('Installed plugins list', 'mainwp-child'),
|
289 |
-
'DBCHECK'
|
290 |
);
|
291 |
|
292 |
$new_lasttime_logged = $lasttime_logged;
|
293 |
|
294 |
-
foreach ($log_items as $log) {
|
295 |
-
$backup_time = $log[
|
296 |
-
if ($backup_time < $lasttime_logged) {
|
297 |
-
// small than last backup time then skip
|
298 |
continue;
|
299 |
}
|
300 |
-
$job_job_types = explode('+', $log['type']);
|
301 |
-
$backup_type
|
302 |
-
foreach($job_job_types as $typeid) {
|
303 |
-
if (isset( $job_types[$typeid] )) {
|
304 |
-
$backup_type .= ' + ' . $job_types[$typeid];
|
305 |
}
|
306 |
}
|
307 |
|
308 |
-
if (empty($backup_type)) {
|
309 |
continue;
|
310 |
} else {
|
311 |
-
$backup_type = ltrim($backup_type, ' + ');
|
312 |
}
|
313 |
$message = 'BackWPup backup finished (' . $backup_type . ')';
|
314 |
do_action( 'mainwp_reports_backwpup_backup', $message, $backup_type, $backup_time );
|
315 |
|
316 |
-
if ($new_lasttime_logged < $backup_time)
|
317 |
$new_lasttime_logged = $backup_time;
|
|
|
318 |
}
|
319 |
|
320 |
-
if ($new_lasttime_logged > $lasttime_logged ) {
|
321 |
-
|
322 |
}
|
323 |
}
|
324 |
-
} catch (Exception $ex) {
|
325 |
-
|
326 |
}
|
327 |
-
|
328 |
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
$information['syncBackwpupData'] = array(
|
335 |
-
'lastbackup' => $lastbackup
|
336 |
);
|
337 |
-
} catch(Exception $e) {
|
338 |
-
|
339 |
}
|
340 |
-
|
341 |
return $information;
|
342 |
}
|
343 |
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
364 |
$can_do_dest = $dest_class->file_get_list( $jobid . '_' . $dest );
|
365 |
if ( ! empty( $can_do_dest ) ) {
|
366 |
-
$jobdest[
|
367 |
}
|
368 |
}
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
542 |
|
543 |
$dir = get_site_option( 'backwpup_cfg_logfolder' );
|
544 |
-
|
545 |
|
546 |
-
|
547 |
-
|
548 |
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
|
556 |
-
|
557 |
|
558 |
-
|
559 |
|
560 |
-
|
561 |
-
|
562 |
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
567 |
|
568 |
-
|
569 |
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
|
575 |
-
|
576 |
-
|
577 |
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
582 |
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
|
587 |
-
|
588 |
-
|
589 |
|
590 |
-
|
591 |
|
592 |
-
|
593 |
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
|
598 |
-
|
599 |
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
|
604 |
-
|
605 |
-
|
606 |
-
|
|
|
|
|
|
|
607 |
|
608 |
-
|
609 |
-
|
|
|
|
|
|
|
610 |
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
|
|
|
|
|
|
|
|
|
|
615 |
|
616 |
$log_folder = get_site_option( 'backwpup_cfg_logfolder' );
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
|
638 |
-
|
639 |
-
|
|
|
|
|
|
|
640 |
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
645 |
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
|
650 |
-
|
651 |
-
|
652 |
|
653 |
-
|
654 |
|
655 |
-
|
656 |
|
657 |
-
|
658 |
-
|
659 |
$log_folder = get_site_option( 'backwpup_cfg_logfolder' );
|
660 |
-
$log_folder = BackWPup_File::get_absolute_path( $log_folder );
|
661 |
$log_folder = untrailingslashit( $log_folder );
|
662 |
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
foreach ( $output->items as $key ) {
|
750 |
-
$temp_array = $key;
|
751 |
-
$temp_array['downloadurl'] = str_replace( array(
|
752 |
-
'&',
|
753 |
-
network_admin_url( 'admin.php' ) . '?page=backwpupbackups&action=',
|
754 |
-
), array(
|
755 |
-
'&',
|
756 |
-
admin_url( 'admin-ajax.php' ) . '?action=mainwp_backwpup_download_backup&type=',
|
757 |
-
), $temp_array['downloadurl'] . '&_wpnonce=' . $this->create_nonce_without_session( 'mainwp_download_backup' ) );
|
758 |
-
|
759 |
-
$temp_array['downloadurl_id'] = '/wp-admin/admin.php?page=backwpupbackups';
|
760 |
-
if ( preg_match( '/.*&jobid=([^&]+)&.*/is', $temp_array['downloadurl'], $matches )) {
|
761 |
-
if ( !empty( $matches[1] ) && is_numeric( $matches[1] ) ) {
|
762 |
-
$temp_array['downloadurl_id'] .= '&download_click_id=' . $matches[1];
|
763 |
-
}
|
764 |
-
error_log('did match' . print_r($matches, true));
|
765 |
-
} else {
|
766 |
-
error_log('not match');
|
767 |
-
}
|
768 |
-
|
769 |
-
$temp_array['website_id'] = $website_id;
|
770 |
-
|
771 |
-
if ( ! isset( $without_dupes[ $temp_array['file'] ] ) ) {
|
772 |
-
$array[] = $temp_array;
|
773 |
-
$without_dupes[ $temp_array['file'] ] = 1;
|
774 |
-
}
|
775 |
-
}
|
776 |
-
} else {
|
777 |
-
foreach ( $output->items as $key => $val ) {
|
778 |
-
$array[] = $val;
|
779 |
-
}
|
780 |
-
}
|
781 |
-
}
|
782 |
-
|
783 |
-
return array( 'success' => 1, 'response' => $array );
|
784 |
-
}
|
785 |
-
|
786 |
-
public function init_download_backup() {
|
787 |
-
if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'backwpupbackups' || !isset( $_GET['download_click_id'] ) || empty( $_GET['download_click_id'] )) {
|
788 |
-
return;
|
789 |
-
}
|
790 |
-
?>
|
791 |
-
<script type="text/javascript">
|
792 |
-
document.addEventListener("DOMContentLoaded", function(event) {
|
793 |
-
var downloadLink = document.querySelector( 'a.backup-download-link[data-jobid="<?php echo intval($_GET['download_click_id']); ?>"' );
|
794 |
-
if (typeof(downloadLink) !== 'undefined' && downloadLink !== null) {
|
795 |
-
downloadLink.click();
|
796 |
}
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
die( '-4' );
|
820 |
-
}
|
821 |
|
822 |
-
|
823 |
-
} else {
|
824 |
-
die( '-5' );
|
825 |
-
}
|
826 |
|
827 |
-
|
828 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
829 |
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
}
|
836 |
-
|
837 |
-
$i = wp_nonce_tick();
|
838 |
-
|
839 |
-
return substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 );
|
840 |
-
}
|
841 |
-
|
842 |
-
protected function verify_nonce_without_session( $nonce, $action = - 1 ) {
|
843 |
-
$nonce = (string) $nonce;
|
844 |
-
$user = wp_get_current_user();
|
845 |
-
$uid = (int) $user->ID;
|
846 |
-
if ( ! $uid ) {
|
847 |
-
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
|
848 |
-
}
|
849 |
-
|
850 |
-
if ( empty( $nonce ) ) {
|
851 |
-
return false;
|
852 |
-
}
|
853 |
-
|
854 |
-
$i = wp_nonce_tick();
|
855 |
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
902 |
|
903 |
-
|
904 |
|
905 |
-
|
906 |
-
|
907 |
-
|
|
|
908 |
|
909 |
-
|
910 |
-
|
|
|
|
|
911 |
|
912 |
-
|
913 |
-
|
914 |
|
915 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
916 |
|
917 |
-
|
|
|
|
|
918 |
|
919 |
-
|
920 |
-
BackWPup_Page_Jobs::load();
|
921 |
-
ob_end_clean();
|
922 |
|
923 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
924 |
|
925 |
-
|
926 |
-
|
927 |
-
} else {
|
928 |
-
$job_object = BackWPup_Job::get_working_data();
|
929 |
-
if ( is_object( $job_object ) ) {
|
930 |
-
return array(
|
931 |
-
'success' => 1,
|
932 |
-
'response' => $output['message'],
|
933 |
-
'logfile' => basename( $job_object->logfile ),
|
934 |
-
);
|
935 |
-
} else {
|
936 |
-
return array( 'success' => 1, 'response' => $output['message'] );
|
937 |
-
}
|
938 |
-
}
|
939 |
-
}
|
940 |
|
941 |
-
|
942 |
-
|
943 |
-
|
|
|
|
|
|
|
|
|
|
|
944 |
|
945 |
-
|
|
|
946 |
|
947 |
-
|
|
|
948 |
|
949 |
-
|
950 |
-
BackWPup_Page_Jobs::load();
|
951 |
-
ob_end_clean();
|
952 |
|
953 |
-
|
954 |
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
}
|
961 |
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
969 |
|
970 |
-
|
971 |
-
|
972 |
|
973 |
-
|
974 |
-
|
975 |
|
976 |
-
|
977 |
-
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
978 |
-
}
|
979 |
-
}
|
980 |
|
981 |
-
|
982 |
-
if ( class_exists( 'BackWPup_Pro_Wizard_SystemTest' ) ) {
|
983 |
-
ob_start();
|
984 |
|
985 |
-
|
986 |
-
|
|
|
987 |
|
988 |
-
|
989 |
|
990 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
991 |
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
997 |
|
998 |
-
|
999 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1000 |
|
1001 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1002 |
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
$emailsecure = ( isset( $settings['emailsecure'] ) ? $settings['emailsecure'] : '' );
|
1008 |
-
$emailuser = ( isset( $settings['emailuser'] ) ? $settings['emailuser'] : '' );
|
1009 |
-
$emailpass = ( isset( $settings['emailpass'] ) ? $settings['emailpass'] : '' );
|
1010 |
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1014 |
|
1015 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1016 |
global $phpmailer;
|
|
|
1017 |
if ( ! is_object( $phpmailer ) || ! $phpmailer instanceof PHPMailer ) {
|
1018 |
if ( file_exists( ABSPATH . WPINC . '/PHPMailer/PHPMailer.php' )) {
|
1019 |
require ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
|
@@ -1038,502 +1364,611 @@ class MainWP_Child_Back_WP_Up {
|
|
1038 |
}
|
1039 |
}
|
1040 |
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
|
1221 |
-
|
1222 |
-
|
1223 |
-
|
1224 |
-
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
1311 |
-
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
1315 |
-
|
1316 |
-
|
1317 |
-
|
1318 |
-
|
1319 |
-
|
1320 |
-
|
1321 |
-
|
1322 |
-
|
1323 |
-
|
1324 |
-
|
1325 |
-
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
|
1331 |
-
|
1332 |
-
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
1349 |
-
|
1350 |
-
|
1351 |
-
|
1352 |
-
|
1353 |
-
|
1354 |
-
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
-
|
1359 |
-
|
1360 |
-
|
1361 |
-
|
1362 |
-
|
1363 |
-
|
1364 |
-
|
1365 |
-
|
1366 |
-
|
1367 |
-
|
1368 |
-
|
1369 |
-
|
1370 |
-
|
1371 |
-
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
1376 |
-
|
1377 |
-
|
1378 |
-
|
1379 |
-
|
1380 |
-
|
1381 |
-
|
1382 |
-
|
1383 |
-
|
1384 |
-
|
1385 |
-
|
1386 |
-
|
1387 |
-
|
1388 |
-
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
|
1399 |
-
|
1400 |
-
|
1401 |
-
|
1402 |
-
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
|
1414 |
-
|
1415 |
-
|
1416 |
-
|
1417 |
-
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
|
1423 |
-
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
|
1429 |
-
|
1430 |
-
|
1431 |
-
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
1435 |
-
|
1436 |
-
|
1437 |
-
|
1438 |
-
|
1439 |
-
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
-
|
1445 |
-
|
1446 |
-
|
1447 |
-
|
1448 |
-
|
1449 |
-
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
-
|
1455 |
-
|
1456 |
-
|
1457 |
-
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
|
1462 |
-
|
1463 |
-
|
1464 |
-
|
1465 |
-
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
-
|
1470 |
-
|
1471 |
-
|
1472 |
-
|
1473 |
-
|
1474 |
-
|
1475 |
-
|
1476 |
-
|
1477 |
-
|
1478 |
-
|
1479 |
-
|
1480 |
-
|
1481 |
-
|
1482 |
-
|
1483 |
-
|
1484 |
-
|
1485 |
-
|
1486 |
-
|
1487 |
-
|
1488 |
-
|
1489 |
-
|
1490 |
-
|
1491 |
-
|
1492 |
-
|
1493 |
-
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
|
1498 |
-
|
1499 |
-
|
1500 |
-
|
1501 |
-
|
1502 |
-
|
1503 |
-
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
1507 |
-
|
1508 |
-
|
1509 |
-
|
1510 |
-
|
1511 |
-
|
1512 |
-
|
1513 |
-
|
1514 |
-
|
1515 |
-
|
1516 |
-
|
1517 |
-
|
1518 |
-
|
1519 |
-
|
1520 |
-
|
1521 |
-
|
1522 |
-
|
1523 |
-
|
1524 |
-
|
1525 |
-
|
1526 |
-
|
1527 |
-
|
1528 |
-
|
1529 |
-
|
1530 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1531 |
}
|
1532 |
|
1533 |
-
|
1534 |
-
|
1535 |
-
|
1536 |
-
|
1537 |
-
|
1538 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1539 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child BackWP UP
|
4 |
+
*
|
5 |
+
* This file handles specific action for the MainWP BackWPup Extension.
|
6 |
*
|
7 |
* Credits
|
8 |
*
|
9 |
* Plugin-Name: BackWPup
|
10 |
+
* Plugin-URI: http://backwpup.com
|
11 |
* Author: Inpsyde GmbH
|
12 |
* Author URI: http://inpsyde.com
|
13 |
* License: GPLv3
|
16 |
* The code is used for the MainWP BackWPup Extension
|
17 |
* Extension URL: https://mainwp.com/extension/backwpup/
|
18 |
*
|
19 |
+
* @package MainWP\Child
|
20 |
+
*/
|
21 |
|
22 |
+
// phpcs:disable -- third party credit.
|
|
|
|
|
23 |
|
24 |
+
namespace MainWP\Child;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Class MainWP_Child_Back_WP_Up
|
28 |
+
*/
|
29 |
class MainWP_Child_Back_WP_Up {
|
30 |
+
|
31 |
+
/**
|
32 |
+
* @var bool Whether or not BackWPup plugin is installed. Default: false.
|
33 |
+
*/
|
34 |
+
public $is_backwpup_installed = false;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @var bool Whether or not BackWPup is Pro version. Default: false.
|
38 |
+
*/
|
39 |
+
public $is_backwpup_pro = false;
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @var string Plugin slug translation string.
|
43 |
+
*/
|
44 |
+
public $plugin_translate = 'mainwp-backwpup-extension';
|
45 |
+
|
46 |
+
/**
|
47 |
+
* @static
|
48 |
+
* @var null Holds the Public static instance of MainWP_Child_Back_WP_Up
|
49 |
+
*/
|
50 |
+
public static $instance = null;
|
51 |
+
|
52 |
+
/** @var string Software version. */
|
53 |
+
protected $software_version = '0.1';
|
54 |
+
|
55 |
+
/** @var array Returned response array for MainWP BackWPup Extension actions. */
|
56 |
+
public static $information = array();
|
57 |
+
|
58 |
+
/** @var string[][] backwpup_cfg variables. */
|
59 |
+
protected $exclusions = array(
|
60 |
+
'cron' => array(
|
61 |
+
'cronminutes',
|
62 |
+
'cronhours',
|
63 |
+
'cronmday',
|
64 |
+
'cronmon',
|
65 |
+
'cronwday',
|
66 |
+
'moncronminutes',
|
67 |
+
'moncronhours',
|
68 |
+
'moncronmday',
|
69 |
+
'weekcronminutes',
|
70 |
+
'weekcronhours',
|
71 |
+
'weekcronwday',
|
72 |
+
'daycronminutes',
|
73 |
+
'daycronhours',
|
74 |
+
'hourcronminutes',
|
75 |
+
'cronbtype',
|
76 |
+
),
|
77 |
+
'dest-EMAIL' => array( 'emailpass' ),
|
78 |
+
'dest-DBDUMP' => array( 'dbdumpspecialsetalltables' ),
|
79 |
+
'dest-FTP' => array( 'ftppass' ),
|
80 |
+
'dest-S3' => array( 's3secretkey' ),
|
81 |
+
'dest-MSAZURE' => array( 'msazurekey' ),
|
82 |
+
'dest-SUGARSYNC' => array( 'sugaremail', 'sugarpass', 'sugarrefreshtoken' ),
|
83 |
+
'dest-GDRIVE' => array( 'gdriverefreshtoken' ),
|
84 |
+
'dest-RSC' => array( 'rscapikey' ),
|
85 |
+
'dest-GLACIER' => array( 'glaciersecretkey' ),
|
86 |
+
);
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Create a public static instance of MainWP_Child_Back_WP_Up.
|
90 |
+
*
|
91 |
+
* @return MainWP_Child_Back_WP_Up|null
|
92 |
+
*/
|
93 |
+
public static function instance() {
|
94 |
+
if ( null == self::$instance ) {
|
95 |
+
self::$instance = new self();
|
96 |
+
}
|
97 |
+
|
98 |
+
return self::$instance;
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* MainWP_Child_Back_WP_Up constructor.
|
103 |
+
*
|
104 |
+
* Run any time the class is called.
|
105 |
+
*
|
106 |
+
* @uses MainWP_Helper::check_files_exists()
|
107 |
+
* @uses MainWP_Helper::check_classes_exists()
|
108 |
+
* @uses MainWP_Helper::check_methods()
|
109 |
+
* @uses \BackWPup::get_instance()
|
110 |
+
* @uses \Exception
|
111 |
+
*/
|
112 |
+
public function __construct() {
|
113 |
+
|
114 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
115 |
|
116 |
try {
|
117 |
|
118 |
if ( is_plugin_active( 'backwpup-pro/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php' ) ) {
|
119 |
$file_path1 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php';
|
120 |
$file_path2 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/Pro/class-pro.php';
|
121 |
+
|
122 |
+
if ( ! file_exists( $file_path2 ) ) {
|
123 |
+
$file_path2 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/pro/class-pro.php';
|
124 |
+
}
|
125 |
+
|
126 |
+
MainWP_Helper::check_files_exists( array( $file_path1, $file_path2 ) );
|
127 |
+
require_once $file_path1;
|
128 |
+
require_once $file_path2;
|
|
|
129 |
$this->is_backwpup_installed = true;
|
130 |
$this->is_backwpup_pro = true;
|
131 |
+
} elseif ( is_plugin_active( 'backwpup/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php' ) ) {
|
132 |
$file_path = plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php';
|
133 |
+
MainWP_Helper::check_files_exists( array( $file_path ) );
|
134 |
+
require_once $file_path;
|
135 |
$this->is_backwpup_installed = true;
|
136 |
}
|
137 |
|
138 |
+
if ( $this->is_backwpup_installed ) {
|
139 |
+
MainWP_Helper::check_classes_exists( '\BackWPup' );
|
140 |
+
MainWP_Helper::check_methods( 'get_instance' );
|
141 |
+
\BackWPup::get_instance();
|
142 |
|
143 |
+
add_action( 'admin_init', array( $this, 'init_download_backup' ) );
|
144 |
+
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
|
|
145 |
}
|
146 |
+
} catch ( \Exception $e ) {
|
|
|
147 |
$this->is_backwpup_installed = false;
|
148 |
}
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* MainWP BackWPup fatal error handler.
|
153 |
+
*
|
154 |
+
* @uses MainWP_Child_Back_WP_Up::$information
|
155 |
+
* @uses MainWP_Helper::write()
|
156 |
+
*/
|
157 |
+
public static function mainwp_backwpup_handle_fatal_error() {
|
158 |
+
|
159 |
+
$error = error_get_last();
|
160 |
+
$info = self::$information;
|
161 |
+
|
162 |
+
if ( isset( $error['type'] ) && E_ERROR === $error['type'] && isset( $error['message'] ) ) {
|
163 |
+
MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
|
164 |
+
} elseif ( ! empty( $info ) ) {
|
165 |
+
MainWP_Helper::write( self::$information );
|
166 |
+
} else {
|
167 |
+
MainWP_Helper::write( array( 'error' => 'Missing information array inside fatal_error' ) );
|
168 |
+
}
|
169 |
+
}
|
170 |
|
171 |
+
/**
|
172 |
+
* MainWP BackWPup Extension actions.
|
173 |
+
*
|
174 |
+
* @uses MainWP_Child_Back_WP_Up::update_settings()
|
175 |
+
* @uses MainWP_Child_Back_WP_Up::insert_or_update_jobs()
|
176 |
+
* @uses MainWP_Child_Back_WP_Up::insert_or_update_jobs_global()
|
177 |
+
* @uses MainWP_Child_Back_WP_Up::get_child_tables()
|
178 |
+
* @uses MainWP_Child_Back_WP_Up::get_job_files()
|
179 |
+
* @uses MainWP_Child_Back_WP_Up::destination_email_check_email()
|
180 |
+
* @uses MainWP_Child_Back_WP_Up::backup_now()
|
181 |
+
* @uses MainWP_Child_Back_WP_Up::ajax_working()
|
182 |
+
* @uses MainWP_Child_Back_WP_Up::backup_abort()
|
183 |
+
* @uses MainWP_Child_Back_WP_Up::tables()
|
184 |
+
* @uses MainWP_Child_Back_WP_Up::view_log()
|
185 |
+
* @uses MainWP_Child_Back_WP_Up::delete_log()
|
186 |
+
* @uses MainWP_Child_Back_WP_Up::delete_job()
|
187 |
+
* @uses MainWP_Child_Back_WP_Up::delete_backup()
|
188 |
+
* @uses MainWP_Child_Back_WP_Up::wizard_system_scan()
|
189 |
+
* @uses MainWP_Child_Back_WP_Up::is_backwpup_pro()
|
190 |
+
* @uses MainWP_Child_Back_WP_Up::show_hide()
|
191 |
+
* @uses MainWP_Child_Back_WP_Up::$information
|
192 |
+
*/
|
193 |
+
public function action() {
|
194 |
+
if ( ! $this->is_backwpup_installed ) {
|
195 |
+
MainWP_Helper::write( array( 'error' => __( 'Please install BackWPup plugin on child website', 'mainwp-child' ) ) );
|
196 |
+
return;
|
197 |
+
}
|
198 |
+
register_shutdown_function( '\MainWP\Child\MainWP_Child_Back_WP_Up::mainwp_backwpup_handle_fatal_error' );
|
199 |
|
200 |
+
$information = array();
|
|
|
201 |
|
202 |
+
if ( ! isset( $_POST['action'] ) ) {
|
203 |
+
$information = array( 'error' => __( 'Missing action.', 'mainwp-child' ) );
|
204 |
+
} else {
|
205 |
+
$mwp_action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
206 |
+
switch ( $mwp_action ) {
|
207 |
+
case 'backwpup_update_settings':
|
208 |
+
$information = $this->update_settings();
|
209 |
+
break;
|
|
|
|
|
|
|
|
|
210 |
|
211 |
+
case 'backwpup_insert_or_update_jobs':
|
212 |
+
$information = $this->insert_or_update_jobs();
|
213 |
+
break;
|
214 |
|
215 |
+
case 'backwpup_insert_or_update_jobs_global':
|
216 |
+
$information = $this->insert_or_update_jobs_global();
|
217 |
+
break;
|
218 |
|
219 |
+
case 'backwpup_get_child_tables':
|
220 |
+
$information = $this->get_child_tables();
|
221 |
+
break;
|
222 |
|
223 |
+
case 'backwpup_get_job_files':
|
224 |
+
$information = $this->get_job_files();
|
225 |
+
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
+
case 'backwpup_destination_email_check_email':
|
228 |
+
$information = $this->destination_email_check_email();
|
229 |
+
break;
|
230 |
+
|
231 |
+
case 'backwpup_backup_now':
|
232 |
+
$information = $this->backup_now();
|
233 |
+
break;
|
234 |
+
|
235 |
+
case 'backwpup_ajax_working':
|
236 |
+
$information = $this->ajax_working();
|
237 |
+
break;
|
238 |
+
|
239 |
+
case 'backwpup_backup_abort':
|
240 |
+
$information = $this->backup_abort();
|
241 |
+
break;
|
242 |
+
|
243 |
+
case 'backwpup_tables':
|
244 |
+
$information = $this->tables();
|
245 |
+
break;
|
246 |
+
|
247 |
+
case 'backwpup_view_log':
|
248 |
+
$information = $this->view_log();
|
249 |
+
break;
|
250 |
+
|
251 |
+
case 'backwpup_delete_log':
|
252 |
+
$information = $this->delete_log();
|
253 |
+
break;
|
254 |
+
|
255 |
+
case 'backwpup_delete_job':
|
256 |
+
$information = $this->delete_job();
|
257 |
+
break;
|
258 |
+
|
259 |
+
case 'backwpup_delete_backup':
|
260 |
+
$information = $this->delete_backup();
|
261 |
+
break;
|
262 |
+
|
263 |
+
case 'backwpup_information':
|
264 |
+
$information = $this->information();
|
265 |
+
break;
|
266 |
+
|
267 |
+
case 'backwpup_wizard_system_scan':
|
268 |
+
$information = $this->wizard_system_scan();
|
269 |
+
break;
|
270 |
+
|
271 |
+
case 'backwpup_is_pro':
|
272 |
+
$information = array( 'is_pro' => $this->is_backwpup_pro );
|
273 |
+
break;
|
274 |
+
|
275 |
+
case 'backwpup_show_hide':
|
276 |
+
$information = $this->show_hide();
|
277 |
+
break;
|
278 |
+
|
279 |
+
default:
|
280 |
+
$information = array( 'error' => __( 'Wrong action.', 'mainwp-child' ) );
|
281 |
+
}
|
282 |
+
}
|
283 |
+
|
284 |
+
self::$information = $information;
|
285 |
+
exit();
|
286 |
+
}
|
287 |
+
|
288 |
+
/**
|
289 |
+
* MainWP BackWPup Extension initiation.
|
290 |
+
*/
|
291 |
+
public function init() {
|
292 |
+
|
293 |
+
if ( ! $this->is_backwpup_installed ) {
|
294 |
+
return;
|
295 |
+
}
|
296 |
+
|
297 |
+
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
|
298 |
+
|
299 |
+
if ( get_option( 'mainwp_backwpup_hide_plugin' ) === 'hide' ) {
|
300 |
+
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
301 |
+
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
302 |
+
}
|
303 |
+
}
|
304 |
+
|
305 |
+
/**
|
306 |
+
* Record BackWPup MainWP Child Reports log.
|
307 |
+
*
|
308 |
+
* @uses MainWP_Child_Back_WP_Up::do_reports_log()
|
309 |
+
*/
|
310 |
+
public function do_site_stats() {
|
311 |
+
if ( has_action( 'mainwp_child_reports_log' ) ) {
|
312 |
+
do_action( 'mainwp_child_reports_log', 'backwpup' );
|
313 |
+
} else {
|
314 |
+
$this->do_reports_log( 'backwpup' );
|
315 |
+
}
|
316 |
+
}
|
317 |
|
318 |
+
/**
|
319 |
+
* Create BackWPup MainWP Client Reports log.
|
320 |
+
*
|
321 |
+
* @param string $ext Extension to create log for.
|
322 |
+
*
|
323 |
+
* @uses MainWP_Child_Back_WP_Up::is_backwpup_installed()
|
324 |
+
* @uses \MainWP\Child\MainWP_Helper::check_classes_exists()
|
325 |
+
* @uses \MainWP\Child\MainWP_Helper::check_methods()
|
326 |
+
* @uses \MainWP\Child\MainWP_Utility::get_lasttime_backup()
|
327 |
+
* @uses \BackWPup_File::get_absolute_path()
|
328 |
+
* @uses \BackWPup_Job::read_logheader()
|
329 |
+
* @uses \Exception
|
330 |
+
*/
|
331 |
+
public function do_reports_log($ext = '' ) {
|
332 |
+
if ( 'backwpup' !== $ext ) {
|
333 |
+
return;
|
334 |
+
}
|
335 |
+
if ( ! $this->is_backwpup_installed ) {
|
336 |
+
return;
|
337 |
+
}
|
338 |
|
339 |
+
try {
|
340 |
|
341 |
+
MainWP_Helper::check_classes_exists( array( '\BackWPup_File', '\BackWPup_Job' ) );
|
342 |
+
MainWP_Helper::check_methods( '\BackWPup_File', array( 'get_absolute_path' ) );
|
343 |
+
MainWP_Helper::check_methods( '\BackWPup_Job', array( 'read_logheader' ) );
|
344 |
+
$lasttime_logged = MainWP_Utility::get_lasttime_backup( 'backwpup' );
|
345 |
$log_folder = get_site_option( 'backwpup_cfg_logfolder' );
|
346 |
+
$log_folder = \BackWPup_File::get_absolute_path( $log_folder );
|
347 |
$log_folder = untrailingslashit( $log_folder );
|
348 |
|
|
|
349 |
$logfiles = array();
|
350 |
+
$dir = opendir( $log_folder );
|
351 |
+
if ( is_readable( $log_folder ) && $dir ) {
|
352 |
+
while ( ( $file = readdir( $dir ) ) !== false ) {
|
353 |
$log_file = $log_folder . '/' . $file;
|
354 |
+
if ( is_file( $log_file ) && is_readable( $log_file ) && false !== strpos( $file, 'backwpup_log_' ) && false !== strpos( $file, '.html' ) ) {
|
355 |
$logfiles[] = $file;
|
356 |
}
|
357 |
}
|
360 |
|
361 |
$log_items = array();
|
362 |
foreach ( $logfiles as $mtime => $logfile ) {
|
363 |
+
$meta = \BackWPup_Job::read_logheader( $log_folder . '/' . $logfile );
|
364 |
+
if ( ! isset( $meta['logtime'] ) || $meta['logtime'] < $lasttime_logged ) {
|
365 |
continue;
|
366 |
+
}
|
367 |
|
368 |
+
if ( isset( $meta['errors'] ) && ! empty( $meta['errors'] ) ) {
|
369 |
+
continue;
|
370 |
}
|
371 |
|
372 |
+
$log_items[ $mtime ] = $meta;
|
373 |
+
$log_items[ $mtime ]['file'] = $logfile;
|
374 |
}
|
375 |
|
376 |
+
if ( ! empty( $log_items ) ) {
|
377 |
$job_types = array(
|
378 |
+
'DBDUMP' => __( 'Database backup', 'mainwp-child' ),
|
379 |
+
'FILE' => __( 'File backup', 'mainwp-child' ),
|
380 |
+
'WPEXP' => __( 'WordPress XML export', 'mainwp-child' ),
|
381 |
+
'WPPLUGIN' => __( 'Installed plugins list', 'mainwp-child' ),
|
382 |
+
'DBCHECK' => __( 'Check database tables', 'mainwp-child' ),
|
383 |
);
|
384 |
|
385 |
$new_lasttime_logged = $lasttime_logged;
|
386 |
|
387 |
+
foreach ( $log_items as $log ) {
|
388 |
+
$backup_time = $log['logtime'];
|
389 |
+
if ( $backup_time < $lasttime_logged ) {
|
|
|
390 |
continue;
|
391 |
}
|
392 |
+
$job_job_types = explode( '+', $log['type'] );
|
393 |
+
$backup_type = '';
|
394 |
+
foreach ( $job_job_types as $typeid ) {
|
395 |
+
if ( isset( $job_types[ $typeid ] ) ) {
|
396 |
+
$backup_type .= ' + ' . $job_types[ $typeid ];
|
397 |
}
|
398 |
}
|
399 |
|
400 |
+
if ( empty( $backup_type ) ) {
|
401 |
continue;
|
402 |
} else {
|
403 |
+
$backup_type = ltrim( $backup_type, ' + ' );
|
404 |
}
|
405 |
$message = 'BackWPup backup finished (' . $backup_type . ')';
|
406 |
do_action( 'mainwp_reports_backwpup_backup', $message, $backup_type, $backup_time );
|
407 |
|
408 |
+
if ( $new_lasttime_logged < $backup_time ) {
|
409 |
$new_lasttime_logged = $backup_time;
|
410 |
+
}
|
411 |
}
|
412 |
|
413 |
+
if ( $new_lasttime_logged > $lasttime_logged ) {
|
414 |
+
MainWP_Utility::update_lasttime_backup( 'backwpup', $new_lasttime_logged ); // to support backup before update feature.
|
415 |
}
|
416 |
}
|
417 |
+
} catch ( \Exception $ex ) {
|
418 |
+
// ok!
|
419 |
}
|
420 |
+
}
|
421 |
|
422 |
+
/**
|
423 |
+
* Sync other data from $data[] and merge with $information[]
|
424 |
+
*
|
425 |
+
* @param array $information Returned response array for MainWP BackWPup Extension actions.
|
426 |
+
* @param array $data Other data to sync to $information array.
|
427 |
+
*
|
428 |
+
* @return array $information Returned information array with both sets of data.
|
429 |
+
*/
|
430 |
+
public function sync_others_data($information, $data = array() ) {
|
431 |
+
if ( isset( $data['syncBackwpupData'] ) && $data['syncBackwpupData'] ) {
|
432 |
+
try {
|
433 |
+
$lastbackup = MainWP_Utility::get_lasttime_backup( 'backwpup' );
|
434 |
$information['syncBackwpupData'] = array(
|
435 |
+
'lastbackup' => $lastbackup,
|
436 |
);
|
437 |
+
} catch ( \Exception $e ) {
|
438 |
+
// ok!
|
439 |
}
|
440 |
+
}
|
441 |
return $information;
|
442 |
}
|
443 |
|
444 |
+
/**
|
445 |
+
* Get backup destinations list.
|
446 |
+
*
|
447 |
+
* @uses MainWP_Helper::check_classes_exists()
|
448 |
+
* @uses MainWP_Helper::check_methods()
|
449 |
+
* @uses \BackWPup_Option::get_job_ids()
|
450 |
+
* @uses \BackWPup::get_registered_destinations()
|
451 |
+
* @uses \BackWPup_Option::get()
|
452 |
+
* @uses \BackWPup::get_destination()
|
453 |
+
* @uses \BackWPup::get_destination::file_get_list()
|
454 |
+
*
|
455 |
+
* @return array $jobdest Backup destination list.
|
456 |
+
* @throws Exception Error Message.
|
457 |
+
*/
|
458 |
+
public function get_destinations_list() {
|
459 |
+
MainWP_Helper::check_classes_exists( array( '\BackWPup', '\BackWPup_Option' ) );
|
460 |
+
MainWP_Helper::check_methods( '\BackWPup', array( 'get_registered_destinations', 'get_destination' ) );
|
461 |
+
MainWP_Helper::check_methods( '\BackWPup_Option', array( 'get_job_ids', 'get' ) );
|
462 |
+
|
463 |
+
$jobdest = array();
|
464 |
+
$jobids = \BackWPup_Option::get_job_ids();
|
465 |
+
$destinations = \BackWPup::get_registered_destinations();
|
466 |
+
foreach ( $jobids as $jobid ) {
|
467 |
+
if ( \BackWPup_Option::get( $jobid, 'backuptype' ) === 'sync' ) {
|
468 |
+
continue;
|
469 |
+
}
|
470 |
+
$dests = \BackWPup_Option::get( $jobid, 'destinations' );
|
471 |
+
foreach ( $dests as $dest ) {
|
472 |
+
if ( ! $destinations[ $dest ]['class'] ) {
|
473 |
+
continue;
|
474 |
+
}
|
475 |
+
|
476 |
+
$dest_class = \BackWPup::get_destination( $dest );
|
477 |
+
if ( $dest_class && method_exists( $dest_class, 'file_get_list' ) ) {
|
478 |
$can_do_dest = $dest_class->file_get_list( $jobid . '_' . $dest );
|
479 |
if ( ! empty( $can_do_dest ) ) {
|
480 |
+
$jobdest[] = $jobid . '_' . $dest;
|
481 |
}
|
482 |
}
|
483 |
+
}
|
484 |
+
}
|
485 |
+
|
486 |
+
return $jobdest;
|
487 |
+
}
|
488 |
+
|
489 |
+
/**
|
490 |
+
* Hide BackWPup Plugin from the WordPress Installed plugin list.
|
491 |
+
*
|
492 |
+
* @param array $plugins Installed plugins.
|
493 |
+
* @return array $plugins Installed plugins without BackWPup Plugin on the list.
|
494 |
+
*/
|
495 |
+
public function all_plugins( $plugins ) {
|
496 |
+
foreach ( $plugins as $key => $value ) {
|
497 |
+
$plugin_slug = basename( $key, '.php' );
|
498 |
+
if ( 'backwpup' === $plugin_slug ) {
|
499 |
+
unset( $plugins[ $key ] );
|
500 |
+
}
|
501 |
+
}
|
502 |
+
|
503 |
+
return $plugins;
|
504 |
+
}
|
505 |
+
|
506 |
+
/**
|
507 |
+
* Remove BackWPup Plugin from the WordPress Admin.
|
508 |
+
*/
|
509 |
+
public function remove_menu() {
|
510 |
+
|
511 |
+
/** @global object $submenu WordPress Submenu array. */
|
512 |
+
global $submenu;
|
513 |
+
|
514 |
+
// Remove the WordPress Admin SubMenu.
|
515 |
+
if ( isset( $submenu['backwpup'] ) ) {
|
516 |
+
unset( $submenu['backwpup'] );
|
517 |
+
}
|
518 |
+
|
519 |
+
// Remove the WordPress Admin Page.
|
520 |
+
remove_menu_page( 'backwpup' );
|
521 |
+
|
522 |
+
// Create a WP Safe Redirect for the page URL.
|
523 |
+
$pos = isset( $_SERVER['REQUEST_URI'] ) ? stripos( wp_unslash( $_SERVER['REQUEST_URI'] ), 'admin.php?page=backwpup' ) : false;
|
524 |
+
if ( false !== $pos ) {
|
525 |
+
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
526 |
+
exit();
|
527 |
+
}
|
528 |
+
}
|
529 |
+
|
530 |
+
/**
|
531 |
+
* Show/Hide BackWPup Plugin.
|
532 |
+
*
|
533 |
+
* @uses MainWP_Helper::instance()::update_option()
|
534 |
+
*
|
535 |
+
* @return int[]|string Return 1 on HIDE, Empty string on SHOW.
|
536 |
+
*/
|
537 |
+
protected function show_hide() {
|
538 |
+
|
539 |
+
$hide = isset( $_POST['show_hide'] ) && ( '1' === $_POST['show_hide'] ) ? 'hide' : '';
|
540 |
+
|
541 |
+
MainWP_Helper::instance()->update_option( 'mainwp_backwpup_hide_plugin', $hide, 'yes' );
|
542 |
+
|
543 |
+
return array( 'success' => 1 );
|
544 |
+
}
|
545 |
+
|
546 |
+
/**
|
547 |
+
* Build the MainWP BackWPup Page Settings.
|
548 |
+
* @return array $output Returned information array.
|
549 |
+
*/
|
550 |
+
protected function information() {
|
551 |
+
|
552 |
+
/** @global $wpdb wpdb */
|
553 |
+
global $wpdb;
|
554 |
+
|
555 |
+
// Copied from BackWPup_Page_Settings.
|
556 |
+
ob_start();
|
557 |
+
echo '<table class="wp-list-table widefat fixed" cellspacing="0" style="width: 85%;margin-left:auto;;margin-right:auto;">';
|
558 |
+
echo '<thead><tr><th width="35%">' . __( 'Setting', 'mainwp-child' ) . '</th><th>' . __( 'Value', 'mainwp-child' ) . '</th></tr></thead>';
|
559 |
+
echo '<tfoot><tr><th>' . __( 'Setting', 'mainwp-child' ) . '</th><th>' . __( 'Value', 'mainwp-child' ) . '</th></tr></tfoot>';
|
560 |
+
echo '<tr title=">=3.2"><td>' . __( 'WordPress version', 'mainwp-child' ) . '</td><td>' . esc_html( \BackWPup::get_plugin_data( 'wp_version' ) ) . '</td></tr>';
|
561 |
+
if ( ! class_exists( '\BackWPup_Pro', false ) ) {
|
562 |
+
echo '<tr title=""><td>' . __( 'BackWPup version', 'mainwp-child' ) . '</td><td>' . esc_html( \BackWPup::get_plugin_data( 'Version' ) ) . ' <a href="' . esc_url( translate( \BackWPup::get_plugin_data( 'pluginuri' ), 'backwpup' ) ) . '">' . __( 'Get pro.', 'mainwp-child' ) . '</a></td></tr>';
|
563 |
+
} else {
|
564 |
+
echo '<tr title=""><td>' . __( 'BackWPup Pro version', 'mainwp-child' ) . '</td><td>' . esc_html( \BackWPup::get_plugin_data( 'Version' ) ) . '</td></tr>';
|
565 |
+
}
|
566 |
+
|
567 |
+
echo '<tr title=">=5.3.3"><td>' . __( 'PHP version', 'mainwp-child' ) . '</td><td>' . esc_html( PHP_VERSION ) . '</td></tr>';
|
568 |
+
echo '<tr title=">=5.0.7"><td>' . __( 'MySQL version', 'mainwp-child' ) . '</td><td>' . esc_html( $wpdb->get_var( 'SELECT VERSION() AS version' ) ) . '</td></tr>';
|
569 |
+
if ( function_exists( 'curl_version' ) ) {
|
570 |
+
$curlversion = curl_version();
|
571 |
+
echo '<tr title=""><td>' . __( 'cURL version', 'mainwp-child' ) . '</td><td>' . esc_html( $curlversion['version'] ) . '</td></tr>';
|
572 |
+
echo '<tr title=""><td>' . __( 'cURL SSL version', 'mainwp-child' ) . '</td><td>' . esc_html( $curlversion['ssl_version'] ) . '</td></tr>';
|
573 |
+
} else {
|
574 |
+
echo '<tr title=""><td>' . __( 'cURL version', 'mainwp-child' ) . '</td><td>' . __( 'unavailable', 'mainwp-child' ) . '</td></tr>';
|
575 |
+
}
|
576 |
+
echo '<tr title=""><td>' . __( 'WP-Cron url:', 'mainwp-child' ) . '</td><td>' . esc_html( site_url( 'wp-cron.php' ) ) . '</td></tr>';
|
577 |
+
|
578 |
+
echo '<tr><td>' . __( 'Server self connect:', 'mainwp-child' ) . '</td><td>';
|
579 |
+
$raw_response = \BackWPup_Job::get_jobrun_url( 'test' );
|
580 |
+
$test_result = '';
|
581 |
+
if ( is_wp_error( $raw_response ) ) {
|
582 |
+
$test_result .= sprintf( __( 'The HTTP response test get an error "%s"', 'mainwp-child' ), esc_html( $raw_response->get_error_message() ) );
|
583 |
+
} elseif ( 200 !== (int) wp_remote_retrieve_response_code( $raw_response ) && 204 !== (int) wp_remote_retrieve_response_code( $raw_response ) ) {
|
584 |
+
$test_result .= sprintf( __( 'The HTTP response test get a false http status (%s)', 'mainwp-child' ), esc_html( wp_remote_retrieve_response_code( $raw_response ) ) );
|
585 |
+
}
|
586 |
+
$headers = wp_remote_retrieve_headers( $raw_response );
|
587 |
+
if ( isset( $headers['x-backwpup-ver'] ) && \BackWPup::get_plugin_data( 'version' ) !== $headers['x-backwpup-ver'] ) {
|
588 |
+
$test_result .= sprintf( __( 'The BackWPup HTTP response header returns a false value: "%s"', 'mainwp-child' ), esc_html( $headers['x-backwpup-ver'] ) );
|
589 |
+
}
|
590 |
+
|
591 |
+
if ( empty( $test_result ) ) {
|
592 |
+
esc_html_e( 'Response Test O.K.', 'mainwp-child' );
|
593 |
+
} else {
|
594 |
+
echo esc_html( $test_result );
|
595 |
+
}
|
596 |
+
echo '</td></tr>';
|
597 |
+
|
598 |
+
echo '<tr><td>' . __( 'Temp folder:', 'mainwp-child' ) . '</td><td>';
|
599 |
+
if ( ! is_dir( \BackWPup::get_plugin_data( 'TEMP' ) ) ) {
|
600 |
+
echo sprintf( __( 'Temp folder %s doesn\'t exist.', 'mainwp-child' ), esc_html( \BackWPup::get_plugin_data( 'TEMP' ) ) );
|
601 |
+
} elseif ( ! is_writable( \BackWPup::get_plugin_data( 'TEMP' ) ) ) {
|
602 |
+
echo sprintf( __( 'Temporary folder %s is not writable.', 'mainwp-child' ), esc_html( \BackWPup::get_plugin_data( 'TEMP' ) ) );
|
603 |
+
} else {
|
604 |
+
echo esc_html( \BackWPup::get_plugin_data( 'TEMP' ) );
|
605 |
+
}
|
606 |
+
echo '</td></tr>';
|
607 |
+
|
608 |
+
echo '<tr><td>' . __( 'Log folder:', 'mainwp-child' ) . '</td><td>';
|
609 |
+
|
610 |
+
$log_folder = \BackWPup_File::get_absolute_path( get_site_option( 'backwpup_cfg_logfolder' ) );
|
611 |
+
|
612 |
+
if ( ! is_dir( $log_folder ) ) {
|
613 |
+
echo sprintf( __( 'Logs folder %s not exist.', 'mainwp-child' ), esc_html( $log_folder ) );
|
614 |
+
} elseif ( ! is_writable( $log_folder ) ) {
|
615 |
+
echo sprintf( __( 'Log folder %s is not writable.', 'mainwp-child' ), esc_html( $log_folder ) );
|
616 |
+
} else {
|
617 |
+
echo esc_html( $log_folder );
|
618 |
+
}
|
619 |
+
echo '</td></tr>';
|
620 |
+
echo '<tr title=""><td>' . __( 'Server', 'mainwp-child' ) . '</td><td>' . ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) ) : '' ) . '</td></tr>';
|
621 |
+
echo '<tr title=""><td>' . __( 'Operating System', 'mainwp-child' ) . '</td><td>' . esc_html( PHP_OS ) . '</td></tr>';
|
622 |
+
echo '<tr title=""><td>' . __( 'PHP SAPI', 'mainwp-child' ) . '</td><td>' . esc_html( PHP_SAPI ) . '</td></tr>';
|
623 |
+
echo '<tr title=""><td>' . __( 'Current PHP user', 'mainwp-child' ) . '</td><td>' . esc_html( get_current_user() ) . '</td></tr>';
|
624 |
+
$text = version_compare( phpversion(), '5.3.0' ) < 0 && (bool) ini_get( 'safe_mode' ) ? __( 'On', 'mainwp-child' ) : __( 'Off', 'mainwp-child' );
|
625 |
+
echo '<tr title=""><td>' . __( 'Safe Mode', 'mainwp-child' ) . '</td><td>' . $text . '</td></tr>';
|
626 |
+
echo '<tr title=">=30"><td>' . __( 'Maximum execution time', 'mainwp-child' ) . '</td><td>' . ini_get( 'max_execution_time' ) . ' ' . __( 'seconds', 'mainwp-child' ) . '</td></tr>';
|
627 |
+
if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) {
|
628 |
+
echo '<tr title="ALTERNATE_WP_CRON"><td>' . __( 'Alternative WP Cron', 'mainwp-child' ) . '</td><td>' . __( 'On', 'mainwp-child' ) . '</td></tr>';
|
629 |
+
} else {
|
630 |
+
echo '<tr title="ALTERNATE_WP_CRON"><td>' . __( 'Alternative WP Cron', 'mainwp-child' ) . '</td><td>' . __( 'Off', 'mainwp-child' ) . '</td></tr>';
|
631 |
+
}
|
632 |
+
if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
|
633 |
+
echo '<tr title="DISABLE_WP_CRON"><td>' . __( 'Disabled WP Cron', 'mainwp-child' ) . '</td><td>' . __( 'On', 'mainwp-child' ) . '</td></tr>';
|
634 |
+
} else {
|
635 |
+
echo '<tr title="DISABLE_WP_CRON"><td>' . __( 'Disabled WP Cron', 'mainwp-child' ) . '</td><td>' . __( 'Off', 'mainwp-child' ) . '</td></tr>';
|
636 |
+
}
|
637 |
+
if ( defined( 'FS_CHMOD_DIR' ) ) {
|
638 |
+
echo '<tr title="FS_CHMOD_DIR"><td>' . __( 'CHMOD Dir', 'mainwp-child' ) . '</td><td>' . FS_CHMOD_DIR . '</td></tr>';
|
639 |
+
} else {
|
640 |
+
echo '<tr title="FS_CHMOD_DIR"><td>' . __( 'CHMOD Dir', 'mainwp-child' ) . '</td><td>0755</td></tr>';
|
641 |
+
}
|
642 |
+
|
643 |
+
$now = localtime( time(), true );
|
644 |
+
echo '<tr title=""><td>' . __( 'Server Time', 'mainwp-child' ) . '</td><td>' . esc_html( $now['tm_hour'] ) . ':' . esc_html( $now['tm_min'] ) . '</td></tr>';
|
645 |
+
echo '<tr title=""><td>' . __( 'Blog Time', 'mainwp-child' ) . '</td><td>' . esc_html( date_i18n( 'H:i' ) ) . '</td></tr>';
|
646 |
+
echo '<tr title=""><td>' . __( 'Blog Timezone', 'mainwp-child' ) . '</td><td>' . esc_html( get_option( 'timezone_string' ) ) . '</td></tr>';
|
647 |
+
echo '<tr title=""><td>' . __( 'Blog Time offset', 'mainwp-child' ) . '</td><td>' . sprintf( __( '%s hours', 'mainwp-child' ), esc_html( get_option( 'gmt_offset' ) ) ) . '</td></tr>';
|
648 |
+
echo '<tr title="WPLANG"><td>' . __( 'Blog language', 'mainwp-child' ) . '</td><td>' . esc_html( get_bloginfo( 'language' ) ) . '</td></tr>';
|
649 |
+
echo '<tr title="utf8"><td>' . __( 'MySQL Client encoding', 'mainwp-child' ) . '</td><td>';
|
650 |
+
echo defined( 'DB_CHARSET' ) ? esc_html( DB_CHARSET ) : '';
|
651 |
+
echo '</td></tr>';
|
652 |
+
echo '<tr title="URF-8"><td>' . __( 'Blog charset', 'mainwp-child' ) . '</td><td>' . esc_html( get_bloginfo( 'charset' ) ) . '</td></tr>';
|
653 |
+
echo '<tr title=">=128M"><td>' . __( 'PHP Memory limit', 'mainwp-child' ) . '</td><td>' . esc_html( ini_get( 'memory_limit' ) ) . '</td></tr>';
|
654 |
+
echo '<tr title="WP_MEMORY_LIMIT"><td>' . __( 'WP memory limit', 'mainwp-child' ) . '</td><td>' . esc_html( WP_MEMORY_LIMIT ) . '</td></tr>';
|
655 |
+
echo '<tr title="WP_MAX_MEMORY_LIMIT"><td>' . __( 'WP maximum memory limit', 'mainwp-child' ) . '</td><td>' . esc_html( WP_MAX_MEMORY_LIMIT ) . '</td></tr>';
|
656 |
+
echo '<tr title=""><td>' . __( 'Memory in use', 'mainwp-child' ) . '</td><td>' . esc_html( size_format( memory_get_usage( true ), 2 ) ) . '</td></tr>';
|
657 |
+
|
658 |
+
$disabled = ini_get( 'disable_functions' );
|
659 |
+
if ( ! empty( $disabled ) ) {
|
660 |
+
$disabledarry = explode( ',', $disabled );
|
661 |
+
echo '<tr title=""><td>' . __( 'Disabled PHP Functions:', 'mainwp-child' ) . '</td><td>';
|
662 |
+
echo esc_html( implode( ', ', $disabledarry ) );
|
663 |
+
echo '</td></tr>';
|
664 |
+
}
|
665 |
+
|
666 |
+
echo '<tr title=""><td>' . __( 'Loaded PHP Extensions:', 'mainwp-child' ) . '</td><td>';
|
667 |
+
$extensions = get_loaded_extensions();
|
668 |
+
sort( $extensions );
|
669 |
+
echo esc_html( implode( ', ', $extensions ) );
|
670 |
+
echo '</td></tr>';
|
671 |
+
echo '</table>';
|
672 |
+
|
673 |
+
$output = ob_get_contents();
|
674 |
+
|
675 |
+
ob_end_clean();
|
676 |
+
|
677 |
+
return array(
|
678 |
+
'success' => 1,
|
679 |
+
'response' => $output,
|
680 |
+
);
|
681 |
+
}
|
682 |
+
|
683 |
+
/**
|
684 |
+
* Delete BackWPup Log.
|
685 |
+
*
|
686 |
+
* @uses \BackWPup_File::get_absolute_path()
|
687 |
+
*
|
688 |
+
* @return int[]|string[] On success return success[1] & error[] message on failure.
|
689 |
+
*/
|
690 |
+
protected function delete_log() {
|
691 |
+
if ( ! isset( $_POST['settings']['logfile'] ) || ! is_array( $_POST['settings']['logfile'] ) ) {
|
692 |
+
return array( 'error' => __( 'Missing logfile.', 'mainwp-child' ) );
|
693 |
+
}
|
694 |
|
695 |
$dir = get_site_option( 'backwpup_cfg_logfolder' );
|
696 |
+
$dir = \BackWPup_File::get_absolute_path( $dir );
|
697 |
|
698 |
+
foreach ( $_POST['settings']['logfile'] as $logfile ) {
|
699 |
+
$logfile = basename( $logfile );
|
700 |
|
701 |
+
if ( ! is_writeable( $dir ) ) {
|
702 |
+
return array( 'error' => __( 'Directory not writable:', 'mainwp-child' ) . $dir );
|
703 |
+
}
|
704 |
+
if ( ! is_file( $dir . $logfile ) ) {
|
705 |
+
return array( 'error' => __( 'Not file:', 'mainwp-child' ) . $dir . $logfile );
|
706 |
+
}
|
707 |
|
708 |
+
unlink( $dir . $logfile );
|
709 |
|
710 |
+
}
|
711 |
|
712 |
+
return array( 'success' => 1 );
|
713 |
+
}
|
714 |
|
715 |
+
/**
|
716 |
+
* Delete backup job.
|
717 |
+
*
|
718 |
+
* @uses \BackWPup_Option::delete_job()
|
719 |
+
*
|
720 |
+
* @return array|int[]|string[] On success return success[1] & error['message'] on failure.
|
721 |
+
*/
|
722 |
+
protected function delete_job() {
|
723 |
+
if ( ! isset( $_POST['job_id'] ) ) {
|
724 |
+
return array( 'error' => __( 'Missing job_id.', 'mainwp-child' ) );
|
725 |
+
}
|
726 |
|
727 |
+
$job_id = (int) $_POST['job_id'];
|
728 |
|
729 |
+
wp_clear_scheduled_hook( 'backwpup_cron', array( 'id' => $job_id ) );
|
730 |
+
if ( ! \BackWPup_Option::delete_job( $job_id ) ) {
|
731 |
+
return array( 'error' => __( 'Cannot delete job', 'mainwp-child' ) );
|
732 |
+
}
|
733 |
|
734 |
+
return array( 'success' => 1 );
|
735 |
+
}
|
736 |
|
737 |
+
/**
|
738 |
+
* Delete backup.
|
739 |
+
*
|
740 |
+
* @uses \BackWPup::get_destination()
|
741 |
+
* @uses \BackWPup::get_destination::file_get_list()
|
742 |
+
* @uses \BackWPup::get_destination::file_delete()
|
743 |
+
*
|
744 |
+
* @return array|int[]|string[] On success return success[1] response['DELETED'] & error['message'] on failure.
|
745 |
+
*/
|
746 |
+
protected function delete_backup() {
|
747 |
+
if ( ! isset( $_POST['settings']['backupfile'] ) ) {
|
748 |
+
return array( 'error' => __( 'Missing backupfile.', 'mainwp-child' ) );
|
749 |
+
}
|
750 |
|
751 |
+
if ( ! isset( $_POST['settings']['dest'] ) ) {
|
752 |
+
return array( 'error' => __( 'Missing dest.', 'mainwp-child' ) );
|
753 |
+
}
|
754 |
|
755 |
+
$backupfile = isset( $_POST['settings']['backupfile'] ) ? wp_unslash( $_POST['settings']['backupfile'] ) : '';
|
756 |
+
$dest = isset( $_POST['settings']['dest'] ) ? sanitize_text_field( wp_unslash( $_POST['settings']['dest'] ) ) : '';
|
757 |
|
758 |
+
list( $dest_id, $dest_name ) = explode( '_', $dest );
|
759 |
|
760 |
+
$dest_class = \BackWPup::get_destination( $dest_name );
|
761 |
|
762 |
+
if ( is_null( $dest_class ) ) {
|
763 |
+
return array( 'error' => __( 'Invalid dest class.', 'mainwp-child' ) );
|
764 |
+
}
|
765 |
|
766 |
+
$files = $dest_class->file_get_list( $dest );
|
767 |
|
768 |
+
foreach ( $files as $file ) {
|
769 |
+
if ( is_array( $file ) && $file['file'] == $backupfile ) {
|
770 |
+
$dest_class->file_delete( $dest, $backupfile );
|
771 |
|
772 |
+
return array(
|
773 |
+
'success' => 1,
|
774 |
+
'response' => 'DELETED',
|
775 |
+
);
|
776 |
+
}
|
777 |
+
}
|
778 |
|
779 |
+
return array(
|
780 |
+
'success' => 1,
|
781 |
+
'response' => 'Not found',
|
782 |
+
);
|
783 |
+
}
|
784 |
|
785 |
+
/**
|
786 |
+
* View BackWPup log.
|
787 |
+
*
|
788 |
+
* @return array|int[]|string[] On success return $output[] & error['message'] on failure.
|
789 |
+
*/
|
790 |
+
protected function view_log() {
|
791 |
+
if ( ! isset( $_POST['settings']['logfile'] ) ) {
|
792 |
+
return array( 'error' => __( 'Missing logfile.', 'mainwp-child' ) );
|
793 |
+
}
|
794 |
|
795 |
$log_folder = get_site_option( 'backwpup_cfg_logfolder' );
|
796 |
+
$log_folder = \BackWPup_File::get_absolute_path( $log_folder );
|
797 |
+
$log_file = $log_folder . basename( $_POST['settings']['logfile'] );
|
798 |
+
|
799 |
+
if ( ! is_readable( $log_file ) && ! is_readable( $log_file . '.gz' ) && ! is_readable( $log_file . '.bz2' ) ) {
|
800 |
+
$output = __( 'Log file doesn\'t exists', 'mainwp-child' );
|
801 |
+
} else {
|
802 |
+
if ( ! file_exists( $log_file ) && file_exists( $log_file . '.gz' ) ) {
|
803 |
+
$log_file = $log_file . '.gz';
|
804 |
+
}
|
805 |
|
806 |
+
if ( ! file_exists( $log_file ) && file_exists( $log_file . '.bz2' ) ) {
|
807 |
+
$log_file = $log_file . '.bz2';
|
808 |
+
}
|
809 |
|
810 |
+
if ( '.gz' == substr( $log_file, - 3 ) ) {
|
811 |
+
$output = file_get_contents( 'compress.zlib://' . $log_file, false );
|
812 |
+
} else {
|
813 |
+
$output = file_get_contents( $log_file, false );
|
814 |
+
}
|
815 |
+
}
|
816 |
|
817 |
+
return array(
|
818 |
+
'success' => 1,
|
819 |
+
'response' => $output,
|
820 |
+
);
|
821 |
+
}
|
822 |
|
823 |
+
/**
|
824 |
+
* Build Tables.
|
825 |
+
*
|
826 |
+
* @uses MainWP_Child_Back_WP_Up::wp_list_table_dependency()
|
827 |
+
* @uses \BackWPup_File::get_absolute_path()
|
828 |
+
* @uses \BackWPup_Page_Logs()
|
829 |
+
* @uses \BackWPup_Page_Backups()
|
830 |
+
* @uses \BackWPup_Option::get_job_ids()
|
831 |
+
* @uses \BackWPup_Option::get()
|
832 |
+
* @uses \BackWPup::get_destination()
|
833 |
+
* @uses \BackWPup::get_destination::file_get_list()
|
834 |
+
* @uses \BackWPup_Option::get()
|
835 |
+
*
|
836 |
+
* @return array Return table array or error['message'] on failure.
|
837 |
+
*/
|
838 |
+
protected function tables() {
|
839 |
+
if ( ! isset( $_POST['settings']['type'] ) ) {
|
840 |
+
return array( 'error' => __( 'Missing type.', 'mainwp-child' ) );
|
841 |
+
}
|
842 |
|
843 |
+
if ( ! isset( $_POST['settings']['website_id'] ) ) {
|
844 |
+
return array( 'error' => __( 'Missing website id.', 'mainwp-child' ) );
|
845 |
+
}
|
846 |
|
847 |
+
$type = isset( $_POST['settings']['type'] ) ? sanitize_text_field( wp_unslash( $_POST['settings']['type'] ) ) : '';
|
848 |
+
$website_id = isset( $_POST['settings']['website_id'] ) ? sanitize_text_field( wp_unslash( $_POST['settings']['website_id'] ) ) : '';
|
849 |
|
850 |
+
$this->wp_list_table_dependency();
|
851 |
|
852 |
+
$array = array();
|
853 |
|
854 |
+
switch ( $type ) {
|
855 |
+
case 'logs':
|
856 |
$log_folder = get_site_option( 'backwpup_cfg_logfolder' );
|
857 |
+
$log_folder = \BackWPup_File::get_absolute_path( $log_folder );
|
858 |
$log_folder = untrailingslashit( $log_folder );
|
859 |
|
860 |
+
if ( ! is_dir( $log_folder ) ) {
|
861 |
+
return array(
|
862 |
+
'success' => 1,
|
863 |
+
'response' => $array,
|
864 |
+
);
|
865 |
+
}
|
866 |
+
update_user_option( get_current_user_id(), 'backwpuplogs_per_page', 99999999 );
|
867 |
+
$output = new \BackWPup_Page_Logs();
|
868 |
+
$output->prepare_items();
|
869 |
+
break;
|
870 |
+
|
871 |
+
case 'backups':
|
872 |
+
update_user_option( get_current_user_id(), 'backwpupbackups_per_page', 99999999 );
|
873 |
+
$output = new \BackWPup_Page_Backups();
|
874 |
+
$output->items = array();
|
875 |
+
|
876 |
+
$jobids = \BackWPup_Option::get_job_ids();
|
877 |
+
|
878 |
+
if ( ! empty( $jobids ) ) {
|
879 |
+
foreach ( $jobids as $jobid ) {
|
880 |
+
if ( \BackWPup_Option::get( $jobid, 'backuptype' ) == 'sync' ) {
|
881 |
+
continue;
|
882 |
+
}
|
883 |
+
|
884 |
+
$dests = \BackWPup_Option::get( $jobid, 'destinations' );
|
885 |
+
foreach ( $dests as $dest ) {
|
886 |
+
$dest_class = \BackWPup::get_destination( $dest );
|
887 |
+
if ( is_null( $dest_class ) ) {
|
888 |
+
continue;
|
889 |
+
}
|
890 |
+
$items = $dest_class->file_get_list( $jobid . '_' . $dest );
|
891 |
+
if ( ! empty( $items ) ) {
|
892 |
+
foreach ( $items as $item ) {
|
893 |
+
$temp_single_item = $item;
|
894 |
+
$temp_single_item['dest'] = $jobid . '_' . $dest;
|
895 |
+
$temp_single_item['timeloc'] = sprintf( __( '%1$s at %2$s', 'mainwp-child' ), date_i18n( get_option( 'date_format' ), $temp_single_item['time'], true ), date_i18n( get_option( 'time_format' ), $temp_single_item['time'], true ) );
|
896 |
+
$output->items[] = $temp_single_item;
|
897 |
+
}
|
898 |
+
}
|
899 |
+
}
|
900 |
+
}
|
901 |
+
}
|
902 |
+
|
903 |
+
break;
|
904 |
+
|
905 |
+
case 'jobs':
|
906 |
+
$output = new \BackWPup_Page_Jobs();
|
907 |
+
$output->prepare_items();
|
908 |
+
break;
|
909 |
+
}
|
910 |
+
|
911 |
+
if ( is_array( $output->items ) ) {
|
912 |
+
if ( 'jobs' == $type ) {
|
913 |
+
foreach ( $output->items as $key => $val ) {
|
914 |
+
$temp_array = array();
|
915 |
+
$temp_array['id'] = $val;
|
916 |
+
$temp_array['name'] = \BackWPup_Option::get( $val, 'name' );
|
917 |
+
$temp_array['type'] = \BackWPup_Option::get( $val, 'type' );
|
918 |
+
$temp_array['destinations'] = \BackWPup_Option::get( $val, 'destinations' );
|
919 |
+
|
920 |
+
if ( $this->is_backwpup_pro ) {
|
921 |
+
$temp_array['export'] = str_replace( '&', '&', wp_nonce_url( network_admin_url( 'admin.php' ) . '?page=backwpupjobs&action=export&jobs[]=' . $val, 'bulk-jobs' ) );
|
922 |
+
}
|
923 |
+
|
924 |
+
if ( \BackWPup_Option::get( $val, 'activetype' ) == 'wpcron' ) {
|
925 |
+
$nextrun = wp_next_scheduled( 'backwpup_cron', array( 'id' => $val ) );
|
926 |
+
if ( $nextrun + ( get_option( 'gmt_offset' ) * 3600 ) ) {
|
927 |
+
$temp_array['nextrun'] = sprintf( __( '%1$s at %2$s by WP-Cron', 'mainwp-child' ), date_i18n( get_option( 'date_format' ), $nextrun, true ), date_i18n( get_option( 'time_format' ), $nextrun, true ) );
|
928 |
+
} else {
|
929 |
+
$temp_array['nextrun'] = __( 'Not scheduled!', 'mainwp-child' );
|
930 |
+
}
|
931 |
+
} else {
|
932 |
+
$temp_array['nextrun'] = __( 'Inactive', 'mainwp-child' );
|
933 |
+
}
|
934 |
+
if ( \BackWPup_Option::get( $val, 'lastrun' ) ) {
|
935 |
+
$lastrun = \BackWPup_Option::get( $val, 'lastrun' );
|
936 |
+
$temp_array['lastrun'] = sprintf( __( '%1$s at %2$s', 'mainwp-child' ), date_i18n( get_option( 'date_format' ), $lastrun, true ), date_i18n( get_option( 'time_format' ), $lastrun, true ) );
|
937 |
+
if ( \BackWPup_Option::get( $val, 'lastruntime' ) ) {
|
938 |
+
$temp_array['lastrun'] .= ' ' . sprintf( __( 'Runtime: %d seconds', 'mainwp-child' ), \BackWPup_Option::get( $val, 'lastruntime' ) );
|
939 |
+
}
|
940 |
+
} else {
|
941 |
+
$temp_array['lastrun'] = __( 'not yet', 'mainwp-child' );
|
942 |
+
}
|
943 |
+
|
944 |
+
$temp_array['website_id'] = $website_id;
|
945 |
+
$array[] = $temp_array;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
946 |
}
|
947 |
+
} elseif ( 'backups' == $type ) {
|
948 |
+
$without_dupes = array();
|
949 |
+
foreach ( $output->items as $key ) {
|
950 |
+
$temp_array = $key;
|
951 |
+
$temp_array['downloadurl'] = str_replace(
|
952 |
+
array(
|
953 |
+
'&',
|
954 |
+
network_admin_url( 'admin.php' ) . '?page=backwpupbackups&action=',
|
955 |
+
),
|
956 |
+
array(
|
957 |
+
'&',
|
958 |
+
admin_url( 'admin-ajax.php' ) . '?action=mainwp_backwpup_download_backup&type=',
|
959 |
+
),
|
960 |
+
$temp_array['downloadurl'] . '&_wpnonce=' . $this->create_nonce_without_session( 'mainwp_download_backup' )
|
961 |
+
);
|
962 |
+
|
963 |
+
$temp_array['downloadurl_id'] = '/wp-admin/admin.php?page=backwpupbackups';
|
964 |
+
if ( preg_match( '/.*&jobid=([^&]+)&.*/is', $temp_array['downloadurl'], $matches ) ) {
|
965 |
+
if ( ! empty( $matches[1] ) && is_numeric( $matches[1] ) ) {
|
966 |
+
$temp_array['downloadurl_id'] .= '&download_click_id=' . $matches[1];
|
967 |
+
}
|
968 |
+
}
|
|
|
|
|
969 |
|
970 |
+
$temp_array['website_id'] = $website_id;
|
|
|
|
|
|
|
971 |
|
972 |
+
if ( ! isset( $without_dupes[ $temp_array['file'] ] ) ) {
|
973 |
+
$array[] = $temp_array;
|
974 |
+
$without_dupes[ $temp_array['file'] ] = 1;
|
975 |
+
}
|
976 |
+
}
|
977 |
+
} else {
|
978 |
+
foreach ( $output->items as $key => $val ) {
|
979 |
+
$array[] = $val;
|
980 |
+
}
|
981 |
+
}
|
982 |
+
}
|
983 |
|
984 |
+
return array(
|
985 |
+
'success' => 1,
|
986 |
+
'response' => $array,
|
987 |
+
);
|
988 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
989 |
|
990 |
+
/**
|
991 |
+
* Initiate download link.
|
992 |
+
*/
|
993 |
+
public function init_download_backup() {
|
994 |
+
if ( ! isset( $_GET['page'] ) || 'backwpupbackups' !== $_GET['page'] || ! isset( $_GET['download_click_id'] ) || empty( $_GET['download_click_id'] ) ) {
|
995 |
+
return;
|
996 |
+
}
|
997 |
+
?>
|
998 |
+
<script type="text/javascript">
|
999 |
+
document.addEventListener("DOMContentLoaded", function(event) {
|
1000 |
+
var downloadLink = document.querySelector( 'a.backup-download-link[data-jobid="<?php echo intval( $_GET['download_click_id'] ); ?>"' );
|
1001 |
+
if (typeof(downloadLink) !== 'undefined' && downloadLink !== null) {
|
1002 |
+
downloadLink.click();
|
1003 |
+
}
|
1004 |
+
});
|
1005 |
+
</script>
|
1006 |
+
<?php
|
1007 |
+
}
|
1008 |
+
|
1009 |
+
/**
|
1010 |
+
* Download backup.
|
1011 |
+
*
|
1012 |
+
* @uses MainWP_Child_Back_WP_Up::verify_nonce_without_session()
|
1013 |
+
* @uses \BackWPup::get_destination()
|
1014 |
+
* @uses \BackWPup::get_destination::file_download()
|
1015 |
+
*/
|
1016 |
+
public function download_backup() {
|
1017 |
+
if ( ! isset( $_GET['type'] ) || empty( $_GET['type'] ) || ! isset( $_GET['_wpnonce'] ) || empty( $_GET['_wpnonce'] ) ) {
|
1018 |
+
die( '-1' );
|
1019 |
+
}
|
1020 |
+
|
1021 |
+
if ( ! current_user_can( 'backwpup_backups_download' ) ) {
|
1022 |
+
die( '-2' );
|
1023 |
+
}
|
1024 |
+
|
1025 |
+
if ( ! $this->verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_backup' ) ) {
|
1026 |
+
die( '-3' );
|
1027 |
+
}
|
1028 |
+
|
1029 |
+
$dest = strtoupper( str_replace( 'download', '', $_GET['type'] ) );
|
1030 |
+
if ( ! empty( $dest ) && strstr( $_GET['type'], 'download' ) ) {
|
1031 |
+
$dest_class = \BackWPup::get_destination( $dest );
|
1032 |
+
if ( is_null( $dest_class ) ) {
|
1033 |
+
die( '-4' );
|
1034 |
+
}
|
1035 |
+
|
1036 |
+
$dest_class->file_download( (int) $_GET['jobid'], $_GET['file'] );
|
1037 |
+
} else {
|
1038 |
+
die( '-5' );
|
1039 |
+
}
|
1040 |
+
|
1041 |
+
die();
|
1042 |
+
}
|
1043 |
+
|
1044 |
+
/**
|
1045 |
+
* Create security nounce without session.
|
1046 |
+
*
|
1047 |
+
* @param int $action Action performing.
|
1048 |
+
*
|
1049 |
+
* @return string|false Return nonce or FALSE on failure.
|
1050 |
+
*/
|
1051 |
+
protected function create_nonce_without_session( $action = - 1 ) {
|
1052 |
+
$user = wp_get_current_user();
|
1053 |
+
$uid = (int) $user->ID;
|
1054 |
+
if ( ! $uid ) {
|
1055 |
+
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
|
1056 |
+
}
|
1057 |
+
|
1058 |
+
$i = wp_nonce_tick();
|
1059 |
+
|
1060 |
+
return substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 );
|
1061 |
+
}
|
1062 |
+
|
1063 |
+
/**
|
1064 |
+
* Verify nonce without session.
|
1065 |
+
*
|
1066 |
+
* @param string $nonce Nonce to verify.
|
1067 |
+
* @param int $action Action to perform.
|
1068 |
+
*
|
1069 |
+
* @return bool|int FALSE on failure. 1 or 2 on success.
|
1070 |
+
*/
|
1071 |
+
protected function verify_nonce_without_session($nonce, $action = - 1 ) {
|
1072 |
+
$nonce = (string) $nonce;
|
1073 |
+
$user = wp_get_current_user();
|
1074 |
+
$uid = (int) $user->ID;
|
1075 |
+
if ( ! $uid ) {
|
1076 |
+
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
|
1077 |
+
}
|
1078 |
+
|
1079 |
+
if ( empty( $nonce ) ) {
|
1080 |
+
return false;
|
1081 |
+
}
|
1082 |
|
1083 |
+
$i = wp_nonce_tick();
|
1084 |
|
1085 |
+
$expected = substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 );
|
1086 |
+
if ( hash_equals( $expected, $nonce ) ) {
|
1087 |
+
return 1;
|
1088 |
+
}
|
1089 |
|
1090 |
+
$expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 );
|
1091 |
+
if ( hash_equals( $expected, $nonce ) ) {
|
1092 |
+
return 2;
|
1093 |
+
}
|
1094 |
|
1095 |
+
return false;
|
1096 |
+
}
|
1097 |
|
1098 |
+
/**
|
1099 |
+
* BackWPup Ajax Working.
|
1100 |
+
*
|
1101 |
+
* @uses MainWP_Child_Back_WP_Up::wp_list_table_dependency()
|
1102 |
+
* @uses \BackWPup_Page_Jobs::ajax_working()
|
1103 |
+
*
|
1104 |
+
* @return array Return success array[ success, response ]
|
1105 |
+
*/
|
1106 |
+
protected function ajax_working() {
|
1107 |
+
|
1108 |
+
if ( ! isset( $_POST['settings'] ) || ! is_array( $_POST['settings'] ) || ! isset( $_POST['settings']['logfile'] ) || ! isset( $_POST['settings']['logpos'] ) ) {
|
1109 |
+
return array( 'error' => __( 'Missing logfile or logpos.', 'mainwp-child' ) );
|
1110 |
+
}
|
1111 |
|
1112 |
+
$_GET['logfile'] = isset( $_POST['settings']['logfile'] ) ? wp_unslash( $_POST['settings']['logfile'] ) : '';
|
1113 |
+
$_GET['logpos'] = isset( $_POST['settings']['logpos'] ) ? wp_unslash( $_POST['settings']['logpos'] ) : '';
|
1114 |
+
$_REQUEST['_wpnonce'] = wp_create_nonce( 'backwpupworking_ajax_nonce' );
|
1115 |
|
1116 |
+
$this->wp_list_table_dependency();
|
|
|
|
|
1117 |
|
1118 |
+
/**
|
1119 |
+
* MainWP BackWPup WP Die ajax handler.
|
1120 |
+
*
|
1121 |
+
* @param string $message Error message container.
|
1122 |
+
* @return string Error message.
|
1123 |
+
*/
|
1124 |
+
function mainwp_backwpup_wp_die_ajax_handler( $message ) {
|
1125 |
+
return 'mainwp_backwpup_wp_die_ajax_handler';
|
1126 |
+
}
|
1127 |
|
1128 |
+
// We do this in order to not die when using wp_die.
|
1129 |
+
if ( ! defined( 'DOING_AJAX' ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1130 |
|
1131 |
+
/**
|
1132 |
+
* Checks whether ajax job is in progress.
|
1133 |
+
*
|
1134 |
+
* @const ( bool ) Default: true
|
1135 |
+
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Back_WP_Up.html
|
1136 |
+
*/
|
1137 |
+
define( 'DOING_AJAX', true );
|
1138 |
+
}
|
1139 |
|
1140 |
+
add_filter( 'wp_die_ajax_handler', 'mainwp_backwpup_wp_die_ajax_handler' );
|
1141 |
+
remove_filter( 'wp_die_ajax_handler', '_ajax_wp_die_handler' );
|
1142 |
|
1143 |
+
ob_start();
|
1144 |
+
\BackWPup_Page_Jobs::ajax_working();
|
1145 |
|
1146 |
+
$output = ob_get_contents();
|
|
|
|
|
1147 |
|
1148 |
+
ob_end_clean();
|
1149 |
|
1150 |
+
return array(
|
1151 |
+
'success' => 1,
|
1152 |
+
'response' => $output,
|
1153 |
+
);
|
1154 |
+
}
|
|
|
1155 |
|
1156 |
+
/**
|
1157 |
+
* Backup now.
|
1158 |
+
*
|
1159 |
+
* @uses MainWP_Child_Back_WP_Up::wp_list_table_dependency()
|
1160 |
+
* @uses MainWP_Child_Back_WP_Up::check_backwpup_messages()
|
1161 |
+
* @uses \BackWPup_Page_Jobs::load()
|
1162 |
+
* @uses \BackWPup_Job::get_working_data()
|
1163 |
+
*
|
1164 |
+
* @return array Response array[ success, response, logfile ] or array[ error ]
|
1165 |
+
*/
|
1166 |
+
protected function backup_now() {
|
1167 |
+
|
1168 |
+
if ( ! isset( $_POST['settings']['job_id'] ) ) {
|
1169 |
+
return array( 'error' => __( 'Missing job_id', 'mainwp-child' ) );
|
1170 |
+
}
|
1171 |
|
1172 |
+
// Simulate http://wp/wp-admin/admin.php?jobid=1&page=backwpupjobs&action=runnow.
|
1173 |
+
$_GET['jobid'] = isset( $_POST['settings']['job_id'] ) ? sanitize_text_field( wp_unslash( $_POST['settings']['job_id'] ) ) : '';
|
1174 |
|
1175 |
+
$_REQUEST['action'] = 'runnow';
|
1176 |
+
$_REQUEST['_wpnonce'] = wp_create_nonce( 'backwpup_job_run-runnowlink' );
|
1177 |
|
1178 |
+
update_site_option( 'backwpup_messages', array() );
|
|
|
|
|
|
|
1179 |
|
1180 |
+
$this->wp_list_table_dependency();
|
|
|
|
|
1181 |
|
1182 |
+
ob_start();
|
1183 |
+
\BackWPup_Page_Jobs::load();
|
1184 |
+
ob_end_clean();
|
1185 |
|
1186 |
+
$output = $this->check_backwpup_messages();
|
1187 |
|
1188 |
+
if ( isset( $output['error'] ) ) {
|
1189 |
+
return array( 'error' => '\BackWPup_Page_Jobs::load fail: ' . $output['error'] );
|
1190 |
+
} else {
|
1191 |
+
$job_object = \BackWPup_Job::get_working_data();
|
1192 |
+
if ( is_object( $job_object ) ) {
|
1193 |
+
return array(
|
1194 |
+
'success' => 1,
|
1195 |
+
'response' => $output['message'],
|
1196 |
+
'logfile' => basename( $job_object->logfile ),
|
1197 |
+
);
|
1198 |
+
} else {
|
1199 |
+
return array(
|
1200 |
+
'success' => 1,
|
1201 |
+
'response' => $output['message'],
|
1202 |
+
);
|
1203 |
+
}
|
1204 |
+
}
|
1205 |
+
}
|
1206 |
|
1207 |
+
/**
|
1208 |
+
* Abort backup.
|
1209 |
+
*
|
1210 |
+
* @uses MainWP_Child_Back_WP_Up::wp_list_table_dependency()
|
1211 |
+
* @uses MainWP_Child_Back_WP_Up::check_backwpup_messages()
|
1212 |
+
* @uses \BackWPup_Page_Jobs::load()
|
1213 |
+
*
|
1214 |
+
* @return array|string[] Return array or error[message] on failure.
|
1215 |
+
*/
|
1216 |
+
protected function backup_abort() {
|
1217 |
+
$_REQUEST['action'] = 'abort';
|
1218 |
+
$_REQUEST['_wpnonce'] = wp_create_nonce( 'abort-job' );
|
1219 |
+
|
1220 |
+
update_site_option( 'backwpup_messages', array() );
|
1221 |
+
|
1222 |
+
$this->wp_list_table_dependency();
|
1223 |
+
|
1224 |
+
ob_start();
|
1225 |
+
\BackWPup_Page_Jobs::load();
|
1226 |
+
ob_end_clean();
|
1227 |
+
|
1228 |
+
$output = $this->check_backwpup_messages();
|
1229 |
+
|
1230 |
+
if ( isset( $output['error'] ) ) {
|
1231 |
+
return array( 'error' => 'Cannot abort: ' . $output['error'] );
|
1232 |
+
} else {
|
1233 |
+
return array(
|
1234 |
+
'success' => 1,
|
1235 |
+
'response' => $output['message'],
|
1236 |
+
);
|
1237 |
+
}
|
1238 |
+
}
|
1239 |
|
1240 |
+
/**
|
1241 |
+
* WordPress list table dependency.
|
1242 |
+
*
|
1243 |
+
* @uses MainWP_Child_Back_WP_Up::MainWP_Fake_Wp_Screen()
|
1244 |
+
*/
|
1245 |
+
protected function wp_list_table_dependency() {
|
1246 |
+
if ( ! function_exists( 'convert_to_screen' ) ) {
|
1247 |
+
/**
|
1248 |
+
* Convert to screen.
|
1249 |
+
*
|
1250 |
+
* We need this because BackWPup_Page_Jobs extends WP_List_Table.
|
1251 |
+
* which uses convert_to_screen.
|
1252 |
+
*
|
1253 |
+
* @param $hook_name Hook name.
|
1254 |
+
* @return MainWP_Fake_Wp_Screen
|
1255 |
+
*/
|
1256 |
+
function convert_to_screen( $hook_name ) {
|
1257 |
+
return new MainWP_Fake_Wp_Screen();
|
1258 |
+
}
|
1259 |
+
}
|
1260 |
|
1261 |
+
if ( ! function_exists( 'add_screen_option' ) ) {
|
1262 |
+
/**
|
1263 |
+
* Adds the WP Fake Screen option.
|
1264 |
+
*
|
1265 |
+
* @param mixed $option Options.
|
1266 |
+
* @param array $args Arguments.
|
1267 |
+
*/
|
1268 |
+
function add_screen_option( $option, $args = array() ) {
|
1269 |
+
}
|
1270 |
+
}
|
1271 |
|
1272 |
+
if ( ! class_exists( '\WP_List_Table' ) ) {
|
1273 |
+
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
|
1274 |
+
}
|
1275 |
+
}
|
|
|
|
|
|
|
1276 |
|
1277 |
+
/**
|
1278 |
+
* Wizard system scan.
|
1279 |
+
*
|
1280 |
+
* @uses \BackWPup_Pro_Wizard_SystemTest()
|
1281 |
+
*
|
1282 |
+
* @return array|string[] Return array or error[message] on failure.
|
1283 |
+
*/
|
1284 |
+
protected function wizard_system_scan() {
|
1285 |
+
if ( class_exists( '\BackWPup_Pro_Wizard_SystemTest' ) ) {
|
1286 |
+
ob_start();
|
1287 |
+
|
1288 |
+
$system_test = new \BackWPup_Pro_Wizard_SystemTest();
|
1289 |
+
$system_test->execute( null );
|
1290 |
+
|
1291 |
+
$output = ob_get_contents();
|
1292 |
+
|
1293 |
+
ob_end_clean();
|
1294 |
+
|
1295 |
+
return array(
|
1296 |
+
'success' => 1,
|
1297 |
+
'response' => $output,
|
1298 |
+
);
|
1299 |
+
} else {
|
1300 |
+
return array( 'error' => 'Missing BackWPup_Pro_Wizard_SystemTest' );
|
1301 |
+
}
|
1302 |
+
}
|
1303 |
|
1304 |
+
/**
|
1305 |
+
* Check destination email.
|
1306 |
+
*
|
1307 |
+
* @uses PHPMailer()
|
1308 |
+
* @uses \BackWPup::get_plugin_data()
|
1309 |
+
* @uses \Swift_SmtpTransport::newInstance()
|
1310 |
+
* @uses \Swift_SendmailTransport::newInstance()
|
1311 |
+
* @uses \Swift_MailTransport::newInstance()
|
1312 |
+
* @uses \Swift_Mailer::newInstance()
|
1313 |
+
* @uses \Swift_Message::newInstance()
|
1314 |
+
* @uses \Exception
|
1315 |
+
*
|
1316 |
+
* @return array|\Exception Return response array.
|
1317 |
+
*/
|
1318 |
+
protected function destination_email_check_email() {
|
1319 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
1320 |
+
|
1321 |
+
$message = '';
|
1322 |
+
|
1323 |
+
$emailmethod = ( isset( $settings['emailmethod'] ) ? $settings['emailmethod'] : '' );
|
1324 |
+
$emailsendmail = ( isset( $settings['emailsendmail'] ) ? $settings['emailsendmail'] : '' );
|
1325 |
+
$emailhost = ( isset( $settings['emailhost'] ) ? $settings['emailhost'] : '' );
|
1326 |
+
$emailhostport = ( isset( $settings['emailhostport'] ) ? $settings['emailhostport'] : '' );
|
1327 |
+
$emailsecure = ( isset( $settings['emailsecure'] ) ? $settings['emailsecure'] : '' );
|
1328 |
+
$emailuser = ( isset( $settings['emailuser'] ) ? $settings['emailuser'] : '' );
|
1329 |
+
$emailpass = ( isset( $settings['emailpass'] ) ? $settings['emailpass'] : '' );
|
1330 |
+
|
1331 |
+
if ( ! isset( $settings['emailaddress'] ) || strlen( $settings['emailaddress'] ) < 2 ) {
|
1332 |
+
$message = __( 'Missing email address.', 'mainwp-child' );
|
1333 |
+
} else {
|
1334 |
+
if ( $emailmethod ) {
|
1335 |
+
|
1336 |
+
/**
|
1337 |
+
* PHP mailer instance.
|
1338 |
+
*
|
1339 |
+
* @global object
|
1340 |
+
*/
|
1341 |
global $phpmailer;
|
1342 |
+
|
1343 |
if ( ! is_object( $phpmailer ) || ! $phpmailer instanceof PHPMailer ) {
|
1344 |
if ( file_exists( ABSPATH . WPINC . '/PHPMailer/PHPMailer.php' )) {
|
1345 |
require ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
|
1364 |
}
|
1365 |
}
|
1366 |
|
1367 |
+
if ( ! class_exists( '\Swift', false ) ) {
|
1368 |
+
require \BackWPup::get_plugin_data( 'plugindir' ) . '/vendor/SwiftMailer/swift_required.php';
|
1369 |
+
}
|
1370 |
+
|
1371 |
+
if ( function_exists( 'mb_internal_encoding' ) && ( (int) ini_get( 'mbstring.func_overload' ) ) & 2 ) {
|
1372 |
+
$mbEncoding = mb_internal_encoding();
|
1373 |
+
mb_internal_encoding( 'ASCII' );
|
1374 |
+
}
|
1375 |
+
|
1376 |
+
try {
|
1377 |
+
// Create the Transport.
|
1378 |
+
if ( 'smtp' == $emailmethod ) {
|
1379 |
+
$transport = \Swift_SmtpTransport::newInstance( $emailhost, $emailhostport );
|
1380 |
+
$transport->setUsername( $emailuser );
|
1381 |
+
$transport->setPassword( $emailpass );
|
1382 |
+
if ( 'ssl' == $emailsecure ) {
|
1383 |
+
$transport->setEncryption( 'ssl' );
|
1384 |
+
}
|
1385 |
+
if ( 'tls' == $emailsecure ) {
|
1386 |
+
$transport->setEncryption( 'tls' );
|
1387 |
+
}
|
1388 |
+
} elseif ( 'sendmail' == $emailmethod ) {
|
1389 |
+
$transport = \Swift_SendmailTransport::newInstance( $emailsendmail );
|
1390 |
+
} else {
|
1391 |
+
$transport = \Swift_MailTransport::newInstance();
|
1392 |
+
}
|
1393 |
+
$emailer = \Swift_Mailer::newInstance( $transport );
|
1394 |
+
|
1395 |
+
$message = \Swift_Message::newInstance( __( 'BackWPup archive sending TEST Message', 'mainwp-child' ) );
|
1396 |
+
$message->setFrom( array( ( isset( $settings['emailsndemail'] ) ? $settings['emailsndemail'] : 'from@example.com' ) => isset( $settings['emailsndemailname'] ) ? $settings['emailsndemailname'] : '' ) );
|
1397 |
+
$message->setTo( array( $settings['emailaddress'] ) );
|
1398 |
+
$message->setBody( __( 'If this message reaches your inbox, sending backup archives via email should work for you.', 'mainwp-child' ) );
|
1399 |
+
|
1400 |
+
$result = $emailer->send( $message );
|
1401 |
+
} catch ( \Exception $e ) {
|
1402 |
+
$message = 'Swift Mailer: ' . $e->getMessage();
|
1403 |
+
}
|
1404 |
+
|
1405 |
+
if ( isset( $mbEncoding ) ) {
|
1406 |
+
mb_internal_encoding( $mbEncoding );
|
1407 |
+
}
|
1408 |
+
|
1409 |
+
if ( ! isset( $result ) || ! $result ) {
|
1410 |
+
$message = __( 'Error while sending email!', 'mainwp-child' );
|
1411 |
+
} else {
|
1412 |
+
$message = __( 'Email sent.', 'mainwp-child' );
|
1413 |
+
}
|
1414 |
+
}
|
1415 |
+
|
1416 |
+
return array(
|
1417 |
+
'success' => 1,
|
1418 |
+
'message' => $message,
|
1419 |
+
);
|
1420 |
+
}
|
1421 |
+
|
1422 |
+
/**
|
1423 |
+
* Get job files.
|
1424 |
+
*
|
1425 |
+
* @uses BackWPup_File::get_upload_dir()
|
1426 |
+
* @uses BackWPup_File::get_folder_size()
|
1427 |
+
* @return array Response array containing folder locations and size.
|
1428 |
+
*/
|
1429 |
+
protected function get_job_files() {
|
1430 |
+
/**
|
1431 |
+
* Taken from BackWPup_JobType_File::get_exclude_dirs.
|
1432 |
+
*
|
1433 |
+
* @param array $folder Folders to exclude.
|
1434 |
+
* @return array Return folders list.
|
1435 |
+
*/
|
1436 |
+
function mainwp_backwpup_get_exclude_dirs( $folder ) {
|
1437 |
+
$folder = trailingslashit( str_replace( '\\', '/', realpath( $folder ) ) );
|
1438 |
+
$exclude_dir_array = array();
|
1439 |
+
|
1440 |
+
if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( ABSPATH ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( ABSPATH ) ) ) != $folder ) {
|
1441 |
+
$exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( ABSPATH ) ) );
|
1442 |
+
}
|
1443 |
+
if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( WP_CONTENT_DIR ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( WP_CONTENT_DIR ) ) ) != $folder ) {
|
1444 |
+
$exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( WP_CONTENT_DIR ) ) );
|
1445 |
+
}
|
1446 |
+
if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( WP_PLUGIN_DIR ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( WP_PLUGIN_DIR ) ) ) != $folder ) {
|
1447 |
+
$exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( WP_PLUGIN_DIR ) ) );
|
1448 |
+
}
|
1449 |
+
if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( get_theme_root() ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( get_theme_root() ) ) ) != $folder ) {
|
1450 |
+
$exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( get_theme_root() ) ) );
|
1451 |
+
}
|
1452 |
+
if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( \BackWPup_File::get_upload_dir() ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( \BackWPup_File::get_upload_dir() ) ) ) != $folder ) {
|
1453 |
+
$exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( \BackWPup_File::get_upload_dir() ) ) );
|
1454 |
+
}
|
1455 |
+
|
1456 |
+
return array_unique( $exclude_dir_array );
|
1457 |
+
}
|
1458 |
+
|
1459 |
+
$return = array();
|
1460 |
+
|
1461 |
+
$folders = array(
|
1462 |
+
'abs' => ABSPATH,
|
1463 |
+
'content' => WP_CONTENT_DIR,
|
1464 |
+
'plugin' => WP_PLUGIN_DIR,
|
1465 |
+
'theme' => get_theme_root(),
|
1466 |
+
'upload' => \BackWPup_File::get_upload_dir(),
|
1467 |
+
);
|
1468 |
+
|
1469 |
+
foreach ( $folders as $key => $folder ) {
|
1470 |
+
$return_temp = array();
|
1471 |
+
$main_folder_name = realpath( $folder );
|
1472 |
+
|
1473 |
+
if ( $main_folder_name ) {
|
1474 |
+
$main_folder_name = untrailingslashit( str_replace( '\\', '/', $main_folder_name ) );
|
1475 |
+
$main_folder_size = '(' . size_format( \BackWPup_File::get_folder_size( $main_folder_name, false ), 2 ) . ')';
|
1476 |
+
|
1477 |
+
$dir = opendir( $main_folder_name );
|
1478 |
+
if ( $dir ) {
|
1479 |
+
while ( false !== ( $file = readdir( $dir ) ) ) {
|
1480 |
+
if ( ! in_array( $file, array( '.', '..' ) ) && is_dir( $main_folder_name . '/' . $file ) && ! in_array( trailingslashit( $main_folder_name . '/' . $file ), mainwp_backwpup_get_exclude_dirs( $main_folder_name ) ) ) {
|
1481 |
+
$folder_size = ' (' . size_format( \BackWPup_File::get_folder_size( $main_folder_name . '/' . $file ), 2 ) . ')';
|
1482 |
+
$return_temp[] = array(
|
1483 |
+
'size' => $folder_size,
|
1484 |
+
'name' => $file,
|
1485 |
+
);
|
1486 |
+
|
1487 |
+
}
|
1488 |
+
}
|
1489 |
+
|
1490 |
+
closedir( $dir );
|
1491 |
+
}
|
1492 |
+
|
1493 |
+
$return[ $key ] = array(
|
1494 |
+
'size' => $main_folder_size,
|
1495 |
+
'name' => $folder,
|
1496 |
+
'folders' => $return_temp,
|
1497 |
+
);
|
1498 |
+
}
|
1499 |
+
}
|
1500 |
+
|
1501 |
+
return array(
|
1502 |
+
'success' => 1,
|
1503 |
+
'folders' => $return,
|
1504 |
+
);
|
1505 |
+
}
|
1506 |
+
|
1507 |
+
/**
|
1508 |
+
* Get Child Site Tables.
|
1509 |
+
*
|
1510 |
+
* @uses BackWPup_Option::get()
|
1511 |
+
*
|
1512 |
+
* @return array Query response containing the tables.
|
1513 |
+
*/
|
1514 |
+
protected function get_child_tables() {
|
1515 |
+
|
1516 |
+
/** @global $wpdb wpdb */
|
1517 |
+
global $wpdb;
|
1518 |
+
|
1519 |
+
$return = array();
|
1520 |
+
|
1521 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
1522 |
+
|
1523 |
+
if ( ! empty( $settings['dbhost'] ) && ! empty( $settings['dbuser'] ) ) {
|
1524 |
+
$mysqli = new \mysqli( $settings['dbhost'], $settings['dbuser'], ( isset( $settings['dbpassword'] ) ? $settings['dbpassword'] : '' ) ); // phpcs:ignore -- third party code.
|
1525 |
+
|
1526 |
+
if ( $mysqli->connect_error ) {
|
1527 |
+
$return['message'] = $mysqli->connect_error;
|
1528 |
+
} else {
|
1529 |
+
if ( ! empty( $settings['dbname'] ) ) {
|
1530 |
+
$res = $mysqli->query( 'SHOW FULL TABLES FROM `' . $mysqli->real_escape_string( $settings['dbname'] ) . '`' );
|
1531 |
+
if ( $res ) {
|
1532 |
+
$tables_temp = array();
|
1533 |
+
while ( $table = $res->fetch_array( MYSQLI_NUM ) ) { // phpcs:ignore -- third party code.
|
1534 |
+
$tables_temp[] = $table[0];
|
1535 |
+
}
|
1536 |
+
|
1537 |
+
$res->close();
|
1538 |
+
$return['tables'] = $tables_temp;
|
1539 |
+
}
|
1540 |
+
}
|
1541 |
+
|
1542 |
+
if ( empty( $settings['dbname'] ) || ! empty( $settings['first'] ) ) {
|
1543 |
+
$res = $mysqli->query( 'SHOW DATABASES' );
|
1544 |
+
if ( $res ) {
|
1545 |
+
$databases_temp = array();
|
1546 |
+
while ( $db = $res->fetch_array() ) {
|
1547 |
+
$databases_temp[] = $db['Database'];
|
1548 |
+
}
|
1549 |
+
|
1550 |
+
$res->close();
|
1551 |
+
$return['databases'] = $databases_temp;
|
1552 |
+
}
|
1553 |
+
}
|
1554 |
+
}
|
1555 |
+
$mysqli->close();
|
1556 |
+
} else {
|
1557 |
+
$tables_temp = array();
|
1558 |
+
|
1559 |
+
$tables = $wpdb->get_results( 'SHOW FULL TABLES FROM `' . DB_NAME . '`', ARRAY_N ); // phpcs:ignore -- safe query.
|
1560 |
+
foreach ( $tables as $table ) {
|
1561 |
+
$tables_temp[] = $table[0];
|
1562 |
+
}
|
1563 |
+
|
1564 |
+
$return['tables'] = $tables_temp;
|
1565 |
+
}
|
1566 |
+
|
1567 |
+
if ( isset( $settings['job_id'] ) ) {
|
1568 |
+
$return['dbdumpexclude'] = \BackWPup_Option::get( $settings['job_id'], 'dbdumpexclude' );
|
1569 |
+
}
|
1570 |
+
return array(
|
1571 |
+
'success' => 1,
|
1572 |
+
'return' => $return,
|
1573 |
+
);
|
1574 |
+
}
|
1575 |
+
|
1576 |
+
/**
|
1577 |
+
* Insert or update global jobs.
|
1578 |
+
*
|
1579 |
+
* @uses MainWP_Child_Back_WP_Up::insert_or_update_jobs()
|
1580 |
+
*
|
1581 |
+
* @return array Response array containing job_id, changes & message array.
|
1582 |
+
*/
|
1583 |
+
protected function insert_or_update_jobs_global() {
|
1584 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
1585 |
+
|
1586 |
+
if ( ! is_array( $settings ) ) {
|
1587 |
+
return array( 'error' => __( 'Missing array settings', 'mainwp-child' ) );
|
1588 |
+
}
|
1589 |
+
|
1590 |
+
if ( ! isset( $settings['job_id'] ) ) {
|
1591 |
+
return array( 'error' => __( 'Missing job_id', 'mainwp-child' ) );
|
1592 |
+
}
|
1593 |
+
|
1594 |
+
if ( $settings['job_id'] > 0 ) {
|
1595 |
+
$new_job_id = intval( $settings['job_id'] );
|
1596 |
+
} else {
|
1597 |
+
$new_job_id = null;
|
1598 |
+
}
|
1599 |
+
|
1600 |
+
$changes_array = array();
|
1601 |
+
$message_array = array();
|
1602 |
+
|
1603 |
+
foreach ( $settings['value'] as $key => $val ) {
|
1604 |
+
$temp_array = array();
|
1605 |
+
$temp_array['tab'] = $key;
|
1606 |
+
$temp_array['value'] = $val;
|
1607 |
+
if ( ! is_null( $new_job_id ) ) {
|
1608 |
+
$temp_array['job_id'] = $new_job_id;
|
1609 |
+
} else {
|
1610 |
+
$temp_array['job_id'] = $settings['job_id'];
|
1611 |
+
}
|
1612 |
+
|
1613 |
+
$_POST['settings'] = $temp_array;
|
1614 |
+
$return = $this->insert_or_update_jobs();
|
1615 |
+
|
1616 |
+
if ( is_null( $new_job_id ) ) {
|
1617 |
+
if ( ! isset( $return['job_id'] ) ) {
|
1618 |
+
return array( 'error' => __( 'Missing new job_id', 'mainwp-child' ) );
|
1619 |
+
}
|
1620 |
+
|
1621 |
+
$new_job_id = $return['job_id'];
|
1622 |
+
}
|
1623 |
+
|
1624 |
+
// We want to exit gracefully.
|
1625 |
+
if ( isset( $return['error_message'] ) ) {
|
1626 |
+
$message_array[ $return['error_message'] ] = 1;
|
1627 |
+
}
|
1628 |
+
|
1629 |
+
if ( isset( $return['changes'] ) ) {
|
1630 |
+
$changes_array = array_merge( $changes_array, $return['changes'] );
|
1631 |
+
}
|
1632 |
+
|
1633 |
+
if ( isset( $return['message'] ) ) {
|
1634 |
+
foreach ( $return['message'] as $message ) {
|
1635 |
+
if ( ! isset( $message_array[ $message ] ) ) {
|
1636 |
+
$message_array[ $message ] = 1;
|
1637 |
+
}
|
1638 |
+
}
|
1639 |
+
}
|
1640 |
+
}
|
1641 |
+
|
1642 |
+
return array(
|
1643 |
+
'success' => 1,
|
1644 |
+
'job_id' => $new_job_id,
|
1645 |
+
'changes' => $changes_array,
|
1646 |
+
'message' => array_keys( $message_array ),
|
1647 |
+
);
|
1648 |
+
}
|
1649 |
+
|
1650 |
+
/**
|
1651 |
+
* Edit form post save.
|
1652 |
+
*
|
1653 |
+
* Parses & saves files, folders, boolean fields excluding any unwanted files or directories.
|
1654 |
+
* [Taken from BackWPup_JobType_File::edit_form_post_save with some tweaks].
|
1655 |
+
*
|
1656 |
+
* @uses BackWPup_Option::update()
|
1657 |
+
*
|
1658 |
+
* @param $post_data Post data to save.
|
1659 |
+
* @param $id Post ID.
|
1660 |
+
*/
|
1661 |
+
public function edit_form_post_save($post_data, $id ) {
|
1662 |
+
// Parse and save files to exclude.
|
1663 |
+
$exclude_input = $post_data['fileexclude'];
|
1664 |
+
$to_exclude_list = $exclude_input ? str_replace( array( "\r\n", "\r" ), ',', $exclude_input ) : array();
|
1665 |
+
if ( $to_exclude_list ) {
|
1666 |
+
$to_exclude_list = sanitize_text_field( stripslashes( $to_exclude_list ) );
|
1667 |
+
}
|
1668 |
+
$to_exclude = $to_exclude_list ? explode( ',', $to_exclude_list ) : array();
|
1669 |
+
$to_exclude_parsed = array();
|
1670 |
+
foreach ( $to_exclude as $key => $value ) {
|
1671 |
+
$normalized = wp_normalize_path( trim( $value ) );
|
1672 |
+
if ( $normalized ) {
|
1673 |
+
$to_exclude_parsed[ $key ] = $normalized;
|
1674 |
+
}
|
1675 |
+
}
|
1676 |
+
sort( $to_exclude_parsed );
|
1677 |
+
\BackWPup_Option::update( $id, 'fileexclude', implode( ',', $to_exclude_parsed ) );
|
1678 |
+
unset( $exclude_input, $to_exclude_list, $to_exclude, $to_exclude_parsed, $normalized );
|
1679 |
+
|
1680 |
+
// Parse and save folders to include.
|
1681 |
+
$include_input = $post_data['dirinclude'];
|
1682 |
+
$include_list = $include_input ? str_replace( array( "\r\n", "\r" ), ',', $include_input ) : array();
|
1683 |
+
$to_include = $include_list ? explode( ',', $include_list ) : array();
|
1684 |
+
$to_include_parsed = array();
|
1685 |
+
foreach ( $to_include as $key => $value ) {
|
1686 |
+
$normalized = trailingslashit( wp_normalize_path( trim( $value ) ) );
|
1687 |
+
if ( $normalized ) {
|
1688 |
+
$normalized = filter_var( $normalized, FILTER_SANITIZE_URL );
|
1689 |
+
}
|
1690 |
+
$realpath = $normalized && '/' !== $normalized ? realpath( $normalized ) : false;
|
1691 |
+
if ( $realpath ) {
|
1692 |
+
$to_include_parsed[ $key ] = $realpath;
|
1693 |
+
}
|
1694 |
+
}
|
1695 |
+
sort( $to_include_parsed );
|
1696 |
+
\BackWPup_Option::update( $id, 'dirinclude', implode( ',', $to_include_parsed ) );
|
1697 |
+
unset( $include_input, $include_list, $to_include, $to_include_parsed, $normalized, $realpath );
|
1698 |
+
|
1699 |
+
// Parse and save boolean fields.
|
1700 |
+
$boolean_fields_def = array(
|
1701 |
+
'backupexcludethumbs' => FILTER_VALIDATE_BOOLEAN,
|
1702 |
+
'backupspecialfiles' => FILTER_VALIDATE_BOOLEAN,
|
1703 |
+
'backuproot' => FILTER_VALIDATE_BOOLEAN,
|
1704 |
+
'backupabsfolderup' => FILTER_VALIDATE_BOOLEAN,
|
1705 |
+
'backupcontent' => FILTER_VALIDATE_BOOLEAN,
|
1706 |
+
'backupplugins' => FILTER_VALIDATE_BOOLEAN,
|
1707 |
+
'backupthemes' => FILTER_VALIDATE_BOOLEAN,
|
1708 |
+
'backupuploads' => FILTER_VALIDATE_BOOLEAN,
|
1709 |
+
);
|
1710 |
+
|
1711 |
+
foreach ( $boolean_fields_def as $key => $value ) {
|
1712 |
+
\BackWPup_Option::update( $id, $key, ! empty( $post_data[ $key ] ) );
|
1713 |
+
}
|
1714 |
+
// Parse and save directories to exclude.
|
1715 |
+
$exclude_dirs_def = array(
|
1716 |
+
'backuprootexcludedirs' => array(
|
1717 |
+
'filter' => FILTER_SANITIZE_URL,
|
1718 |
+
'flags' => FILTER_FORCE_ARRAY,
|
1719 |
+
),
|
1720 |
+
'backuppluginsexcludedirs' => array(
|
1721 |
+
'filter' => FILTER_SANITIZE_URL,
|
1722 |
+
'flags' => FILTER_FORCE_ARRAY,
|
1723 |
+
),
|
1724 |
+
'backupcontentexcludedirs' => array(
|
1725 |
+
'filter' => FILTER_SANITIZE_URL,
|
1726 |
+
'flags' => FILTER_FORCE_ARRAY,
|
1727 |
+
),
|
1728 |
+
'backupthemesexcludedirs' => array(
|
1729 |
+
'filter' => FILTER_SANITIZE_URL,
|
1730 |
+
'flags' => FILTER_FORCE_ARRAY,
|
1731 |
+
),
|
1732 |
+
'backupuploadsexcludedirs' => array(
|
1733 |
+
'filter' => FILTER_SANITIZE_URL,
|
1734 |
+
'flags' => FILTER_FORCE_ARRAY,
|
1735 |
+
),
|
1736 |
+
);
|
1737 |
+
foreach ( $exclude_dirs_def as $key => $filter ) {
|
1738 |
+
$value = ! empty( $post_data[ $key ] ) && is_array( $post_data[ $key ] ) ? $post_data[ $key ] : array();
|
1739 |
+
\BackWPup_Option::update( $id, $key, $value );
|
1740 |
+
}
|
1741 |
+
}
|
1742 |
+
|
1743 |
+
/**
|
1744 |
+
* Insert or update jobs.
|
1745 |
+
*
|
1746 |
+
* @uses BackWPup_Option::get_job_ids()
|
1747 |
+
* @uses BackWPup_Option::get()
|
1748 |
+
* @uses BackWPup_Option::update()
|
1749 |
+
* @uses BackWPup_Admin::get_messages()
|
1750 |
+
* @uses BackWPup_Admin::message()
|
1751 |
+
* @uses BackWPup_Job::get_jobrun_url()
|
1752 |
+
* @uses BackWPup_Page_Editjob::save_post_form()
|
1753 |
+
* @uses MainWP_Child_Back_WP_Up::edit_form_post_save()
|
1754 |
+
* @uses MainWP_Child_Back_WP_Up::check_backwpup_messages()
|
1755 |
+
*
|
1756 |
+
* @return array Response array containing job_id, changes & message array.
|
1757 |
+
*/
|
1758 |
+
protected function insert_or_update_jobs() {
|
1759 |
+
|
1760 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
1761 |
+
|
1762 |
+
if ( ! is_array( $settings ) || ! isset( $settings['value'] ) ) {
|
1763 |
+
return array( 'error' => __( 'Missing array settings', 'mainwp-child' ) );
|
1764 |
+
}
|
1765 |
+
|
1766 |
+
if ( ! isset( $settings['tab'] ) ) {
|
1767 |
+
return array( 'error' => __( 'Missing tab', 'mainwp-child' ) );
|
1768 |
+
}
|
1769 |
+
|
1770 |
+
if ( ! isset( $settings['job_id'] ) ) {
|
1771 |
+
return array( 'error' => __( 'Missing job_id', 'mainwp-child' ) );
|
1772 |
+
}
|
1773 |
+
|
1774 |
+
if ( ! class_exists( '\BackWPup' ) ) {
|
1775 |
+
return array( 'error' => __( 'Install BackWPup on child website', 'mainwp-child' ) );
|
1776 |
+
}
|
1777 |
+
|
1778 |
+
if ( $settings['job_id'] > 0 ) {
|
1779 |
+
$job_id = intval( $settings['job_id'] );
|
1780 |
+
} else {
|
1781 |
+
// generate jobid if not exists.
|
1782 |
+
$newjobid = \BackWPup_Option::get_job_ids();
|
1783 |
+
sort( $newjobid );
|
1784 |
+
$job_id = end( $newjobid ) + 1;
|
1785 |
+
}
|
1786 |
+
|
1787 |
+
update_site_option( 'backwpup_messages', array() );
|
1788 |
+
|
1789 |
+
if ( isset( $settings['value']['backupdir'] ) && empty( $settings['value']['backupdir'] ) ) {
|
1790 |
+
$backupdir = \BackWPup_Option::get( (int) $job_id, 'backupdir' );
|
1791 |
+
if ( ! empty( $backupdir ) ) {
|
1792 |
+
$settings['value']['backupdir'] = $backupdir;
|
1793 |
+
}
|
1794 |
+
}
|
1795 |
+
|
1796 |
+
foreach ( $settings['value'] as $key => $val ) {
|
1797 |
+
$_POST[ $key ] = $val;
|
1798 |
+
}
|
1799 |
+
|
1800 |
+
if ( 'jobtype-FILE' == $settings['tab'] ) {
|
1801 |
+
$this->edit_form_post_save( $settings['value'], $job_id );
|
1802 |
+
$messages = \BackWPup_Admin::get_messages();
|
1803 |
+
if ( empty( $messages['error'] ) ) {
|
1804 |
+
$url = \BackWPup_Job::get_jobrun_url( 'runnowlink', $job_id );
|
1805 |
+
\BackWPup_Admin::message( sprintf( __( 'Changes for job <i>%s</i> saved.', 'mainwp-child' ), \BackWPup_Option::get( $job_id, 'name' ) ) . ' <a href="' . network_admin_url( 'admin.php' ) . '?page=backwpupjobs">' . __( 'Jobs overview', 'mainwp-child' ) . '</a> | <a href="' . $url['url'] . '">' . __( 'Run now', 'mainwp-child' ) . '</a>' );
|
1806 |
+
}
|
1807 |
+
} elseif ( 'dest-DROPBOX' == $settings['tab'] ) {
|
1808 |
+
unset( $settings['value'] );
|
1809 |
+
\BackWPup_Page_Editjob::save_post_form( $settings['tab'], $job_id );
|
1810 |
+
} else {
|
1811 |
+
\BackWPup_Page_Editjob::save_post_form( $settings['tab'], $job_id );
|
1812 |
+
}
|
1813 |
+
|
1814 |
+
$return = $this->check_backwpup_messages();
|
1815 |
+
|
1816 |
+
if ( isset( $return['error'] ) ) {
|
1817 |
+
return array(
|
1818 |
+
'success' => 1,
|
1819 |
+
'error_message' => __( 'Cannot save jobs: ' . $return['error'], 'mainwp-child' ),
|
1820 |
+
);
|
1821 |
+
}
|
1822 |
+
|
1823 |
+
if ( isset( $settings['value']['sugarrefreshtoken'] ) ) {
|
1824 |
+
\BackWPup_Option::update( $job_id, 'sugarrefreshtoken', $settings['value']['sugarrefreshtoken'] );
|
1825 |
+
}
|
1826 |
+
|
1827 |
+
if ( isset( $settings['value']['gdriverefreshtoken'] ) ) {
|
1828 |
+
\BackWPup_Option::update( $job_id, 'gdriverefreshtoken', $settings['value']['gdriverefreshtoken'] );
|
1829 |
+
}
|
1830 |
+
|
1831 |
+
if ( isset( $settings['value']['dbdumpspecialsetalltables'] ) && $settings['value']['dbdumpspecialsetalltables'] ) {
|
1832 |
+
\BackWPup_Option::update( $job_id, 'dbdumpexclude', array() );
|
1833 |
+
}
|
1834 |
+
|
1835 |
+
if ( isset( $settings['value']['dropboxtoken'] ) && isset( $settings['value']['dropboxroot'] ) ) {
|
1836 |
+
\BackWPup_Option::update( $job_id, 'dropboxtoken', $settings['value']['dropboxtoken'] );
|
1837 |
+
\BackWPup_Option::update( $job_id, 'dropboxroot', $settings['value']['dropboxroot'] );
|
1838 |
+
}
|
1839 |
+
|
1840 |
+
$changes_array = array();
|
1841 |
+
|
1842 |
+
foreach ( $settings['value'] as $key => $val ) {
|
1843 |
+
$temp_value = \BackWPup_Option::get( $job_id, $key );
|
1844 |
+
if ( is_string( $temp_value ) ) {
|
1845 |
+
if ( isset( $this->exclusions[ $settings['tab'] ] ) ) {
|
1846 |
+
if ( ! in_array( $key, $this->exclusions[ $settings['tab'] ] ) && strcmp( $temp_value, $val ) != 0 ) {
|
1847 |
+
$changes_array[ $key ] = $temp_value;
|
1848 |
+
}
|
1849 |
+
} elseif ( strcmp( $temp_value, $val ) != 0 ) {
|
1850 |
+
$changes_array[ $key ] = $temp_value;
|
1851 |
+
}
|
1852 |
+
}
|
1853 |
+
}
|
1854 |
+
|
1855 |
+
return array(
|
1856 |
+
'success' => 1,
|
1857 |
+
'job_id' => $job_id,
|
1858 |
+
'changes' => $changes_array,
|
1859 |
+
'message' => $return['message'],
|
1860 |
+
);
|
1861 |
+
}
|
1862 |
+
|
1863 |
+
|
1864 |
+
/**
|
1865 |
+
* Update settings.
|
1866 |
+
*
|
1867 |
+
* @uses BackWPup_Page_Settings()
|
1868 |
+
* @uses BackWPup_Page_Settings::save_post_form()
|
1869 |
+
* @uses BackWPup_Pro_Settings_APIKeys::get_instance()
|
1870 |
+
* @uses BackWPup_Pro_Settings_APIKeys::save_form()
|
1871 |
+
* @uses MainWP_Child_Back_WP_Up::check_backwpup_messages()
|
1872 |
+
*
|
1873 |
+
* @return array Response array success, changes, message[].
|
1874 |
+
*/
|
1875 |
+
protected function update_settings() {
|
1876 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
1877 |
+
|
1878 |
+
if ( ! is_array( $settings ) || ! isset( $settings['value'] ) ) {
|
1879 |
+
return array( 'error' => __( 'Missing array settings', 'mainwp-child' ) );
|
1880 |
+
}
|
1881 |
+
|
1882 |
+
if ( ! class_exists( '\BackWPup' ) ) {
|
1883 |
+
return array( 'error' => __( 'Install BackWPup on child website', 'mainwp-child' ) );
|
1884 |
+
}
|
1885 |
+
|
1886 |
+
if ( isset( $settings['value']['is_premium'] ) && 1 == $settings['value']['is_premium'] && false == $this->is_backwpup_pro ) {
|
1887 |
+
return array( 'error' => __( 'You try to use pro version settings in non pro plugin version. Please install pro version on child and try again.', 'mainwp-child' ) );
|
1888 |
+
}
|
1889 |
+
|
1890 |
+
foreach ( $settings['value'] as $key => $val ) {
|
1891 |
+
$_POST[ $key ] = $val;
|
1892 |
+
}
|
1893 |
+
|
1894 |
+
update_site_option( 'backwpup_messages', array() );
|
1895 |
+
|
1896 |
+
$settings_views = array();
|
1897 |
+
$settings_updaters = array();
|
1898 |
+
|
1899 |
+
$backwpup = new \BackWPup_Page_Settings( $settings_views, $settings_updaters );
|
1900 |
+
$backwpup->save_post_form();
|
1901 |
+
|
1902 |
+
if ( class_exists( '\BackWPup_Pro' ) ) {
|
1903 |
+
$pro_settings = \BackWPup_Pro_Settings_APIKeys::get_instance();
|
1904 |
+
$pro_settings->save_form();
|
1905 |
+
|
1906 |
+
}
|
1907 |
+
$return = $this->check_backwpup_messages();
|
1908 |
+
|
1909 |
+
if ( isset( $return['error'] ) ) {
|
1910 |
+
return array( 'error' => __( 'Cannot save settings: ' . $return['error'], 'mainwp-child' ) );
|
1911 |
+
}
|
1912 |
+
|
1913 |
+
$exclusions = array(
|
1914 |
+
'is_premium',
|
1915 |
+
'dropboxappsecret',
|
1916 |
+
'dropboxsandboxappsecret',
|
1917 |
+
'sugarsyncsecret',
|
1918 |
+
'googleclientsecret',
|
1919 |
+
'override',
|
1920 |
+
'httpauthpassword',
|
1921 |
+
);
|
1922 |
+
|
1923 |
+
$changes_array = array();
|
1924 |
+
|
1925 |
+
foreach ( $settings['value'] as $key => $val ) {
|
1926 |
+
|
1927 |
+
$temp_value = get_site_option( 'backwpup_cfg_' . $key, '' );
|
1928 |
+
if ( ! in_array( $key, $exclusions ) && strcmp( $temp_value, $val ) != 0 ) {
|
1929 |
+
$changes_array[ $key ] = $temp_value;
|
1930 |
+
}
|
1931 |
+
}
|
1932 |
+
|
1933 |
+
return array(
|
1934 |
+
'success' => 1,
|
1935 |
+
'changes' => $changes_array,
|
1936 |
+
'message' => $return['message'],
|
1937 |
+
);
|
1938 |
+
}
|
1939 |
+
|
1940 |
+
/**
|
1941 |
+
* Check BackWPup Message.
|
1942 |
+
*
|
1943 |
+
* @return array|string[] Returns an empty array or Error[], Message[].
|
1944 |
+
*/
|
1945 |
+
protected function check_backwpup_messages() {
|
1946 |
+
$message = get_site_option( 'backwpup_messages', array() );
|
1947 |
+
update_site_option( 'backwpup_messages', array() );
|
1948 |
+
|
1949 |
+
if ( isset( $message['error'] ) ) {
|
1950 |
+
return array( 'error' => implode( ', ', $message['error'] ) );
|
1951 |
+
} elseif ( isset( $message['updated'] ) ) {
|
1952 |
+
return array( 'message' => $message['updated'] );
|
1953 |
+
} else {
|
1954 |
+
return array( 'error' => 'Generic error' );
|
1955 |
+
}
|
1956 |
+
}
|
1957 |
}
|
1958 |
|
1959 |
+
// phpcs:disable Generic.Files.OneObjectStructurePerFile -- fake class
|
1960 |
+
if ( ! class_exists( '\MainWP\Child\MainWP_Fake_Wp_Screen' ) ) {
|
1961 |
+
/**
|
1962 |
+
* Class MainWP_Fake_Wp_Screen
|
1963 |
+
*
|
1964 |
+
* @used-by MainWP_Child_Back_WP_Up::wp_list_table_dependency()
|
1965 |
+
*/
|
1966 |
+
class MainWP_Fake_Wp_Screen {
|
1967 |
+
/** @var string Action. */
|
1968 |
+
public $action;
|
1969 |
+
/** @var string Base url. */
|
1970 |
+
public $base;
|
1971 |
+
/** @var int ID*/
|
1972 |
+
public $id;
|
1973 |
+
}
|
1974 |
}
|
class/class-mainwp-child-branding-render.php
ADDED
@@ -0,0 +1,376 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Render Branding
|
4 |
+
*
|
5 |
+
* This file handles rendering the Child Branding settings.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_Branding_Render
|
14 |
+
*
|
15 |
+
* @package MainWP\Child
|
16 |
+
*/
|
17 |
+
class MainWP_Child_Branding_Render {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Public static variable to hold the single instance of the class.
|
21 |
+
*
|
22 |
+
* @var mixed Default null
|
23 |
+
*/
|
24 |
+
public static $instance = null;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Method instance()
|
28 |
+
*
|
29 |
+
* Create a public static instance.
|
30 |
+
*
|
31 |
+
* @return mixed Class instance.
|
32 |
+
*/
|
33 |
+
public static function instance() {
|
34 |
+
if ( null === self::$instance ) {
|
35 |
+
self::$instance = new self();
|
36 |
+
}
|
37 |
+
return self::$instance;
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Get Class Name.
|
42 |
+
*
|
43 |
+
* @return string
|
44 |
+
*/
|
45 |
+
public static function get_class_name() {
|
46 |
+
return __CLASS__;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* MainWP_Child_Branding_Render constructor.
|
51 |
+
*
|
52 |
+
* Run any time the class is called.
|
53 |
+
*/
|
54 |
+
public function __construct() {
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Method admin_head_hide_elements().
|
59 |
+
*/
|
60 |
+
public function admin_head_hide_elements() {
|
61 |
+
?>
|
62 |
+
<script type="text/javascript">
|
63 |
+
document.addEventListener( "DOMContentLoaded", function( event ) {
|
64 |
+
document.getElementById( "wp-admin-bar-updates" ).outerHTML = '';
|
65 |
+
document.getElementById( "menu-plugins" ).outerHTML = '';
|
66 |
+
var els_core = document.querySelectorAll( "a[href='update-core.php']" );
|
67 |
+
for ( var i = 0, l = els_core.length; i < l; i++ ) {
|
68 |
+
var el = els_core[i];
|
69 |
+
el.parentElement.innerHTML = '';
|
70 |
+
}
|
71 |
+
} );
|
72 |
+
</script>
|
73 |
+
<?php
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Render Contact Support.
|
78 |
+
*
|
79 |
+
* @return string Contact Support form html.
|
80 |
+
*/
|
81 |
+
public function contact_support() {
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Current user global.
|
85 |
+
*
|
86 |
+
* @global string
|
87 |
+
*/
|
88 |
+
global $current_user;
|
89 |
+
|
90 |
+
?>
|
91 |
+
<style>
|
92 |
+
.mainwp_info-box-yellow {
|
93 |
+
margin: 5px 0 15px;
|
94 |
+
padding: .6em;
|
95 |
+
background: #ffffe0;
|
96 |
+
border: 1px solid #e6db55;
|
97 |
+
border-radius: 3px;
|
98 |
+
-moz-border-radius: 3px;
|
99 |
+
-webkit-border-radius: 3px;
|
100 |
+
clear: both;
|
101 |
+
}
|
102 |
+
</style>
|
103 |
+
<?php
|
104 |
+
$opts = MainWP_Child_Branding::instance()->child_branding_options;
|
105 |
+
|
106 |
+
if ( isset( $_POST['submit'] ) ) {
|
107 |
+
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), '_contactNonce' ) ) {
|
108 |
+
return false;
|
109 |
+
}
|
110 |
+
$this->render_submit_message( $opts );
|
111 |
+
return;
|
112 |
+
}
|
113 |
+
|
114 |
+
$from_page = '';
|
115 |
+
if ( isset( $_GET['from_page'] ) ) {
|
116 |
+
$from_page = isset( $_GET['from_page'] ) ? rawurldecode( wp_unslash( $_GET['from_page'] ) ) : '';
|
117 |
+
} else {
|
118 |
+
$protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) ), 'off' ) ? 'https://' : 'http://';
|
119 |
+
$fullurl = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? $protocol . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . wp_unslash( $_SERVER['REQUEST_URI'] ) : '';
|
120 |
+
$from_page = rawurldecode( $fullurl );
|
121 |
+
}
|
122 |
+
|
123 |
+
$support_message = $opts['support_message'];
|
124 |
+
$support_message = nl2br( stripslashes( $support_message ) );
|
125 |
+
$from_email = $current_user ? $current_user->user_email : '';
|
126 |
+
?>
|
127 |
+
<form action="" method="post">
|
128 |
+
<div style="width: 99%;">
|
129 |
+
<h2><?php echo esc_html( $opts['contact_label'] ); ?></h2>
|
130 |
+
<div style="height: auto; margin-bottom: 10px; text-align: left">
|
131 |
+
<p><?php echo wp_kses_post( $support_message ); ?></p>
|
132 |
+
<p>
|
133 |
+
<label for="mainwp_branding_contact_message_subject"><?php esc_html_e( 'Subject:', 'mainwp-child' ); ?></label>
|
134 |
+
<br>
|
135 |
+
<input type="text" id="mainwp_branding_contact_message_subject" name="mainwp_branding_contact_message_subject" style="width: 650px;">
|
136 |
+
</p>
|
137 |
+
<p>
|
138 |
+
<label for="mainwp_branding_contact_send_from"><?php esc_html_e( 'From:', 'mainwp-child' ); ?></label>
|
139 |
+
<br>
|
140 |
+
<input type="text" id="mainwp_branding_contact_send_from" name="mainwp_branding_contact_send_from" style="width: 650px;" value="<?php echo esc_attr( $from_email ); ?>">
|
141 |
+
</p>
|
142 |
+
<div style="max-width: 650px;">
|
143 |
+
<label for="mainwp_branding_contact_message_content"><?php esc_html_e( 'Your message:', 'mainwp-child' ); ?></label>
|
144 |
+
<br>
|
145 |
+
<?php
|
146 |
+
remove_editor_styles(); // stop custom theme styling interfering with the editor.
|
147 |
+
wp_editor(
|
148 |
+
'',
|
149 |
+
'mainwp_branding_contact_message_content',
|
150 |
+
array(
|
151 |
+
'textarea_name' => 'mainwp_branding_contact_message_content',
|
152 |
+
'textarea_rows' => 10,
|
153 |
+
'teeny' => true,
|
154 |
+
'wpautop' => true,
|
155 |
+
'media_buttons' => false,
|
156 |
+
)
|
157 |
+
);
|
158 |
+
?>
|
159 |
+
</div>
|
160 |
+
</div>
|
161 |
+
<br/>
|
162 |
+
<?php
|
163 |
+
$button_title = $opts['submit_button_title'];
|
164 |
+
$button_title = ! empty( $button_title ) ? $button_title : __( 'Submit', 'mainwp-child' );
|
165 |
+
?>
|
166 |
+
<input id="mainwp-branding-contact-support-submit" type="submit" name="submit" value="<?php echo esc_attr( $button_title ); ?>" class="button-primary button" style="float: left"/>
|
167 |
+
</div>
|
168 |
+
<input type="hidden" name="mainwp_branding_send_from_page" value="<?php echo esc_url( $from_page ); ?>"/>
|
169 |
+
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( '_contactNonce' ) ); ?>"/>
|
170 |
+
</form>
|
171 |
+
<?php
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Render contact support submit message.
|
176 |
+
*
|
177 |
+
* @param array $opts An array containg message options.
|
178 |
+
*/
|
179 |
+
private function render_submit_message( $opts ) {
|
180 |
+
$from_page = isset( $_POST['mainwp_branding_send_from_page'] ) ? wp_unslash( $_POST['mainwp_branding_send_from_page'] ) : '';
|
181 |
+
$back_link = $opts['message_return_sender'];
|
182 |
+
$back_link = ! empty( $back_link ) ? $back_link : 'Go Back';
|
183 |
+
$back_link = ! empty( $from_page ) ? '<a href="' . esc_url( $from_page ) . '" title="' . esc_attr( $back_link ) . '">' . esc_html( $back_link ) . '</a>' : '';
|
184 |
+
|
185 |
+
if ( $this->send_support_mail() ) {
|
186 |
+
$send_email_message = isset( $opts['send_email_message'] ) ? $opts['send_email_message'] : '';
|
187 |
+
if ( ! empty( $send_email_message ) ) {
|
188 |
+
$send_email_message = stripslashes( $send_email_message );
|
189 |
+
} else {
|
190 |
+
$send_email_message = __( 'Message has been submitted successfully.', 'mainwp-child' );
|
191 |
+
}
|
192 |
+
} else {
|
193 |
+
$send_email_message = __( 'Sending email failed!', 'mainwp-child' );
|
194 |
+
}
|
195 |
+
?>
|
196 |
+
<div class="mainwp_info-box-yellow"><?php echo esc_html( $send_email_message ) . '  ' . $back_link; ?></div>
|
197 |
+
<?php
|
198 |
+
}
|
199 |
+
|
200 |
+
/**
|
201 |
+
* Send support email.
|
202 |
+
*
|
203 |
+
* @return bool Return TRUE on success FALSE on failure.
|
204 |
+
*/
|
205 |
+
public function send_support_mail() {
|
206 |
+
$opts = MainWP_Child_Branding::instance()->get_branding_options();
|
207 |
+
$email = $opts['support_email'];
|
208 |
+
$sub = isset( $_POST['mainwp_branding_contact_message_subject'] ) ? wp_kses_post( nl2br( stripslashes( wp_unslash( $_POST['mainwp_branding_contact_message_subject'] ) ) ) ) : '';
|
209 |
+
$from = isset( $_POST['mainwp_branding_contact_send_from'] ) ? trim( wp_unslash( $_POST['mainwp_branding_contact_send_from'] ) ) : '';
|
210 |
+
$subject = ! empty( $sub ) ? $sub : 'MainWP - Support Contact';
|
211 |
+
$content = isset( $_POST['mainwp_branding_contact_message_content'] ) ? wp_kses_post( nl2br( stripslashes( wp_unslash( $_POST['mainwp_branding_contact_message_content'] ) ) ) ) : '';
|
212 |
+
$mail = '';
|
213 |
+
$headers = '';
|
214 |
+
|
215 |
+
$from_page = isset( $_POST['mainwp_branding_send_from_page'] ) ? wp_unslash( $_POST['mainwp_branding_send_from_page'] ) : '';
|
216 |
+
|
217 |
+
if ( ! empty( $_POST['mainwp_branding_contact_message_content'] ) && ! empty( $email ) ) {
|
218 |
+
|
219 |
+
/**
|
220 |
+
* Current user global.
|
221 |
+
*
|
222 |
+
* @global string
|
223 |
+
*/
|
224 |
+
global $current_user;
|
225 |
+
|
226 |
+
$headers .= "Content-Type: text/html;charset=utf-8\r\n";
|
227 |
+
if ( ! empty( $from ) ) {
|
228 |
+
$headers .= 'From: "' . $from . '" <' . $from . ">\r\n";
|
229 |
+
}
|
230 |
+
$mail .= "<p>Support Email from: <a href='" . site_url() . "'>" . site_url() . "</a></p>\r\n\r\n";
|
231 |
+
$mail .= '<p>Sent from WordPress page: ' . ( ! empty( $from_page ) ? "<a href='" . esc_url( $from_page ) . "'>" . esc_url( $from_page ) . "</a></p>\r\n\r\n" : '' );
|
232 |
+
$mail .= '<p>Client Email: ' . $current_user->user_email . " </p>\r\n\r\n";
|
233 |
+
$mail .= "<p>Support Text:</p>\r\n\r\n";
|
234 |
+
$mail .= '<p>' . $content . "</p>\r\n\r\n";
|
235 |
+
|
236 |
+
wp_mail( $email, $subject, $mail, $headers );
|
237 |
+
|
238 |
+
return true;
|
239 |
+
}
|
240 |
+
return false;
|
241 |
+
}
|
242 |
+
|
243 |
+
/**
|
244 |
+
* After admin bar render.
|
245 |
+
*/
|
246 |
+
public function after_admin_bar_render() {
|
247 |
+
$hide_slugs = apply_filters( 'mainwp_child_hide_update_notice', array() );
|
248 |
+
|
249 |
+
if ( ! is_array( $hide_slugs ) ) {
|
250 |
+
$hide_slugs = array();
|
251 |
+
}
|
252 |
+
|
253 |
+
if ( 0 == count( $hide_slugs ) ) {
|
254 |
+
return;
|
255 |
+
}
|
256 |
+
|
257 |
+
if ( ! function_exists( '\get_plugin_updates' ) ) {
|
258 |
+
include_once ABSPATH . '/wp-admin/includes/update.php';
|
259 |
+
}
|
260 |
+
|
261 |
+
$count_hide = 0;
|
262 |
+
|
263 |
+
$updates = get_plugin_updates();
|
264 |
+
if ( is_array( $updates ) ) {
|
265 |
+
foreach ( $updates as $slug => $data ) {
|
266 |
+
if ( in_array( $slug, $hide_slugs ) ) {
|
267 |
+
$count_hide++;
|
268 |
+
}
|
269 |
+
}
|
270 |
+
}
|
271 |
+
|
272 |
+
if ( 0 == $count_hide ) {
|
273 |
+
return;
|
274 |
+
}
|
275 |
+
?>
|
276 |
+
<script type="text/javascript">
|
277 |
+
var mainwpCountHide = <?php echo esc_attr( $count_hide ); ?>;
|
278 |
+
document.addEventListener( "DOMContentLoaded", function( event ) {
|
279 |
+
var $adminBarUpdates = document.querySelector( '#wp-admin-bar-updates .ab-label' ),
|
280 |
+
itemCount;
|
281 |
+
|
282 |
+
if ( typeof( $adminBarUpdates ) !== 'undefined' && $adminBarUpdates !== null ) {
|
283 |
+
itemCount = $adminBarUpdates.textContent;
|
284 |
+
itemCount = parseInt( itemCount );
|
285 |
+
|
286 |
+
itemCount -= mainwpCountHide;
|
287 |
+
if ( itemCount < 0 )
|
288 |
+
itemCount = 0;
|
289 |
+
|
290 |
+
$adminBarUpdates.textContent = itemCount;
|
291 |
+
}
|
292 |
+
} );
|
293 |
+
</script>
|
294 |
+
<?php
|
295 |
+
}
|
296 |
+
|
297 |
+
/**
|
298 |
+
* Admin footer text.
|
299 |
+
*/
|
300 |
+
public function in_admin_footer() {
|
301 |
+
$hide_slugs = apply_filters( 'mainwp_child_hide_update_notice', array() );
|
302 |
+
|
303 |
+
if ( ! is_array( $hide_slugs ) ) {
|
304 |
+
$hide_slugs = array();
|
305 |
+
}
|
306 |
+
|
307 |
+
$count_hide = 0;
|
308 |
+
|
309 |
+
$updates = get_plugin_updates();
|
310 |
+
if ( is_array( $updates ) ) {
|
311 |
+
foreach ( $updates as $slug => $data ) {
|
312 |
+
if ( in_array( $slug, $hide_slugs ) ) {
|
313 |
+
$count_hide++;
|
314 |
+
}
|
315 |
+
}
|
316 |
+
}
|
317 |
+
|
318 |
+
if ( 0 == $count_hide ) {
|
319 |
+
return;
|
320 |
+
}
|
321 |
+
|
322 |
+
?>
|
323 |
+
<script type="text/javascript">
|
324 |
+
var mainwpCountHide = <?php echo esc_attr( $count_hide ); ?>;
|
325 |
+
document.addEventListener( "DOMContentLoaded", function( event ) {
|
326 |
+
if ( typeof( pagenow ) !== 'undefined' && pagenow == 'plugins' ) {
|
327 |
+
<?php
|
328 |
+
// hide update notice row.
|
329 |
+
if ( in_array( 'mainwp-child/mainwp-child.php', $hide_slugs ) ) {
|
330 |
+
?>
|
331 |
+
var el = document.querySelector( 'tr#mainwp-child-update' );
|
332 |
+
if ( typeof( el ) !== 'undefined' && el !== null ) {
|
333 |
+
el.style.display = 'none';
|
334 |
+
}
|
335 |
+
<?php
|
336 |
+
}
|
337 |
+
// hide update notice row.
|
338 |
+
if ( in_array( 'mainwp-child-reports/mainwp-child-reports.php', $hide_slugs ) ) {
|
339 |
+
?>
|
340 |
+
var el = document.querySelector( 'tr#mainwp-child-reports-update' );
|
341 |
+
if ( typeof( el ) !== 'undefined' && el !== null ) {
|
342 |
+
el.style.display = 'none';
|
343 |
+
}
|
344 |
+
<?php
|
345 |
+
}
|
346 |
+
?>
|
347 |
+
}
|
348 |
+
|
349 |
+
if ( mainwpCountHide > 0 ) {
|
350 |
+
jQuery( document ).ready( function () {
|
351 |
+
|
352 |
+
var $adminBarUpdates = jQuery( '#wp-admin-bar-updates' ),
|
353 |
+
$pluginsNavMenuUpdateCount = jQuery( 'a[href="plugins.php"] .update-plugins' ),
|
354 |
+
itemCount;
|
355 |
+
itemCount = $adminBarUpdates.find( '.ab-label' ).text();
|
356 |
+
itemCount -= mainwpCountHide;
|
357 |
+
if ( itemCount < 0 )
|
358 |
+
itemCount = 0;
|
359 |
+
|
360 |
+
itemPCount = $pluginsNavMenuUpdateCount.find( '.plugin-count' ).text();
|
361 |
+
itemPCount -= mainwpCountHide;
|
362 |
+
|
363 |
+
if ( itemPCount < 0 )
|
364 |
+
itemPCount = 0;
|
365 |
+
|
366 |
+
$adminBarUpdates.find( '.ab-label' ).text( itemCount );
|
367 |
+
$pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( itemPCount );
|
368 |
+
|
369 |
+
} );
|
370 |
+
}
|
371 |
+
} );
|
372 |
+
</script>
|
373 |
+
<?php
|
374 |
+
}
|
375 |
+
|
376 |
+
}
|
class/class-mainwp-child-branding.php
CHANGED
@@ -1,78 +1,142 @@
|
|
1 |
<?php
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
class MainWP_Child_Branding {
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
public static $instance = null;
|
5 |
|
|
|
|
|
|
|
|
|
|
|
6 |
public $child_plugin_dir;
|
7 |
-
public $child_branding_options = null;
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
}
|
13 |
-
return
|
14 |
}
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
public function __construct() {
|
17 |
$this->child_plugin_dir = dirname( dirname( __FILE__ ) );
|
18 |
add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) );
|
19 |
add_filter( 'mainwp_child_plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 3 );
|
20 |
-
|
21 |
}
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
$opts['extra_settings'] = get_option( 'mainwp_branding_extra_settings' );
|
38 |
-
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $opts );
|
39 |
-
}
|
40 |
-
|
41 |
-
if ( !isset($opts['contact_label']) || empty($opts['contact_label']) ) {
|
42 |
-
$opts['contact_label'] = 'Contact Support';
|
43 |
-
}
|
44 |
-
|
45 |
-
$disconnected = isset( $opts['branding_disconnected'] ) ? $opts['branding_disconnected'] : '';
|
46 |
-
$preserve_branding = isset( $opts['preserve_branding'] ) ? $opts['preserve_branding'] : '';
|
47 |
-
$cancelled_branding = ( $disconnected === 'yes' ) && ! $preserve_branding;
|
48 |
-
|
49 |
-
$opts['cancelled_branding'] = $cancelled_branding;
|
50 |
-
$opts['branding_preserve_title'] = '';
|
51 |
-
|
52 |
-
if ( ! $cancelled_branding ) {
|
53 |
-
if (isset($opts['branding_header'])) {
|
54 |
-
$branding_header = $opts['branding_header'];
|
55 |
-
if ( is_array( $branding_header ) && isset( $branding_header['name'] ) && ! empty( $branding_header['name'] ) ) {
|
56 |
-
$opts['branding_preserve_title'] = stripslashes( $branding_header['name'] );
|
57 |
-
}
|
58 |
-
}
|
59 |
-
}
|
60 |
-
|
61 |
-
$opts = apply_filters( 'mainwp_child_branding_init_options', $opts );
|
62 |
-
return $opts;
|
63 |
-
}
|
64 |
-
|
65 |
-
function get_extra_options() {
|
66 |
-
$extra = array();
|
67 |
-
if (is_array($this->child_branding_options) && isset($this->child_branding_options['extra_settings'])) {
|
68 |
-
$extra = $this->child_branding_options['extra_settings'];
|
69 |
-
if (!is_array($extra))
|
70 |
-
$extra = array();
|
71 |
-
}
|
72 |
-
|
73 |
-
return $extra;
|
74 |
-
}
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
public function plugin_row_meta( $plugin_meta, $plugin_file, $child_plugin_slug ) {
|
77 |
if ( $child_plugin_slug !== $plugin_file ) {
|
78 |
return $plugin_meta;
|
@@ -81,7 +145,7 @@ class MainWP_Child_Branding {
|
|
81 |
if ( ! $this->is_branding() ) {
|
82 |
return $plugin_meta;
|
83 |
}
|
84 |
-
// hide View details links
|
85 |
$meta_total = count( $plugin_meta );
|
86 |
for ( $i = 0; $i < $meta_total; $i++ ) {
|
87 |
$str_meta = $plugin_meta[ $i ];
|
@@ -94,69 +158,52 @@ class MainWP_Child_Branding {
|
|
94 |
return $plugin_meta;
|
95 |
}
|
96 |
|
|
|
|
|
|
|
|
|
|
|
97 |
public function child_deactivation() {
|
98 |
-
|
99 |
-
|
100 |
-
'
|
101 |
-
'
|
102 |
-
'
|
103 |
-
'
|
104 |
-
'
|
105 |
-
'
|
106 |
-
'
|
107 |
-
'
|
108 |
-
'
|
109 |
-
'
|
110 |
-
'
|
111 |
-
'
|
112 |
-
|
113 |
-
'
|
114 |
-
'
|
115 |
-
'
|
116 |
-
'
|
117 |
-
'mainwp_branding_extra_settings',
|
118 |
-
'mainwp_branding_ext_enabled',
|
119 |
);
|
120 |
|
121 |
-
foreach ( $
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
'disable_change',
|
128 |
-
'disable_switching_theme',
|
129 |
-
'show_support',
|
130 |
-
'support_email',
|
131 |
-
'support_message',
|
132 |
-
'remove_restore',
|
133 |
-
'remove_setting',
|
134 |
-
'remove_server_info',
|
135 |
-
'remove_wp_tools',
|
136 |
-
'remove_wp_setting',
|
137 |
-
'remove_permalink',
|
138 |
-
//'branding_header', // don't remove header
|
139 |
-
'contact_label',
|
140 |
-
'email_message',
|
141 |
-
'message_return_sender',
|
142 |
-
'submit_button_title',
|
143 |
-
'extra_settings',
|
144 |
-
'branding_ext_enabled',
|
145 |
-
);
|
146 |
-
|
147 |
-
foreach($brandingOptions_empty as $opt) {
|
148 |
-
if (isset($this->child_branding_options[$opt])) {
|
149 |
-
$this->child_branding_options[$opt] = '';
|
150 |
-
}
|
151 |
-
}
|
152 |
-
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options );
|
153 |
-
|
154 |
}
|
155 |
|
156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
public function action() {
|
158 |
$information = array();
|
159 |
-
|
|
|
160 |
case 'update_branding':
|
161 |
$information = $this->update_branding();
|
162 |
break;
|
@@ -164,65 +211,79 @@ class MainWP_Child_Branding {
|
|
164 |
MainWP_Helper::write( $information );
|
165 |
}
|
166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
public function update_branding() {
|
168 |
$information = array();
|
169 |
-
$settings = maybe_unserialize( base64_decode( $_POST['settings'] ) );
|
170 |
if ( ! is_array( $settings ) ) {
|
171 |
return $information;
|
172 |
}
|
173 |
|
174 |
-
|
175 |
-
|
176 |
|
177 |
-
|
178 |
-
$current_settings['branding_ext_enabled'] = 'Y';
|
179 |
|
180 |
-
$header
|
181 |
'name' => $settings['child_plugin_name'],
|
182 |
'description' => $settings['child_plugin_desc'],
|
183 |
'author' => $settings['child_plugin_author'],
|
184 |
'authoruri' => $settings['child_plugin_author_uri'],
|
185 |
-
'pluginuri' => isset($settings['child_plugin_uri']) ? $settings['child_plugin_uri'] : '',
|
186 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
$current_settings['preserve_branding'] = $settings['child_preserve_branding'];
|
208 |
-
$current_settings['branding_header'] = $header;
|
209 |
-
$current_settings['support_email'] = $settings['child_support_email'];
|
210 |
-
$current_settings['support_message'] = $settings['child_support_message'];
|
211 |
-
$current_settings['remove_restore'] = $settings['child_remove_restore'];
|
212 |
-
$current_settings['remove_setting'] = $settings['child_remove_setting'];
|
213 |
-
$current_settings['remove_server_info'] = $settings['child_remove_server_info'];
|
214 |
-
$current_settings['remove_connection_detail'] = isset($settings['child_remove_connection_detail']) ? $settings['child_remove_connection_detail'] : 0 ;
|
215 |
-
$current_settings['remove_wp_tools'] = $settings['child_remove_wp_tools'];
|
216 |
-
$current_settings['remove_wp_setting'] = $settings['child_remove_wp_setting'];
|
217 |
-
$current_settings['remove_permalink'] = $settings['child_remove_permalink'];
|
218 |
-
$current_settings['contact_label'] = $settings['child_button_contact_label'];
|
219 |
-
$current_settings['email_message'] = $settings['child_send_email_message'];
|
220 |
-
$current_settings['return_sender'] = $settings['child_message_return_sender'];
|
221 |
-
$current_settings['submit_button_title'] = $settings['child_submit_button_title'];
|
222 |
-
|
223 |
-
if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) {
|
224 |
-
$current_settings['disable_wp_branding'] = $settings['child_disable_wp_branding'];
|
225 |
-
}
|
226 |
|
227 |
$extra_setting = array(
|
228 |
'show_button_in' => $settings['child_show_support_button_in'],
|
@@ -233,8 +294,8 @@ class MainWP_Child_Branding {
|
|
233 |
'remove_widget_activity' => $settings['child_remove_widget_activity'],
|
234 |
'remove_widget_quick' => $settings['child_remove_widget_quick'],
|
235 |
'remove_widget_news' => $settings['child_remove_widget_news'],
|
236 |
-
'login_image_link'
|
237 |
-
'login_image_title'
|
238 |
'site_generator' => $settings['child_site_generator'],
|
239 |
'generator_link' => $settings['child_generator_link'],
|
240 |
'admin_css' => $settings['child_admin_css'],
|
@@ -266,21 +327,24 @@ class MainWP_Child_Branding {
|
|
266 |
$extra_setting['login_image'] = array();
|
267 |
} else {
|
268 |
try {
|
269 |
-
$upload = $this->
|
270 |
if ( null !== $upload ) {
|
271 |
-
$extra_setting['login_image'] = array(
|
|
|
|
|
|
|
272 |
if ( isset( $current_extra_setting['login_image']['path'] ) ) {
|
273 |
$old_file = $current_extra_setting['login_image']['path'];
|
274 |
if ( ! empty( $old_file ) && file_exists( $old_file ) ) {
|
275 |
-
|
276 |
}
|
277 |
}
|
278 |
}
|
279 |
-
} catch ( Exception $e ) {
|
280 |
$information['error']['login_image'] = $e->getMessage();
|
281 |
}
|
282 |
}
|
283 |
-
}
|
284 |
$extra_setting['login_image'] = $current_extra_setting['login_image'];
|
285 |
}
|
286 |
|
@@ -289,82 +353,60 @@ class MainWP_Child_Branding {
|
|
289 |
$extra_setting['favico_image'] = array();
|
290 |
} else {
|
291 |
try {
|
292 |
-
$upload = $this->
|
293 |
if ( null !== $upload ) {
|
294 |
-
$extra_setting['favico_image'] = array(
|
|
|
|
|
|
|
295 |
if ( isset( $current_extra_setting['favico_image']['path'] ) ) {
|
296 |
$old_file = $current_extra_setting['favico_image']['path'];
|
297 |
if ( ! empty( $old_file ) && file_exists( $old_file ) ) {
|
298 |
-
|
299 |
}
|
300 |
}
|
301 |
}
|
302 |
-
} catch ( Exception $e ) {
|
303 |
$information['error']['favico_image'] = $e->getMessage();
|
304 |
}
|
305 |
}
|
306 |
-
}
|
307 |
$extra_setting['favico_image'] = $current_extra_setting['favico_image'];
|
308 |
}
|
309 |
-
|
310 |
-
//MainWP_Helper::update_option( 'mainwp_branding_extra_settings', $extra_setting, 'yes' );
|
311 |
-
$current_settings['extra_settings'] = $extra_setting;
|
312 |
-
|
313 |
-
// keep it to compatible with old version of child reports plugin
|
314 |
-
if ( $settings['child_plugin_hide'] ) {
|
315 |
-
MainWP_Helper::update_option( 'mainwp_branding_child_hide', 'T', 'yes' );
|
316 |
-
} else {
|
317 |
-
MainWP_Helper::update_option( 'mainwp_branding_child_hide', '' );
|
318 |
-
}
|
319 |
-
//
|
320 |
-
// if ( $settings['child_show_support_button'] && ! empty( $settings['child_support_email'] ) ) {
|
321 |
-
// MainWP_Helper::update_option( 'mainwp_branding_show_support', 'T' );
|
322 |
-
// } else {
|
323 |
-
// MainWP_Helper::update_option( 'mainwp_branding_show_support', '' );
|
324 |
-
// }
|
325 |
-
|
326 |
-
// if ( $settings['child_disable_change'] ) {
|
327 |
-
// MainWP_Helper::update_option( 'mainwp_branding_disable_change', 'T' );
|
328 |
-
// } else {
|
329 |
-
// MainWP_Helper::update_option( 'mainwp_branding_disable_change', '' );
|
330 |
-
// }
|
331 |
-
|
332 |
-
// if ( $settings['child_disable_switching_theme'] ) {
|
333 |
-
// MainWP_Helper::update_option( 'mainwp_branding_disable_switching_theme', 'T' );
|
334 |
-
// } else {
|
335 |
-
// MainWP_Helper::update_option( 'mainwp_branding_disable_switching_theme', '' );
|
336 |
-
// }
|
337 |
-
|
338 |
-
$current_settings['hide'] = $settings['child_plugin_hide'] ? 'T' : '';
|
339 |
-
$current_settings['show_support'] = ( $settings['child_show_support_button'] && !empty($settings['child_support_email']) ) ? 'T' : '';
|
340 |
-
$current_settings['disable_change'] = $settings['child_disable_change'] ? 'T' : '';
|
341 |
-
$current_settings['disable_switching_theme'] = $settings['child_disable_switching_theme'] ? 'T' : '';
|
342 |
-
|
343 |
-
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $current_settings );
|
344 |
-
|
345 |
-
$information['result'] = 'SUCCESS';
|
346 |
-
|
347 |
-
return $information;
|
348 |
}
|
349 |
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
$temporary_file = download_url( $img_url );
|
356 |
-
|
357 |
|
358 |
if ( is_wp_error( $temporary_file ) ) {
|
359 |
-
throw new Exception(
|
360 |
} else {
|
361 |
$upload_dir = wp_upload_dir();
|
362 |
-
$local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url );
|
363 |
$local_img_path = dirname( $local_img_path ) . '/' . wp_unique_filename( dirname( $local_img_path ), basename( $local_img_path ) );
|
364 |
$local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path );
|
365 |
-
$moved =
|
366 |
if ( $moved ) {
|
367 |
-
return array(
|
|
|
|
|
|
|
368 |
}
|
369 |
}
|
370 |
if ( file_exists( $temporary_file ) ) {
|
@@ -374,71 +416,90 @@ class MainWP_Child_Branding {
|
|
374 |
return null;
|
375 |
}
|
376 |
|
377 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
378 |
public function branding_init() {
|
379 |
|
380 |
$extra_setting = $this->get_extra_options();
|
381 |
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
}
|
390 |
-
$opts = $this->child_branding_options;
|
391 |
|
392 |
$cancelled_branding = $opts['cancelled_branding'];
|
|
|
393 |
if ( $cancelled_branding ) {
|
394 |
return;
|
395 |
}
|
396 |
|
397 |
-
|
398 |
add_filter( 'all_plugins', array( $this, 'modify_plugin_header' ) );
|
399 |
|
400 |
if ( $this->is_branding() ) {
|
401 |
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
402 |
-
|
403 |
}
|
404 |
|
405 |
-
|
406 |
return;
|
407 |
}
|
408 |
|
409 |
add_filter( 'map_meta_cap', array( $this, 'branding_map_meta_cap' ), 10, 5 );
|
410 |
|
411 |
-
if ( 'T' === $opts['disable_change']) {
|
412 |
|
413 |
-
// Disable the
|
414 |
-
remove_action('load-update-core.php', 'wp_update_plugins');
|
415 |
-
add_filter('pre_site_transient_update_plugins', '__return_null');
|
416 |
|
417 |
-
// Disable the
|
418 |
-
remove_action('load-update-core.php', 'wp_update_themes');
|
419 |
-
add_filter(
|
|
|
|
|
|
|
|
|
|
|
420 |
|
421 |
-
|
422 |
-
|
|
|
|
|
|
|
423 |
function remove_core_updates() {
|
424 |
-
add_action(
|
425 |
-
|
426 |
-
|
427 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
|
429 |
-
add_action( 'admin_head', array(
|
430 |
-
add_action( 'admin_menu', array($this, 'branding_redirect' ), 9);
|
431 |
}
|
432 |
|
433 |
-
|
434 |
-
|
435 |
-
if ( !isset($opts['disable_wp_branding']) || $opts['disable_wp_branding']
|
436 |
add_filter( 'wp_footer', array( &$this, 'branding_global_footer' ), 15 );
|
437 |
add_action( 'wp_dashboard_setup', array( &$this, 'custom_dashboard_widgets' ), 999 );
|
438 |
-
// branding site generator
|
439 |
$types = array( 'html', 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export' );
|
440 |
foreach ( $types as $type ) {
|
441 |
-
add_filter( 'get_the_generator_' . $type, array( &$this, '
|
442 |
}
|
443 |
add_action( 'admin_head', array( &$this, 'custom_admin_css' ) );
|
444 |
add_action( 'login_enqueue_scripts', array( &$this, 'custom_login_css' ) );
|
@@ -448,13 +509,12 @@ class MainWP_Child_Branding {
|
|
448 |
add_filter( 'login_headertext', array( &$this, 'custom_login_headertitle' ) );
|
449 |
add_action( 'wp_head', array( &$this, 'custom_favicon_frontend' ) );
|
450 |
if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) {
|
451 |
-
//remove_filter( 'update_footer', 'core_update_footer' );
|
452 |
add_filter( 'update_footer', array( &$this, 'core_update_footer' ), 14 );
|
453 |
-
|
454 |
}
|
455 |
|
456 |
if ( isset( $extra_setting['hide_nag'] ) && ! empty( $extra_setting['hide_nag'] ) ) {
|
457 |
-
add_action( 'admin_init', array($this, 'admin_init'));
|
458 |
}
|
459 |
|
460 |
add_action( 'admin_menu', array( &$this, 'remove_default_post_metaboxes' ) );
|
@@ -462,48 +522,82 @@ class MainWP_Child_Branding {
|
|
462 |
}
|
463 |
}
|
464 |
|
465 |
-
|
|
|
|
|
|
|
|
|
466 |
public function admin_init() {
|
467 |
remove_action( 'admin_notices', 'update_nag', 3 );
|
468 |
}
|
469 |
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
476 |
return false;
|
477 |
}
|
478 |
|
479 |
-
|
480 |
-
if ( empty
|
481 |
return false;
|
482 |
}
|
483 |
-
|
484 |
|
485 |
if ( 'T' === $opts['show_support'] ) {
|
486 |
$title = $opts['contact_label'];
|
487 |
if ( isset( $extra_setting['show_button_in'] ) && ( 2 === (int) $extra_setting['show_button_in'] || 3 === (int) $extra_setting['show_button_in'] ) ) {
|
488 |
$title = $opts['contact_label'];
|
489 |
-
add_menu_page(
|
490 |
-
$
|
491 |
-
|
492 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
493 |
}
|
494 |
|
495 |
if ( isset( $extra_setting['show_button_in'] ) && ( 1 === $extra_setting['show_button_in'] || 3 === $extra_setting['show_button_in'] ) ) {
|
496 |
-
add_submenu_page(
|
497 |
-
|
498 |
-
|
499 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
500 |
add_action( 'admin_bar_menu', array( $this, 'add_support_button_in_top_admin_bar' ), 100 );
|
501 |
}
|
502 |
}
|
503 |
-
|
504 |
}
|
505 |
|
506 |
-
|
|
|
|
|
|
|
|
|
|
|
507 |
$extra_setting = $this->get_extra_options();
|
508 |
|
509 |
add_filter( 'manage_posts_columns', array( &$this, 'custom_post_columns' ) );
|
@@ -542,8 +636,16 @@ class MainWP_Child_Branding {
|
|
542 |
}
|
543 |
}
|
544 |
|
545 |
-
|
546 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
547 |
$extra_setting = $this->get_extra_options();
|
548 |
|
549 |
if ( isset( $extra_setting['hide_metabox_post_comments'] ) && $extra_setting['hide_metabox_post_comments'] ) {
|
@@ -559,7 +661,16 @@ class MainWP_Child_Branding {
|
|
559 |
return $defaults;
|
560 |
}
|
561 |
|
562 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
563 |
$extra_setting = $this->get_extra_options();
|
564 |
|
565 |
if ( isset( $extra_setting['hide_metabox_post_slug'] ) && $extra_setting['hide_metabox_post_slug'] ) {
|
@@ -569,12 +680,17 @@ class MainWP_Child_Branding {
|
|
569 |
return $defaults;
|
570 |
}
|
571 |
|
572 |
-
|
|
|
|
|
|
|
|
|
|
|
573 |
$extra_setting = $this->get_extra_options();
|
574 |
|
575 |
add_filter( 'manage_pages_columns', array( &$this, 'custom_pages_columns' ) );
|
576 |
|
577 |
-
if ( isset( $extra_setting['hide_metabox_page_custom_fields'] ) && $extra_setting['hide_metabox_page_custom_fields'] ) {
|
578 |
remove_meta_box( 'postcustom', 'page', 'normal' );
|
579 |
}
|
580 |
if ( isset( $extra_setting['hide_metabox_page_author'] ) && $extra_setting['hide_metabox_page_author'] ) {
|
@@ -597,7 +713,16 @@ class MainWP_Child_Branding {
|
|
597 |
}
|
598 |
}
|
599 |
|
600 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
601 |
$extra_setting = $this->get_extra_options();
|
602 |
|
603 |
if ( isset( $extra_setting['hide_metabox_page_comments'] ) && $extra_setting['hide_metabox_page_comments'] ) {
|
@@ -610,41 +735,47 @@ class MainWP_Child_Branding {
|
|
610 |
return $defaults;
|
611 |
}
|
612 |
|
|
|
|
|
|
|
|
|
|
|
613 |
public function branding_redirect() {
|
614 |
-
$pos1 = stripos( $_SERVER['REQUEST_URI'], 'update-core.php' );
|
615 |
-
$pos2 = stripos( $_SERVER['REQUEST_URI'], 'plugins.php' );
|
616 |
if ( false !== $pos1 || false !== $pos2 ) {
|
617 |
-
|
618 |
exit();
|
619 |
}
|
620 |
}
|
621 |
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
var el = els_core[i];
|
630 |
-
el.parentElement.innerHTML = '';
|
631 |
-
}
|
632 |
-
});
|
633 |
-
</script><?php
|
634 |
-
}
|
635 |
-
|
636 |
-
function core_update_footer() {
|
637 |
-
echo ''; // it clear version text
|
638 |
}
|
639 |
|
640 |
-
|
|
|
|
|
|
|
|
|
|
|
641 |
$extra_setting = $this->get_extra_options();
|
642 |
if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) {
|
643 |
echo wp_kses_post( nl2br( stripslashes( $extra_setting['dashboard_footer'] ) ) );
|
644 |
}
|
645 |
}
|
646 |
|
647 |
-
|
|
|
|
|
|
|
|
|
|
|
648 |
$extra_setting = $this->get_extra_options();
|
649 |
if ( isset( $extra_setting['favico_image']['url'] ) && ! empty( $extra_setting['favico_image']['url'] ) ) {
|
650 |
$favico = $extra_setting['favico_image']['url'];
|
@@ -652,18 +783,29 @@ class MainWP_Child_Branding {
|
|
652 |
}
|
653 |
}
|
654 |
|
655 |
-
|
|
|
|
|
|
|
|
|
|
|
656 |
$extra_setting = $this->get_extra_options();
|
657 |
if ( isset( $extra_setting['login_image']['url'] ) && ! empty( $extra_setting['login_image']['url'] ) ) {
|
658 |
$login_logo = $extra_setting['login_image']['url'];
|
659 |
-
echo '<style type="text/css">
|
660 |
-
#login h1 a { background-image: url(\'' . esc_url( $login_logo ) . '\') !important; height:70px !important; width:310px !important; background-size: auto auto !important; }
|
661 |
-
</style>';
|
662 |
}
|
663 |
}
|
664 |
|
665 |
-
|
666 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
667 |
$extra_setting = $this->get_extra_options();
|
668 |
if ( isset( $extra_setting['login_image_link'] ) && ! empty( $extra_setting['login_image_link'] ) ) {
|
669 |
return $extra_setting['login_image_link'];
|
@@ -672,8 +814,16 @@ class MainWP_Child_Branding {
|
|
672 |
return $value;
|
673 |
}
|
674 |
|
675 |
-
|
676 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
677 |
$extra_setting = $this->get_extra_options();
|
678 |
if ( isset( $extra_setting['login_image_title'] ) && ! empty( $extra_setting['login_image_title'] ) ) {
|
679 |
return $extra_setting['login_image_title'];
|
@@ -682,7 +832,18 @@ class MainWP_Child_Branding {
|
|
682 |
return $value;
|
683 |
}
|
684 |
|
685 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
686 |
$extra_setting = $this->get_extra_options();
|
687 |
$texts_replace = $extra_setting['texts_replace'];
|
688 |
if ( is_array( $texts_replace ) && count( $texts_replace ) > 0 ) {
|
@@ -696,7 +857,12 @@ class MainWP_Child_Branding {
|
|
696 |
return $translations;
|
697 |
}
|
698 |
|
699 |
-
|
|
|
|
|
|
|
|
|
|
|
700 |
$header_css = '';
|
701 |
$extra_setting = $this->get_extra_options();
|
702 |
|
@@ -714,18 +880,143 @@ class MainWP_Child_Branding {
|
|
714 |
}
|
715 |
|
716 |
if ( ! empty( $header_css ) ) {
|
717 |
-
echo '<style>' .
|
718 |
}
|
719 |
}
|
720 |
|
721 |
-
|
|
|
|
|
|
|
|
|
|
|
722 |
$extra_setting = $this->get_extra_options();
|
723 |
if ( isset( $extra_setting['login_css'] ) && ! empty( $extra_setting['login_css'] ) ) {
|
724 |
-
echo '<style>' .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
725 |
}
|
|
|
726 |
}
|
727 |
|
728 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
729 |
$extra_setting = $this->get_extra_options();
|
730 |
if ( isset( $extra_setting['site_generator'] ) ) {
|
731 |
if ( ! empty( $extra_setting['site_generator'] ) ) {
|
@@ -755,7 +1046,7 @@ class MainWP_Child_Branding {
|
|
755 |
$generator = '<!-- generator="' . $extra_setting['site_generator'] . '" -->';
|
756 |
break;
|
757 |
case 'export':
|
758 |
-
$generator = '<!-- generator="' . $extra_setting['site_generator'] . '" created="' . date( 'Y-m-d H:i' ) . '" -->';
|
759 |
break;
|
760 |
endswitch;
|
761 |
|
@@ -766,8 +1057,20 @@ class MainWP_Child_Branding {
|
|
766 |
return $generator;
|
767 |
}
|
768 |
|
769 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
770 |
global $wp_meta_boxes;
|
|
|
771 |
$extra_setting = $this->get_extra_options();
|
772 |
if ( isset( $extra_setting['remove_widget_welcome'] ) && $extra_setting['remove_widget_welcome'] ) {
|
773 |
remove_action( 'welcome_panel', 'wp_welcome_panel' );
|
@@ -786,6 +1089,11 @@ class MainWP_Child_Branding {
|
|
786 |
}
|
787 |
}
|
788 |
|
|
|
|
|
|
|
|
|
|
|
789 |
public function branding_global_footer() {
|
790 |
$extra_setting = $this->get_extra_options();
|
791 |
if ( isset( $extra_setting['global_footer'] ) && ! empty( $extra_setting['global_footer'] ) ) {
|
@@ -793,146 +1101,36 @@ class MainWP_Child_Branding {
|
|
793 |
}
|
794 |
}
|
795 |
|
796 |
-
public function send_support_mail() {
|
797 |
-
$email = $this->child_branding_options['support_email'];
|
798 |
-
$sub = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_subject'] ) ) );
|
799 |
-
$from = trim($_POST['mainwp_branding_contact_send_from']);
|
800 |
-
$subject = !empty( $sub ) ? $sub : "MainWP - Support Contact";
|
801 |
-
$content = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_content'] ) ) );
|
802 |
-
$mail = $headers = '';
|
803 |
-
if ( ! empty( $_POST['mainwp_branding_contact_message_content'] ) && ! empty( $email ) ) {
|
804 |
-
global $current_user;
|
805 |
-
$headers .= "Content-Type: text/html;charset=utf-8\r\n";
|
806 |
-
if (!empty($from))
|
807 |
-
$headers .= "From: \"" . $from . "\" <" . $from . ">\r\n";
|
808 |
-
$mail .= "<p>Support Email from: <a href='" . site_url() . "'>" . site_url() . "</a></p>\r\n\r\n";
|
809 |
-
$mail .= "<p>Sent from WordPress page: " . ( ! empty( $_POST["mainwp_branding_send_from_page"] ) ? "<a href='" . esc_url( $_POST["mainwp_branding_send_from_page"] ) . "'>" . esc_url( $_POST["mainwp_branding_send_from_page"] ) . "</a></p>\r\n\r\n" : "" );
|
810 |
-
$mail .= "<p>Client Email: " . $current_user->user_email . " </p>\r\n\r\n";
|
811 |
-
$mail .= "<p>Support Text:</p>\r\n\r\n";
|
812 |
-
$mail .= "<p>" . $content . "</p>\r\n\r\n";
|
813 |
-
|
814 |
-
if ( @wp_mail( $email, $subject, $mail, $headers ) ) {
|
815 |
-
;
|
816 |
-
}
|
817 |
-
|
818 |
-
return true;
|
819 |
-
}
|
820 |
-
|
821 |
-
return false;
|
822 |
-
}
|
823 |
-
|
824 |
-
function contact_support() {
|
825 |
-
global $current_user;
|
826 |
-
?>
|
827 |
-
<style>
|
828 |
-
.mainwp_info-box-yellow {
|
829 |
-
margin: 5px 0 15px;
|
830 |
-
padding: .6em;
|
831 |
-
background: #ffffe0;
|
832 |
-
border: 1px solid #e6db55;
|
833 |
-
border-radius: 3px;
|
834 |
-
-moz-border-radius: 3px;
|
835 |
-
-webkit-border-radius: 3px;
|
836 |
-
clear: both;
|
837 |
-
}
|
838 |
-
</style>
|
839 |
-
<?php
|
840 |
-
$opts = $this->child_branding_options;
|
841 |
-
|
842 |
-
if ( isset( $_POST['submit'] ) ) {
|
843 |
-
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], '_contactNonce' ) ) {
|
844 |
-
return false;
|
845 |
-
}
|
846 |
-
$from_page = $_POST['mainwp_branding_send_from_page'];
|
847 |
-
$back_link = $opts['message_return_sender'];
|
848 |
-
$back_link = ! empty( $back_link ) ? $back_link : 'Go Back';
|
849 |
-
$back_link = ! empty( $from_page ) ? '<a href="' . esc_url( $from_page ) . '" title="' . esc_attr( $back_link ) . '">' . esc_html( $back_link ) . '</a>' : '';
|
850 |
-
|
851 |
-
if ( $this->send_support_mail() ) {
|
852 |
-
$send_email_message = isset( $opts['send_email_message'] ) ? $opts['send_email_message'] : '';
|
853 |
-
if ( ! empty( $send_email_message ) ) {
|
854 |
-
$send_email_message = stripslashes( $send_email_message );
|
855 |
-
} else {
|
856 |
-
$send_email_message = __( 'Message has been submitted successfully.', 'mainwp-child' );
|
857 |
-
}
|
858 |
-
} else {
|
859 |
-
$send_email_message = __( 'Sending email failed!', 'mainwp-child' );
|
860 |
-
}
|
861 |
-
?>
|
862 |
-
<div
|
863 |
-
class="mainwp_info-box-yellow"><?php echo esc_html( $send_email_message ) . "  " . $back_link; ?></div><?php
|
864 |
-
} else {
|
865 |
-
$from_page = '';
|
866 |
-
if ( isset( $_GET['from_page'] ) ) {
|
867 |
-
$from_page = urldecode( $_GET['from_page'] );
|
868 |
-
} else {
|
869 |
-
$protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( $_SERVER['HTTPS'], 'off' ) ? 'https://' : 'http://';
|
870 |
-
$fullurl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
871 |
-
$from_page = urldecode( $fullurl );
|
872 |
-
}
|
873 |
-
|
874 |
-
$support_message = $opts['support_message'];
|
875 |
-
$support_message = nl2br( stripslashes( $support_message ) );
|
876 |
-
$from_email = $current_user ? $current_user->user_email : '';
|
877 |
-
?>
|
878 |
-
<form action="" method="post">
|
879 |
-
<div style="width: 99%;">
|
880 |
-
<h2><?php echo esc_html( $opts['contact_label'] ); ?></h2>
|
881 |
-
|
882 |
-
<div style="height: auto; margin-bottom: 10px; text-align: left">
|
883 |
-
<p><?php echo wp_kses_post( $support_message ); ?></p>
|
884 |
-
<p><label for="mainwp_branding_contact_message_subject"><?php _e('Subject:', 'mainwp-child'); ?></label><br>
|
885 |
-
<input type="text" id="mainwp_branding_contact_message_subject" name="mainwp_branding_contact_message_subject" style="width: 650px;"></p>
|
886 |
-
<p><label for="mainwp_branding_contact_send_from"><?php _e('From:', 'mainwp-child'); ?></label><br>
|
887 |
-
<input type="text" id="mainwp_branding_contact_send_from" name="mainwp_branding_contact_send_from" style="width: 650px;" value="<?php echo esc_html( $from_email ); ?>"></p>
|
888 |
-
<div style="max-width: 650px;">
|
889 |
-
<label for="mainwp_branding_contact_message_content"><?php _e('Your message:', 'mainwp-child'); ?></label><br>
|
890 |
-
<?php
|
891 |
-
remove_editor_styles(); // stop custom theme styling interfering with the editor
|
892 |
-
wp_editor( '', 'mainwp_branding_contact_message_content', array(
|
893 |
-
'textarea_name' => 'mainwp_branding_contact_message_content',
|
894 |
-
'textarea_rows' => 10,
|
895 |
-
'teeny' => true,
|
896 |
-
'wpautop' => true,
|
897 |
-
'media_buttons' => false,
|
898 |
-
)
|
899 |
-
);
|
900 |
-
?>
|
901 |
-
</div>
|
902 |
-
</div>
|
903 |
-
<br/>
|
904 |
-
<?php
|
905 |
-
$button_title = $opts['submit_button_title'];
|
906 |
-
$button_title = ! empty( $button_title ) ? $button_title : __( 'Submit' );
|
907 |
-
?>
|
908 |
-
<input id="mainwp-branding-contact-support-submit" type="submit" name="submit"
|
909 |
-
value="<?php echo esc_attr( $button_title ); ?>"
|
910 |
-
class="button-primary button" style="float: left"/>
|
911 |
-
</div>
|
912 |
-
<input type="hidden" name="mainwp_branding_send_from_page"
|
913 |
-
value="<?php echo esc_url( $from_page ); ?>"/>
|
914 |
-
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( '_contactNonce' ) ); ?>"/>
|
915 |
-
</form>
|
916 |
-
<?php }
|
917 |
-
}
|
918 |
-
|
919 |
/**
|
920 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
921 |
*/
|
922 |
public function add_support_button_in_top_admin_bar( $wp_admin_bar ) {
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
927 |
return false;
|
928 |
}
|
929 |
|
930 |
if ( isset( $_GET['from_page'] ) ) {
|
931 |
-
$href = admin_url( 'admin.php?page=ContactSupport&from_page=' .
|
932 |
} else {
|
933 |
-
$protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( $_SERVER['HTTPS'], 'off' ) ? 'https://' : 'http://';
|
934 |
-
$fullurl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
935 |
-
$href = admin_url( 'admin.php?page=ContactSupport&from_page=' .
|
936 |
}
|
937 |
$args = array(
|
938 |
'id' => 999,
|
@@ -948,179 +1146,94 @@ class MainWP_Child_Branding {
|
|
948 |
$wp_admin_bar->add_node( $args );
|
949 |
}
|
950 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
951 |
public function is_branding() {
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
|
|
|
|
973 |
}
|
974 |
|
975 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
976 |
if ( $this->is_branding() ) {
|
977 |
-
|
978 |
return $branding_header['name'];
|
979 |
}
|
980 |
return '';
|
981 |
}
|
982 |
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
$updates = get_plugin_updates();
|
1010 |
-
if (is_array($updates)) {
|
1011 |
-
foreach($updates as $slug => $data) {
|
1012 |
-
if (in_array($slug, $hide_slugs)) {
|
1013 |
-
$count_hide++;
|
1014 |
-
}
|
1015 |
-
}
|
1016 |
-
}
|
1017 |
-
|
1018 |
-
if ( $count_hide == 0) {
|
1019 |
-
return;
|
1020 |
-
}
|
1021 |
-
// js for front end
|
1022 |
-
?>
|
1023 |
-
<script type="text/javascript">
|
1024 |
-
var mainwpCountHide = <?php echo esc_attr($count_hide); ?>;
|
1025 |
-
document.addEventListener("DOMContentLoaded", function(event) {
|
1026 |
-
var $adminBarUpdates = document.querySelector( '#wp-admin-bar-updates .ab-label' ),
|
1027 |
-
itemCount;
|
1028 |
-
|
1029 |
-
if (typeof($adminBarUpdates) !== 'undefined' && $adminBarUpdates !== null) {
|
1030 |
-
itemCount = $adminBarUpdates.textContent;
|
1031 |
-
itemCount = parseInt(itemCount);
|
1032 |
-
|
1033 |
-
itemCount -= mainwpCountHide;
|
1034 |
-
if (itemCount < 0)
|
1035 |
-
itemCount = 0;
|
1036 |
-
|
1037 |
-
$adminBarUpdates.textContent = itemCount;
|
1038 |
-
}
|
1039 |
-
});
|
1040 |
-
</script><?php
|
1041 |
-
|
1042 |
-
}
|
1043 |
-
|
1044 |
-
public function in_admin_footer() {
|
1045 |
-
|
1046 |
-
$hide_slugs = apply_filters('mainwp_child_hide_update_notice' , array());
|
1047 |
-
|
1048 |
-
if (!is_array($hide_slugs))
|
1049 |
-
$hide_slugs = array();
|
1050 |
-
|
1051 |
-
$count_hide = 0;
|
1052 |
-
|
1053 |
-
$updates = get_plugin_updates();
|
1054 |
-
if (is_array($updates)) {
|
1055 |
-
foreach($updates as $slug => $data) {
|
1056 |
-
if (in_array($slug, $hide_slugs)) {
|
1057 |
-
$count_hide++;
|
1058 |
-
}
|
1059 |
-
}
|
1060 |
-
}
|
1061 |
-
|
1062 |
-
if ( $count_hide == 0) {
|
1063 |
-
return;
|
1064 |
-
}
|
1065 |
-
|
1066 |
-
// to tweaks counting of update notification display
|
1067 |
-
// js for admin end
|
1068 |
-
?>
|
1069 |
-
<script type="text/javascript">
|
1070 |
-
var mainwpCountHide = <?php echo esc_attr($count_hide); ?>;
|
1071 |
-
document.addEventListener("DOMContentLoaded", function(event) {
|
1072 |
-
if (typeof(pagenow) !== 'undefined' && pagenow == 'plugins') {
|
1073 |
-
<?php
|
1074 |
-
// hide update notice row
|
1075 |
-
if (in_array('mainwp-child/mainwp-child.php', $hide_slugs)) {
|
1076 |
-
?>
|
1077 |
-
var el = document.querySelector('tr#mainwp-child-update');
|
1078 |
-
if (typeof(el) !== 'undefined' && el !== null) {
|
1079 |
-
el.style.display = 'none';
|
1080 |
-
}
|
1081 |
-
<?php
|
1082 |
-
}
|
1083 |
-
// hide update notice row
|
1084 |
-
if (in_array('mainwp-child-reports/mainwp-child-reports.php', $hide_slugs)) {
|
1085 |
-
?>
|
1086 |
-
var el = document.querySelector('tr#mainwp-child-reports-update');
|
1087 |
-
if (typeof(el) !== 'undefined' && el !== null) {
|
1088 |
-
el.style.display = 'none';
|
1089 |
-
}
|
1090 |
-
<?php
|
1091 |
-
}
|
1092 |
-
?>
|
1093 |
-
}
|
1094 |
-
|
1095 |
-
if (mainwpCountHide > 0) {
|
1096 |
-
jQuery( document ).ready( function () {
|
1097 |
-
|
1098 |
-
var $adminBarUpdates = jQuery( '#wp-admin-bar-updates' ),
|
1099 |
-
$pluginsNavMenuUpdateCount = jQuery( 'a[href="plugins.php"] .update-plugins' ),
|
1100 |
-
itemCount;
|
1101 |
-
itemCount = $adminBarUpdates.find( '.ab-label' ).text();
|
1102 |
-
itemCount -= mainwpCountHide;
|
1103 |
-
if (itemCount < 0)
|
1104 |
-
itemCount = 0;
|
1105 |
-
|
1106 |
-
itemPCount = $pluginsNavMenuUpdateCount.find( '.plugin-count' ).text();
|
1107 |
-
itemPCount -= mainwpCountHide;
|
1108 |
-
|
1109 |
-
if (itemPCount < 0)
|
1110 |
-
itemPCount = 0;
|
1111 |
-
|
1112 |
-
$adminBarUpdates.find( '.ab-label' ).text(itemCount);
|
1113 |
-
$pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( itemPCount );
|
1114 |
-
|
1115 |
-
});
|
1116 |
-
}
|
1117 |
-
});
|
1118 |
-
</script><?php
|
1119 |
-
}
|
1120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1121 |
public function branding_map_meta_cap( $caps, $cap, $user_id, $args ) {
|
1122 |
-
if ( isset($this->child_branding_options['disable_switching_theme']) && 'T' === $this->child_branding_options['disable_switching_theme'] ) {
|
1123 |
-
// disable: theme switching
|
1124 |
if ( 'switch_themes' === $cap ) {
|
1125 |
$caps[0] = 'do_not_allow';
|
1126 |
}
|
@@ -1128,51 +1241,77 @@ class MainWP_Child_Branding {
|
|
1128 |
return $caps;
|
1129 |
}
|
1130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1131 |
public function modify_plugin_header( $plugins ) {
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
if ( is_array( $branding_header ) && ! empty( $branding_header['name'] )
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
return $plugins;
|
1160 |
-
}
|
1161 |
|
1162 |
-
|
1163 |
-
|
1164 |
-
return $slugs;
|
1165 |
-
}
|
1166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1167 |
|
1168 |
-
|
1169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1170 |
return $value;
|
1171 |
}
|
1172 |
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
|
1177 |
if ( isset( $value->response['mainwp-child/mainwp-child.php'] ) ) {
|
1178 |
unset( $value->response['mainwp-child/mainwp-child.php'] );
|
@@ -1180,6 +1319,17 @@ class MainWP_Child_Branding {
|
|
1180 |
return $value;
|
1181 |
}
|
1182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1183 |
public function update_plugin_header( $plugins, $header ) {
|
1184 |
$plugin_key = '';
|
1185 |
foreach ( $plugins as $key => $value ) {
|
@@ -1204,4 +1354,3 @@ class MainWP_Child_Branding {
|
|
1204 |
return $plugins;
|
1205 |
}
|
1206 |
}
|
1207 |
-
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Branding
|
4 |
+
*
|
5 |
+
* MainWP Branding extension handler.
|
6 |
+
* Extension URL: https://mainwp.com/extension/branding/
|
7 |
+
*
|
8 |
+
* @package MainWP\Child
|
9 |
+
*/
|
10 |
+
|
11 |
+
namespace MainWP\Child;
|
12 |
+
|
13 |
+
// phpcs:disable Generic.Metrics.CyclomaticComplexity -- to custom read/write files, complex functions/features.
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Class MainWP_Child_Branding
|
17 |
+
*
|
18 |
+
* MainWP Branding extension handler.
|
19 |
+
*/
|
20 |
class MainWP_Child_Branding {
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Public static variable to hold the single instance of the class.
|
24 |
+
*
|
25 |
+
* @var mixed Default null
|
26 |
+
*/
|
27 |
public static $instance = null;
|
28 |
|
29 |
+
/**
|
30 |
+
* Public variable to hold the MainWP Child plugin directory information.
|
31 |
+
*
|
32 |
+
* @var string Default null
|
33 |
+
*/
|
34 |
public $child_plugin_dir;
|
|
|
35 |
|
36 |
+
/**
|
37 |
+
* Method instance()
|
38 |
+
*
|
39 |
+
* Create a public static instance.
|
40 |
+
*
|
41 |
+
* @return mixed Class instance.
|
42 |
+
*/
|
43 |
+
public static function instance() {
|
44 |
+
if ( null === self::$instance ) {
|
45 |
+
self::$instance = new self();
|
46 |
}
|
47 |
+
return self::$instance;
|
48 |
}
|
49 |
|
50 |
+
/**
|
51 |
+
* MainWP_Child_Branding constructor.
|
52 |
+
*
|
53 |
+
* Run any time class is called.
|
54 |
+
*
|
55 |
+
* @return void
|
56 |
+
*/
|
57 |
public function __construct() {
|
58 |
$this->child_plugin_dir = dirname( dirname( __FILE__ ) );
|
59 |
add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) );
|
60 |
add_filter( 'mainwp_child_plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 3 );
|
61 |
+
$this->child_branding_options = $this->init_options();
|
62 |
}
|
63 |
|
64 |
+
/**
|
65 |
+
* Method init_options()
|
66 |
+
*
|
67 |
+
* Initiate the branding extension options.
|
68 |
+
*
|
69 |
+
* @return array Array containing branding options.
|
70 |
+
*/
|
71 |
+
public function init_options() {
|
72 |
+
|
73 |
+
$opts = get_option( 'mainwp_child_branding_settings' );
|
74 |
+
|
75 |
+
if ( ! is_array( $opts ) ) {
|
76 |
+
$opts = array();
|
77 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
+
if ( ! isset( $opts['contact_label'] ) || empty( $opts['contact_label'] ) ) {
|
80 |
+
$opts['contact_label'] = __( 'Contact Support', 'mainwp-child' );
|
81 |
+
}
|
82 |
+
|
83 |
+
$disconnected = isset( $opts['branding_disconnected'] ) ? $opts['branding_disconnected'] : '';
|
84 |
+
$preserve_branding = isset( $opts['preserve_branding'] ) ? $opts['preserve_branding'] : '';
|
85 |
+
$cancelled_branding = ( 'yes' === $disconnected ) && ! $preserve_branding;
|
86 |
+
|
87 |
+
$opts['cancelled_branding'] = $cancelled_branding;
|
88 |
+
$opts['branding_preserve_title'] = '';
|
89 |
+
|
90 |
+
if ( ! $cancelled_branding ) {
|
91 |
+
if ( isset( $opts['branding_header'] ) ) {
|
92 |
+
$branding_header = $opts['branding_header'];
|
93 |
+
if ( is_array( $branding_header ) && isset( $branding_header['name'] ) && ! empty( $branding_header['name'] ) ) {
|
94 |
+
$opts['branding_preserve_title'] = stripslashes( $branding_header['name'] );
|
95 |
+
}
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Filter 'mainwp_child_branding_init_options'
|
101 |
+
*
|
102 |
+
* Set custom branding setting through the filter.
|
103 |
+
*
|
104 |
+
* @since 4.0
|
105 |
+
*/
|
106 |
+
$opts = apply_filters( 'mainwp_child_branding_init_options', $opts );
|
107 |
+
return $opts;
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Method get_extra_options()
|
112 |
+
*
|
113 |
+
* Get extra branding settings.
|
114 |
+
*
|
115 |
+
* @return array Array containing the extra branding settings.
|
116 |
+
*/
|
117 |
+
public function get_extra_options() {
|
118 |
+
$extra = array();
|
119 |
+
if ( is_array( $this->child_branding_options ) && isset( $this->child_branding_options['extra_settings'] ) ) {
|
120 |
+
$extra = $this->child_branding_options['extra_settings'];
|
121 |
+
if ( ! is_array( $extra ) ) {
|
122 |
+
$extra = array();
|
123 |
+
}
|
124 |
+
}
|
125 |
+
|
126 |
+
return $extra;
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Method plugin_row_meta()
|
131 |
+
*
|
132 |
+
* Handle plugin meta information when custom branding is applied.
|
133 |
+
*
|
134 |
+
* @param array $plugin_meta An array of the plugin's metadata, including the version, author, author URI, and plugin URI.
|
135 |
+
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
|
136 |
+
* @param string $child_plugin_slug MainWP Child plugin slug.
|
137 |
+
*
|
138 |
+
* @return array An array of the plugin's metadata, including the version, author, author URI, and plugin URI.
|
139 |
+
*/
|
140 |
public function plugin_row_meta( $plugin_meta, $plugin_file, $child_plugin_slug ) {
|
141 |
if ( $child_plugin_slug !== $plugin_file ) {
|
142 |
return $plugin_meta;
|
145 |
if ( ! $this->is_branding() ) {
|
146 |
return $plugin_meta;
|
147 |
}
|
148 |
+
// hide View details links!
|
149 |
$meta_total = count( $plugin_meta );
|
150 |
for ( $i = 0; $i < $meta_total; $i++ ) {
|
151 |
$str_meta = $plugin_meta[ $i ];
|
158 |
return $plugin_meta;
|
159 |
}
|
160 |
|
161 |
+
/**
|
162 |
+
* Method child_deactivation()
|
163 |
+
*
|
164 |
+
* Empty custom branding options upon MainWP Child plugin deactivation.
|
165 |
+
*/
|
166 |
public function child_deactivation() {
|
167 |
+
$brandingOptions_empty = array(
|
168 |
+
'hide',
|
169 |
+
'disable_change',
|
170 |
+
'disable_switching_theme',
|
171 |
+
'show_support',
|
172 |
+
'support_email',
|
173 |
+
'support_message',
|
174 |
+
'remove_restore',
|
175 |
+
'remove_setting',
|
176 |
+
'remove_server_info',
|
177 |
+
'remove_wp_tools',
|
178 |
+
'remove_wp_setting',
|
179 |
+
'remove_permalink',
|
180 |
+
'contact_label',
|
181 |
+
'email_message',
|
182 |
+
'message_return_sender',
|
183 |
+
'submit_button_title',
|
184 |
+
'extra_settings',
|
185 |
+
'branding_ext_enabled',
|
|
|
|
|
186 |
);
|
187 |
|
188 |
+
foreach ( $brandingOptions_empty as $opt ) {
|
189 |
+
if ( isset( $this->child_branding_options[ $opt ] ) ) {
|
190 |
+
$this->child_branding_options[ $opt ] = '';
|
191 |
+
}
|
192 |
+
}
|
193 |
+
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
}
|
195 |
|
196 |
+
/**
|
197 |
+
* Method action()
|
198 |
+
*
|
199 |
+
* Fire off certain branding actions.
|
200 |
+
*
|
201 |
+
* @uses MainWP_Child_Branding::update_branding() Update custom branding settings.
|
202 |
+
*/
|
203 |
public function action() {
|
204 |
$information = array();
|
205 |
+
$mwp_action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
206 |
+
switch ( $mwp_action ) {
|
207 |
case 'update_branding':
|
208 |
$information = $this->update_branding();
|
209 |
break;
|
211 |
MainWP_Helper::write( $information );
|
212 |
}
|
213 |
|
214 |
+
/**
|
215 |
+
* Method update_branding()
|
216 |
+
*
|
217 |
+
* Update custom branding settings.
|
218 |
+
*
|
219 |
+
* @used-by MainWP_Child_Branding::action() Fire off certain Google Pagespeed Insights plugin actions.
|
220 |
+
*
|
221 |
+
* @return array Action result.
|
222 |
+
*/
|
223 |
public function update_branding() {
|
224 |
$information = array();
|
225 |
+
$settings = isset( $_POST['settings'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['settings'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- Required for bacwards compatibility.
|
226 |
if ( ! is_array( $settings ) ) {
|
227 |
return $information;
|
228 |
}
|
229 |
|
230 |
+
$current_settings = $this->child_branding_options;
|
231 |
+
$current_extra_setting = $this->child_branding_options['extra_settings'];
|
232 |
|
233 |
+
$current_settings['branding_ext_enabled'] = 'Y';
|
|
|
234 |
|
235 |
+
$header = array(
|
236 |
'name' => $settings['child_plugin_name'],
|
237 |
'description' => $settings['child_plugin_desc'],
|
238 |
'author' => $settings['child_plugin_author'],
|
239 |
'authoruri' => $settings['child_plugin_author_uri'],
|
240 |
+
'pluginuri' => isset( $settings['child_plugin_uri'] ) ? $settings['child_plugin_uri'] : '',
|
241 |
);
|
242 |
+
$current_settings['branding_header'] = $header;
|
243 |
+
|
244 |
+
$current_settings['preserve_branding'] = $settings['child_preserve_branding'];
|
245 |
+
$current_settings['support_email'] = $settings['child_support_email'];
|
246 |
+
$current_settings['support_message'] = $settings['child_support_message'];
|
247 |
+
$current_settings['remove_restore'] = $settings['child_remove_restore'];
|
248 |
+
$current_settings['remove_setting'] = $settings['child_remove_setting'];
|
249 |
+
$current_settings['remove_server_info'] = $settings['child_remove_server_info'];
|
250 |
+
$current_settings['remove_connection_detail'] = isset( $settings['child_remove_connection_detail'] ) ? $settings['child_remove_connection_detail'] : 0;
|
251 |
+
$current_settings['remove_wp_tools'] = $settings['child_remove_wp_tools'];
|
252 |
+
$current_settings['remove_wp_setting'] = $settings['child_remove_wp_setting'];
|
253 |
+
$current_settings['remove_permalink'] = $settings['child_remove_permalink'];
|
254 |
+
$current_settings['contact_label'] = $settings['child_button_contact_label'];
|
255 |
+
$current_settings['email_message'] = $settings['child_send_email_message'];
|
256 |
+
$current_settings['message_return_sender'] = $settings['child_message_return_sender'];
|
257 |
+
$current_settings['submit_button_title'] = $settings['child_submit_button_title'];
|
258 |
+
$current_settings['hide'] = $settings['child_plugin_hide'] ? 'T' : '';
|
259 |
+
$current_settings['show_support'] = ( $settings['child_show_support_button'] && ! empty( $settings['child_support_email'] ) ) ? 'T' : '';
|
260 |
+
$current_settings['disable_change'] = $settings['child_disable_change'] ? 'T' : '';
|
261 |
+
$current_settings['disable_switching_theme'] = $settings['child_disable_switching_theme'] ? 'T' : '';
|
262 |
+
if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) {
|
263 |
+
$current_settings['disable_wp_branding'] = $settings['child_disable_wp_branding'];
|
264 |
+
}
|
265 |
+
$current_settings['extra_settings'] = $this->get_extra_settings( $current_extra_setting, $settings, $information );
|
266 |
+
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $current_settings );
|
267 |
|
268 |
+
$information['result'] = 'SUCCESS';
|
269 |
+
|
270 |
+
return $information;
|
271 |
+
}
|
272 |
+
|
273 |
+
/**
|
274 |
+
* Method get_extra_settings()
|
275 |
+
*
|
276 |
+
* Get extra branding settings.
|
277 |
+
*
|
278 |
+
* @param array $current_extra_setting An array containing the current extra branding settings.
|
279 |
+
* @param array $settings An array containing the branding settings.
|
280 |
+
* @param array $information An array containing the synchronization information.
|
281 |
+
*
|
282 |
+
* @used-by MainWP_Child_Branding::update_branding() Update custom branding settings.
|
283 |
+
*
|
284 |
+
* @return array An array of branding extra settings
|
285 |
+
*/
|
286 |
+
public function get_extra_settings( $current_extra_setting, $settings, &$information ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
|
288 |
$extra_setting = array(
|
289 |
'show_button_in' => $settings['child_show_support_button_in'],
|
294 |
'remove_widget_activity' => $settings['child_remove_widget_activity'],
|
295 |
'remove_widget_quick' => $settings['child_remove_widget_quick'],
|
296 |
'remove_widget_news' => $settings['child_remove_widget_news'],
|
297 |
+
'login_image_link' => $settings['child_login_image_link'],
|
298 |
+
'login_image_title' => $settings['child_login_image_title'],
|
299 |
'site_generator' => $settings['child_site_generator'],
|
300 |
'generator_link' => $settings['child_generator_link'],
|
301 |
'admin_css' => $settings['child_admin_css'],
|
327 |
$extra_setting['login_image'] = array();
|
328 |
} else {
|
329 |
try {
|
330 |
+
$upload = $this->branding_upload_image( $settings['child_login_image_url'] );
|
331 |
if ( null !== $upload ) {
|
332 |
+
$extra_setting['login_image'] = array(
|
333 |
+
'path' => $upload['path'],
|
334 |
+
'url' => $upload['url'],
|
335 |
+
);
|
336 |
if ( isset( $current_extra_setting['login_image']['path'] ) ) {
|
337 |
$old_file = $current_extra_setting['login_image']['path'];
|
338 |
if ( ! empty( $old_file ) && file_exists( $old_file ) ) {
|
339 |
+
unlink( $old_file );
|
340 |
}
|
341 |
}
|
342 |
}
|
343 |
+
} catch ( \Exception $e ) {
|
344 |
$information['error']['login_image'] = $e->getMessage();
|
345 |
}
|
346 |
}
|
347 |
+
} elseif ( isset( $current_extra_setting['login_image'] ) ) {
|
348 |
$extra_setting['login_image'] = $current_extra_setting['login_image'];
|
349 |
}
|
350 |
|
353 |
$extra_setting['favico_image'] = array();
|
354 |
} else {
|
355 |
try {
|
356 |
+
$upload = $this->branding_upload_image( $settings['child_favico_image_url'] );
|
357 |
if ( null !== $upload ) {
|
358 |
+
$extra_setting['favico_image'] = array(
|
359 |
+
'path' => $upload['path'],
|
360 |
+
'url' => $upload['url'],
|
361 |
+
);
|
362 |
if ( isset( $current_extra_setting['favico_image']['path'] ) ) {
|
363 |
$old_file = $current_extra_setting['favico_image']['path'];
|
364 |
if ( ! empty( $old_file ) && file_exists( $old_file ) ) {
|
365 |
+
unlink( $old_file );
|
366 |
}
|
367 |
}
|
368 |
}
|
369 |
+
} catch ( \Exception $e ) {
|
370 |
$information['error']['favico_image'] = $e->getMessage();
|
371 |
}
|
372 |
}
|
373 |
+
} elseif ( isset( $current_extra_setting['favico_image'] ) ) {
|
374 |
$extra_setting['favico_image'] = $current_extra_setting['favico_image'];
|
375 |
}
|
376 |
+
return $extra_setting;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
}
|
378 |
|
379 |
+
/**
|
380 |
+
* Method branding_upload_image()
|
381 |
+
*
|
382 |
+
* Upload custom image from MainWP Dashboard.
|
383 |
+
*
|
384 |
+
* @param string $img_url Contains image URL.
|
385 |
+
*
|
386 |
+
* @throws \Exception Error message.
|
387 |
+
*
|
388 |
+
* @return array An array containing the image information such as path and URL.
|
389 |
+
*/
|
390 |
+
public function branding_upload_image( $img_url ) {
|
391 |
+
include_once ABSPATH . 'wp-admin/includes/file.php';
|
392 |
+
|
393 |
+
add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 );
|
394 |
$temporary_file = download_url( $img_url );
|
395 |
+
remove_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 );
|
396 |
|
397 |
if ( is_wp_error( $temporary_file ) ) {
|
398 |
+
throw new \Exception( $temporary_file->get_error_message() );
|
399 |
} else {
|
400 |
$upload_dir = wp_upload_dir();
|
401 |
+
$local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url );
|
402 |
$local_img_path = dirname( $local_img_path ) . '/' . wp_unique_filename( dirname( $local_img_path ), basename( $local_img_path ) );
|
403 |
$local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path );
|
404 |
+
$moved = rename( $temporary_file, $local_img_path );
|
405 |
if ( $moved ) {
|
406 |
+
return array(
|
407 |
+
'path' => $local_img_path,
|
408 |
+
'url' => $local_img_url,
|
409 |
+
);
|
410 |
}
|
411 |
}
|
412 |
if ( file_exists( $temporary_file ) ) {
|
416 |
return null;
|
417 |
}
|
418 |
|
419 |
+
/**
|
420 |
+
* Method branding_init()
|
421 |
+
*
|
422 |
+
* Initiate custom branding features.
|
423 |
+
*
|
424 |
+
* @return void
|
425 |
+
*/
|
426 |
public function branding_init() {
|
427 |
|
428 |
$extra_setting = $this->get_extra_options();
|
429 |
|
430 |
+
if ( is_admin() ) {
|
431 |
+
add_action( 'in_admin_footer', array( MainWP_Child_Branding_Render::instance(), 'in_admin_footer' ) );
|
432 |
+
} elseif ( is_user_logged_in() ) {
|
433 |
+
add_action( 'wp_after_admin_bar_render', array( MainWP_Child_Branding_Render::instance(), 'after_admin_bar_render' ) );
|
434 |
+
}
|
435 |
+
|
436 |
+
$opts = $this->child_branding_options;
|
|
|
|
|
437 |
|
438 |
$cancelled_branding = $opts['cancelled_branding'];
|
439 |
+
|
440 |
if ( $cancelled_branding ) {
|
441 |
return;
|
442 |
}
|
443 |
|
444 |
+
// enable branding in case child plugin deactive and re-activated.
|
445 |
add_filter( 'all_plugins', array( $this, 'modify_plugin_header' ) );
|
446 |
|
447 |
if ( $this->is_branding() ) {
|
448 |
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
449 |
+
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );
|
450 |
}
|
451 |
|
452 |
+
if ( ! isset( $opts['branding_ext_enabled'] ) || 'Y' !== $opts['branding_ext_enabled'] ) {
|
453 |
return;
|
454 |
}
|
455 |
|
456 |
add_filter( 'map_meta_cap', array( $this, 'branding_map_meta_cap' ), 10, 5 );
|
457 |
|
458 |
+
if ( 'T' === $opts['disable_change'] ) {
|
459 |
|
460 |
+
// Disable the WordPress plugin update notifications.
|
461 |
+
remove_action( 'load-update-core.php', 'wp_update_plugins' );
|
462 |
+
add_filter( 'pre_site_transient_update_plugins', '__return_null' );
|
463 |
|
464 |
+
// Disable the WordPress theme update notifications.
|
465 |
+
remove_action( 'load-update-core.php', 'wp_update_themes' );
|
466 |
+
add_filter(
|
467 |
+
'pre_site_transient_update_themes',
|
468 |
+
function( $a ) {
|
469 |
+
return null;
|
470 |
+
}
|
471 |
+
);
|
472 |
|
473 |
+
/**
|
474 |
+
* Disable the WordPress core update notifications.
|
475 |
+
*
|
476 |
+
* @uses MainWP_Child_Branding_Render::get_class_name()
|
477 |
+
*/
|
478 |
function remove_core_updates() {
|
479 |
+
add_action(
|
480 |
+
'init',
|
481 |
+
function( $a ) {
|
482 |
+
remove_action( 'wp_version_check', 'wp_version_check' );
|
483 |
+
},
|
484 |
+
2
|
485 |
+
);
|
486 |
+
add_filter( 'pre_option_update_core', '__return_null' );
|
487 |
+
add_filter( 'pre_site_transient_update_core', '__return_null' );
|
488 |
+
} add_action( 'after_setup_theme', 'remove_core_updates' );
|
489 |
|
490 |
+
add_action( 'admin_head', array( MainWP_Child_Branding_Render::get_class_name(), 'admin_head_hide_elements' ), 15 );
|
491 |
+
add_action( 'admin_menu', array( $this, 'branding_redirect' ), 9 );
|
492 |
}
|
493 |
|
494 |
+
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
|
495 |
+
|
496 |
+
if ( ! isset( $opts['disable_wp_branding'] ) || 'Y' !== $opts['disable_wp_branding'] ) {
|
497 |
add_filter( 'wp_footer', array( &$this, 'branding_global_footer' ), 15 );
|
498 |
add_action( 'wp_dashboard_setup', array( &$this, 'custom_dashboard_widgets' ), 999 );
|
499 |
+
// branding site generator.
|
500 |
$types = array( 'html', 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export' );
|
501 |
foreach ( $types as $type ) {
|
502 |
+
add_filter( 'get_the_generator_' . $type, array( &$this, 'custom_generator' ), 999, 2 );
|
503 |
}
|
504 |
add_action( 'admin_head', array( &$this, 'custom_admin_css' ) );
|
505 |
add_action( 'login_enqueue_scripts', array( &$this, 'custom_login_css' ) );
|
509 |
add_filter( 'login_headertext', array( &$this, 'custom_login_headertitle' ) );
|
510 |
add_action( 'wp_head', array( &$this, 'custom_favicon_frontend' ) );
|
511 |
if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) {
|
|
|
512 |
add_filter( 'update_footer', array( &$this, 'core_update_footer' ), 14 );
|
513 |
+
add_filter( 'admin_footer_text', array( &$this, 'admin_footer_text' ), 14 );
|
514 |
}
|
515 |
|
516 |
if ( isset( $extra_setting['hide_nag'] ) && ! empty( $extra_setting['hide_nag'] ) ) {
|
517 |
+
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
518 |
}
|
519 |
|
520 |
add_action( 'admin_menu', array( &$this, 'remove_default_post_metaboxes' ) );
|
522 |
}
|
523 |
}
|
524 |
|
525 |
+
/**
|
526 |
+
* Method admin_init()
|
527 |
+
*
|
528 |
+
* Remove remove the update nag.
|
529 |
+
*/
|
530 |
public function admin_init() {
|
531 |
remove_action( 'admin_notices', 'update_nag', 3 );
|
532 |
}
|
533 |
|
534 |
+
/**
|
535 |
+
* Method admin_menu()
|
536 |
+
*
|
537 |
+
* Add the support form page admin menu item.
|
538 |
+
*/
|
539 |
+
public function admin_menu() {
|
540 |
+
|
541 |
+
/**
|
542 |
+
* Filter 'mainwp_branding_role_cap_enable_contact_form'
|
543 |
+
*
|
544 |
+
* Manage the support form visibility. Set false to hide the support form page.
|
545 |
+
*
|
546 |
+
* @since 4.0
|
547 |
+
*/
|
548 |
+
$enable_contact = apply_filters( 'mainwp_branding_role_cap_enable_contact_form', false );
|
549 |
+
|
550 |
+
if ( ! $enable_contact && ! current_user_can( 'administrator' ) ) {
|
551 |
return false;
|
552 |
}
|
553 |
|
554 |
+
$extra_setting = $this->get_extra_options();
|
555 |
+
if ( empty( $extra_setting ) ) {
|
556 |
return false;
|
557 |
}
|
558 |
+
$opts = $this->child_branding_options;
|
559 |
|
560 |
if ( 'T' === $opts['show_support'] ) {
|
561 |
$title = $opts['contact_label'];
|
562 |
if ( isset( $extra_setting['show_button_in'] ) && ( 2 === (int) $extra_setting['show_button_in'] || 3 === (int) $extra_setting['show_button_in'] ) ) {
|
563 |
$title = $opts['contact_label'];
|
564 |
+
add_menu_page(
|
565 |
+
$title,
|
566 |
+
$title,
|
567 |
+
'read',
|
568 |
+
'ContactSupport2',
|
569 |
+
array(
|
570 |
+
MainWP_Child_Branding_Render::instance(),
|
571 |
+
'contact_support',
|
572 |
+
),
|
573 |
+
'',
|
574 |
+
'2.0001'
|
575 |
+
);
|
576 |
}
|
577 |
|
578 |
if ( isset( $extra_setting['show_button_in'] ) && ( 1 === $extra_setting['show_button_in'] || 3 === $extra_setting['show_button_in'] ) ) {
|
579 |
+
add_submenu_page(
|
580 |
+
null,
|
581 |
+
$title,
|
582 |
+
$opts['contact_label'],
|
583 |
+
'read',
|
584 |
+
'ContactSupport',
|
585 |
+
array(
|
586 |
+
MainWP_Child_Branding_Render::instance(),
|
587 |
+
'contact_support',
|
588 |
+
)
|
589 |
+
);
|
590 |
add_action( 'admin_bar_menu', array( $this, 'add_support_button_in_top_admin_bar' ), 100 );
|
591 |
}
|
592 |
}
|
|
|
593 |
}
|
594 |
|
595 |
+
/**
|
596 |
+
* Method remove_default_post_metaboxes()
|
597 |
+
*
|
598 |
+
* Hide new post screen unwanted metaboxes.
|
599 |
+
*/
|
600 |
+
public function remove_default_post_metaboxes() {
|
601 |
$extra_setting = $this->get_extra_options();
|
602 |
|
603 |
add_filter( 'manage_posts_columns', array( &$this, 'custom_post_columns' ) );
|
636 |
}
|
637 |
}
|
638 |
|
639 |
+
/**
|
640 |
+
* Method custom_post_columns()
|
641 |
+
*
|
642 |
+
* Hide unwanted posts table columns.
|
643 |
+
*
|
644 |
+
* @param array $defaults An array containing default Manage Posts columns.
|
645 |
+
*
|
646 |
+
* @return array $defaults An updated array containing default Manage Posts columns.
|
647 |
+
*/
|
648 |
+
public function custom_post_columns( $defaults ) {
|
649 |
$extra_setting = $this->get_extra_options();
|
650 |
|
651 |
if ( isset( $extra_setting['hide_metabox_post_comments'] ) && $extra_setting['hide_metabox_post_comments'] ) {
|
661 |
return $defaults;
|
662 |
}
|
663 |
|
664 |
+
/**
|
665 |
+
* Method manage_my_category_columns()
|
666 |
+
*
|
667 |
+
* Hide the post slug metabox.
|
668 |
+
*
|
669 |
+
* @param array $defaults An array containing default Manage Posts columns.
|
670 |
+
*
|
671 |
+
* @return array $defaults An updated array containing default Manage Posts columns.
|
672 |
+
*/
|
673 |
+
public function manage_my_category_columns( $defaults ) {
|
674 |
$extra_setting = $this->get_extra_options();
|
675 |
|
676 |
if ( isset( $extra_setting['hide_metabox_post_slug'] ) && $extra_setting['hide_metabox_post_slug'] ) {
|
680 |
return $defaults;
|
681 |
}
|
682 |
|
683 |
+
/**
|
684 |
+
* Method remove_default_page_metaboxes()
|
685 |
+
*
|
686 |
+
* Hide new post screen unwanted metaboxes.
|
687 |
+
*/
|
688 |
+
public function remove_default_page_metaboxes() {
|
689 |
$extra_setting = $this->get_extra_options();
|
690 |
|
691 |
add_filter( 'manage_pages_columns', array( &$this, 'custom_pages_columns' ) );
|
692 |
|
693 |
+
if ( isset( $extra_setting['hide_metabox_page_custom_fields'] ) && $extra_setting['hide_metabox_page_custom_fields'] ) {
|
694 |
remove_meta_box( 'postcustom', 'page', 'normal' );
|
695 |
}
|
696 |
if ( isset( $extra_setting['hide_metabox_page_author'] ) && $extra_setting['hide_metabox_page_author'] ) {
|
713 |
}
|
714 |
}
|
715 |
|
716 |
+
/**
|
717 |
+
* Method custom_pages_columns()
|
718 |
+
*
|
719 |
+
* Hide unwanted pages table columns.
|
720 |
+
*
|
721 |
+
* @param array $defaults An array containing default Manage Pages columns.
|
722 |
+
*
|
723 |
+
* @return array $defaults An updated array containing default Manage Pages columns.
|
724 |
+
*/
|
725 |
+
public function custom_pages_columns( $defaults ) {
|
726 |
$extra_setting = $this->get_extra_options();
|
727 |
|
728 |
if ( isset( $extra_setting['hide_metabox_page_comments'] ) && $extra_setting['hide_metabox_page_comments'] ) {
|
735 |
return $defaults;
|
736 |
}
|
737 |
|
738 |
+
/**
|
739 |
+
* Method branding_redirect()
|
740 |
+
*
|
741 |
+
* Prevent updates by redirecting access from the Updates and Plugins page.
|
742 |
+
*/
|
743 |
public function branding_redirect() {
|
744 |
+
$pos1 = isset( $_SERVER['REQUEST_URI'] ) ? stripos( wp_unslash( $_SERVER['REQUEST_URI'] ), 'update-core.php' ) : false;
|
745 |
+
$pos2 = isset( $_SERVER['REQUEST_URI'] ) ? stripos( wp_unslash( $_SERVER['REQUEST_URI'] ), 'plugins.php' ) : false;
|
746 |
if ( false !== $pos1 || false !== $pos2 ) {
|
747 |
+
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
748 |
exit();
|
749 |
}
|
750 |
}
|
751 |
|
752 |
+
/**
|
753 |
+
* Method core_update_footer()
|
754 |
+
*
|
755 |
+
* Remove the footer text containing the WP Core version info.
|
756 |
+
*/
|
757 |
+
public function core_update_footer() {
|
758 |
+
echo '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
759 |
}
|
760 |
|
761 |
+
/**
|
762 |
+
* Method core_update_footer()
|
763 |
+
*
|
764 |
+
* Set custom admin footer text.
|
765 |
+
*/
|
766 |
+
public function admin_footer_text() {
|
767 |
$extra_setting = $this->get_extra_options();
|
768 |
if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) {
|
769 |
echo wp_kses_post( nl2br( stripslashes( $extra_setting['dashboard_footer'] ) ) );
|
770 |
}
|
771 |
}
|
772 |
|
773 |
+
/**
|
774 |
+
* Method custom_favicon_frontend()
|
775 |
+
*
|
776 |
+
* Set custom site favicon.
|
777 |
+
*/
|
778 |
+
public function custom_favicon_frontend() {
|
779 |
$extra_setting = $this->get_extra_options();
|
780 |
if ( isset( $extra_setting['favico_image']['url'] ) && ! empty( $extra_setting['favico_image']['url'] ) ) {
|
781 |
$favico = $extra_setting['favico_image']['url'];
|
783 |
}
|
784 |
}
|
785 |
|
786 |
+
/**
|
787 |
+
* Method custom_login_logo()
|
788 |
+
*
|
789 |
+
* Set custom site login page logo.
|
790 |
+
*/
|
791 |
+
public function custom_login_logo() {
|
792 |
$extra_setting = $this->get_extra_options();
|
793 |
if ( isset( $extra_setting['login_image']['url'] ) && ! empty( $extra_setting['login_image']['url'] ) ) {
|
794 |
$login_logo = $extra_setting['login_image']['url'];
|
795 |
+
echo '<style type="text/css">#login h1 a { background-image: url(\'' . esc_url( $login_logo ) . '\') !important; height:70px !important; width:310px !important; background-size: auto auto !important; }</style>';
|
|
|
|
|
796 |
}
|
797 |
}
|
798 |
|
799 |
+
/**
|
800 |
+
* Method custom_login_headerurl()
|
801 |
+
*
|
802 |
+
* Set custom site login logo link.
|
803 |
+
*
|
804 |
+
* @param string $value Contains the image link information.
|
805 |
+
*
|
806 |
+
* @return string $value Contains the image link updated information.
|
807 |
+
*/
|
808 |
+
public function custom_login_headerurl( $value ) {
|
809 |
$extra_setting = $this->get_extra_options();
|
810 |
if ( isset( $extra_setting['login_image_link'] ) && ! empty( $extra_setting['login_image_link'] ) ) {
|
811 |
return $extra_setting['login_image_link'];
|
814 |
return $value;
|
815 |
}
|
816 |
|
817 |
+
/**
|
818 |
+
* Method custom_login_headertitle()
|
819 |
+
*
|
820 |
+
* Set custom site login logo title.
|
821 |
+
*
|
822 |
+
* @param string $value Contains the image title information.
|
823 |
+
*
|
824 |
+
* @return string $value Contains the image title updated information.
|
825 |
+
*/
|
826 |
+
public function custom_login_headertitle( $value ) {
|
827 |
$extra_setting = $this->get_extra_options();
|
828 |
if ( isset( $extra_setting['login_image_title'] ) && ! empty( $extra_setting['login_image_title'] ) ) {
|
829 |
return $extra_setting['login_image_title'];
|
832 |
return $value;
|
833 |
}
|
834 |
|
835 |
+
/**
|
836 |
+
* Method custom_gettext()
|
837 |
+
*
|
838 |
+
* Replace language domains.
|
839 |
+
*
|
840 |
+
* @param array $translations An array containing the list of available translations.
|
841 |
+
* @param string $text Contains the text to replace.
|
842 |
+
* @param string $domain Contains the language domain.
|
843 |
+
*
|
844 |
+
* @return array $translations An array containing the list of available translations.
|
845 |
+
*/
|
846 |
+
public function custom_gettext( $translations, $text, $domain = 'default' ) {
|
847 |
$extra_setting = $this->get_extra_options();
|
848 |
$texts_replace = $extra_setting['texts_replace'];
|
849 |
if ( is_array( $texts_replace ) && count( $texts_replace ) > 0 ) {
|
857 |
return $translations;
|
858 |
}
|
859 |
|
860 |
+
/**
|
861 |
+
* Method custom_admin_css()
|
862 |
+
*
|
863 |
+
* Set custom WP Admin area CSS.
|
864 |
+
*/
|
865 |
+
public function custom_admin_css() {
|
866 |
$header_css = '';
|
867 |
$extra_setting = $this->get_extra_options();
|
868 |
|
880 |
}
|
881 |
|
882 |
if ( ! empty( $header_css ) ) {
|
883 |
+
echo '<style>' . self::parse_css( $header_css ) . '</style>';
|
884 |
}
|
885 |
}
|
886 |
|
887 |
+
/**
|
888 |
+
* Method custom_login_css()
|
889 |
+
*
|
890 |
+
* Set custom Login page CSS.
|
891 |
+
*/
|
892 |
+
public function custom_login_css() {
|
893 |
$extra_setting = $this->get_extra_options();
|
894 |
if ( isset( $extra_setting['login_css'] ) && ! empty( $extra_setting['login_css'] ) ) {
|
895 |
+
echo '<style>' . self::parse_css( $extra_setting['login_css'] ) . '</style>';
|
896 |
+
}
|
897 |
+
}
|
898 |
+
|
899 |
+
/**
|
900 |
+
* Method parse_css()
|
901 |
+
*
|
902 |
+
* Parses CSS into an array.
|
903 |
+
*
|
904 |
+
* @param string $css Contains the CSS code that needs to be parsed.
|
905 |
+
*
|
906 |
+
* @return mixed Rebuilt CSS.
|
907 |
+
*
|
908 |
+
* Copyright (C) 2009 Peter Kröner, CSSPARSER.
|
909 |
+
*/
|
910 |
+
public static function parse_css( $css ) {
|
911 |
+
|
912 |
+
// Remove CSS-Comments.
|
913 |
+
$css = preg_replace( '/\/\*.*?\*\//ms', '', $css );
|
914 |
+
// Remove HTML-Comments.
|
915 |
+
$css = preg_replace( '/([^\'"]+?)(\<!--|--\>)([^\'"]+?)/ms', '$1$3', $css );
|
916 |
+
// Extract @media-blocks into $blocks.
|
917 |
+
preg_match_all( '/@.+?\}[^\}]*?\}/ms', $css, $blocks );
|
918 |
+
// Append the rest to $blocks.
|
919 |
+
array_push( $blocks[0], preg_replace( '/@.+?\}[^\}]*?\}/ms', '', $css ) );
|
920 |
+
$ordered = array();
|
921 |
+
$count_blocks = count( $blocks[0] );
|
922 |
+
for ( $i = 0; $i < $count_blocks; $i++ ) {
|
923 |
+
// If @media-block, strip declaration and parenthesis.
|
924 |
+
if ( '@media' === substr( $blocks[0][ $i ], 0, 6 ) ) {
|
925 |
+
$ordered_key = preg_replace( '/^(@media[^\{]+)\{.*\}$/ms', '$1', $blocks[0][ $i ] );
|
926 |
+
$ordered_value = preg_replace( '/^@media[^\{]+\{(.*)\}$/ms', '$1', $blocks[0][ $i ] );
|
927 |
+
} elseif ( '@' === substr( $blocks[0][ $i ], 0, 1 ) ) {
|
928 |
+
$ordered_key = $blocks[0][ $i ];
|
929 |
+
$ordered_value = $blocks[0][ $i ];
|
930 |
+
} else {
|
931 |
+
$ordered_key = 'main';
|
932 |
+
$ordered_value = $blocks[0][ $i ];
|
933 |
+
}
|
934 |
+
// Split by parenthesis, ignoring those inside content-quotes.
|
935 |
+
$ordered[ $ordered_key ] = preg_split( '/([^\'"\{\}]*?[\'"].*?(?<!\\\)[\'"][^\'"\{\}]*?)[\{\}]|([^\'"\{\}]*?)[\{\}]/', trim( $ordered_value, " \r\n\t" ), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
|
936 |
+
}
|
937 |
+
return self::parse_css_rebuild( $ordered );
|
938 |
+
}
|
939 |
+
|
940 |
+
/**
|
941 |
+
* Method parse_css_rebuild()
|
942 |
+
*
|
943 |
+
* Rebuild parsed CSS.
|
944 |
+
*
|
945 |
+
* @param string $ordered Contains the parsed CSS code that needs to be rebuit.
|
946 |
+
*
|
947 |
+
* @return mixed CSS output.
|
948 |
+
*
|
949 |
+
* Copyright (C) 2009 Peter Kröner, CSSPARSER.
|
950 |
+
*/
|
951 |
+
public static function parse_css_rebuild( $ordered ) {
|
952 |
+
// Beginning to rebuild new slim CSS-Array.
|
953 |
+
foreach ( $ordered as $key => $val ) {
|
954 |
+
$new = array();
|
955 |
+
$count_val = count( $val );
|
956 |
+
for ( $i = 0; $i < $count_val; $i++ ) {
|
957 |
+
// Split selectors and rules and split properties and values.
|
958 |
+
$selector = trim( $val[ $i ], " \r\n\t" );
|
959 |
+
|
960 |
+
if ( ! empty( $selector ) ) {
|
961 |
+
if ( ! isset( $new[ $selector ] ) ) {
|
962 |
+
$new[ $selector ] = array();
|
963 |
+
}
|
964 |
+
$rules = explode( ';', $val[ ++$i ] );
|
965 |
+
foreach ( $rules as $rule ) {
|
966 |
+
$rule = trim( $rule, " \r\n\t" );
|
967 |
+
if ( ! empty( $rule ) ) {
|
968 |
+
$rule = array_reverse( explode( ':', $rule ) );
|
969 |
+
$property = trim( array_pop( $rule ), " \r\n\t" );
|
970 |
+
$value = implode( ':', array_reverse( $rule ) );
|
971 |
+
|
972 |
+
if ( ! isset( $new[ $selector ][ $property ] ) || ! preg_match( '/!important/', $new[ $selector ][ $property ] ) ) {
|
973 |
+
$new[ $selector ][ $property ] = $value;
|
974 |
+
} elseif ( preg_match( '/!important/', $new[ $selector ][ $property ] ) && preg_match( '/!important/', $value ) ) {
|
975 |
+
$new[ $selector ][ $property ] = $value;
|
976 |
+
}
|
977 |
+
}
|
978 |
+
}
|
979 |
+
}
|
980 |
+
}
|
981 |
+
$ordered[ $key ] = $new;
|
982 |
+
}
|
983 |
+
$parsed = $ordered;
|
984 |
+
|
985 |
+
$output = '';
|
986 |
+
foreach ( $parsed as $media => $content ) {
|
987 |
+
if ( '@media' === substr( $media, 0, 6 ) ) {
|
988 |
+
$output .= $media . " {\n";
|
989 |
+
$prefix = "\t";
|
990 |
+
} else {
|
991 |
+
$prefix = '';
|
992 |
+
}
|
993 |
+
|
994 |
+
foreach ( $content as $selector => $rules ) {
|
995 |
+
$output .= $prefix . $selector . " {\n";
|
996 |
+
foreach ( $rules as $property => $value ) {
|
997 |
+
$output .= $prefix . "\t" . $property . ': ' . $value;
|
998 |
+
$output .= ";\n";
|
999 |
+
}
|
1000 |
+
$output .= $prefix . "}\n\n";
|
1001 |
+
}
|
1002 |
+
if ( '@media' === substr( $media, 0, 6 ) ) {
|
1003 |
+
$output .= "}\n\n";
|
1004 |
+
}
|
1005 |
}
|
1006 |
+
return $output;
|
1007 |
}
|
1008 |
|
1009 |
+
/**
|
1010 |
+
* Method custom_generator()
|
1011 |
+
*
|
1012 |
+
* Set custom generator meta tag.
|
1013 |
+
*
|
1014 |
+
* @param string $generator Contains the generator information.
|
1015 |
+
* @param string $type Contains the generator type information.
|
1016 |
+
*
|
1017 |
+
* @return string Contains the updated generator information.
|
1018 |
+
*/
|
1019 |
+
public function custom_generator( $generator, $type = '' ) {
|
1020 |
$extra_setting = $this->get_extra_options();
|
1021 |
if ( isset( $extra_setting['site_generator'] ) ) {
|
1022 |
if ( ! empty( $extra_setting['site_generator'] ) ) {
|
1046 |
$generator = '<!-- generator="' . $extra_setting['site_generator'] . '" -->';
|
1047 |
break;
|
1048 |
case 'export':
|
1049 |
+
$generator = '<!-- generator="' . $extra_setting['site_generator'] . '" created="' . date( 'Y-m-d H:i' ) . '" -->'; //phpcs:ignore -- current local time.
|
1050 |
break;
|
1051 |
endswitch;
|
1052 |
|
1057 |
return $generator;
|
1058 |
}
|
1059 |
|
1060 |
+
/**
|
1061 |
+
* Method custom_dashboard_widgets()
|
1062 |
+
*
|
1063 |
+
* Hide unwanted WordPress Dashboard page widgets.
|
1064 |
+
*/
|
1065 |
+
public function custom_dashboard_widgets() {
|
1066 |
+
|
1067 |
+
/**
|
1068 |
+
* Public variable to hold the Metaboxes array.
|
1069 |
+
*
|
1070 |
+
* @var array Metaboxes.
|
1071 |
+
*/
|
1072 |
global $wp_meta_boxes;
|
1073 |
+
|
1074 |
$extra_setting = $this->get_extra_options();
|
1075 |
if ( isset( $extra_setting['remove_widget_welcome'] ) && $extra_setting['remove_widget_welcome'] ) {
|
1076 |
remove_action( 'welcome_panel', 'wp_welcome_panel' );
|
1089 |
}
|
1090 |
}
|
1091 |
|
1092 |
+
/**
|
1093 |
+
* Method branding_global_footer()
|
1094 |
+
*
|
1095 |
+
* Set custom footer text.
|
1096 |
+
*/
|
1097 |
public function branding_global_footer() {
|
1098 |
$extra_setting = $this->get_extra_options();
|
1099 |
if ( isset( $extra_setting['global_footer'] ) && ! empty( $extra_setting['global_footer'] ) ) {
|
1101 |
}
|
1102 |
}
|
1103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1104 |
/**
|
1105 |
+
* Method add_support_button_in_top_admin_bar()
|
1106 |
+
*
|
1107 |
+
* Add or remove the admin bar Support button node.
|
1108 |
+
*
|
1109 |
+
* @param object $wp_admin_bar An object containing the WP Admin bar information.
|
1110 |
+
*
|
1111 |
+
* @return bool If conditions not met, return false.
|
1112 |
*/
|
1113 |
public function add_support_button_in_top_admin_bar( $wp_admin_bar ) {
|
1114 |
+
|
1115 |
+
/**
|
1116 |
+
* Filter 'mainwp_branding_role_cap_enable_contact_form'
|
1117 |
+
*
|
1118 |
+
* Manage the support form visibility. Set false to hide the support form page.
|
1119 |
+
*
|
1120 |
+
* @since 4.0
|
1121 |
+
*/
|
1122 |
+
$enable_contact = apply_filters( 'mainwp_branding_role_cap_enable_contact_form', false );
|
1123 |
+
|
1124 |
+
if ( ! $enable_contact && ! current_user_can( 'administrator' ) ) {
|
1125 |
return false;
|
1126 |
}
|
1127 |
|
1128 |
if ( isset( $_GET['from_page'] ) ) {
|
1129 |
+
$href = admin_url( 'admin.php?page=ContactSupport&from_page=' . ( ! empty( $_GET['from_page'] ) ? rawurlencode( esc_url( wp_unslash( $_GET['from_page'] ) ) ) : '' ) );
|
1130 |
} else {
|
1131 |
+
$protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) ), 'off' ) ? 'https://' : 'http://';
|
1132 |
+
$fullurl = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? $protocol . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . wp_unslash( $_SERVER['REQUEST_URI'] ) : '';
|
1133 |
+
$href = admin_url( 'admin.php?page=ContactSupport&from_page=' . rawurlencode( esc_url( $fullurl ) ) );
|
1134 |
}
|
1135 |
$args = array(
|
1136 |
'id' => 999,
|
1146 |
$wp_admin_bar->add_node( $args );
|
1147 |
}
|
1148 |
|
1149 |
+
/**
|
1150 |
+
* Method is_branding()
|
1151 |
+
*
|
1152 |
+
* Check if the custom branding is enabled.
|
1153 |
+
*
|
1154 |
+
* @return bool If branding enabled, return true, if not, return false.
|
1155 |
+
*/
|
1156 |
public function is_branding() {
|
1157 |
+
$opts = $this->child_branding_options;
|
1158 |
+
|
1159 |
+
if ( ! isset( $opts['branding_ext_enabled'] ) || 'Y' !== $opts['branding_ext_enabled'] ) {
|
1160 |
+
return false;
|
1161 |
+
}
|
1162 |
+
|
1163 |
+
$is_hide = isset( $opts['hide'] ) ? $opts['hide'] : '';
|
1164 |
+
$cancelled_branding = $opts['cancelled_branding'];
|
1165 |
+
$branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : '';
|
1166 |
+
|
1167 |
+
if ( $cancelled_branding ) {
|
1168 |
+
return false;
|
1169 |
+
}
|
1170 |
+
|
1171 |
+
if ( 'T' === $is_hide ) {
|
1172 |
+
return true;
|
1173 |
+
}
|
1174 |
+
|
1175 |
+
if ( is_array( $branding_header ) && ! empty( $branding_header['name'] ) ) {
|
1176 |
+
return true;
|
1177 |
+
}
|
1178 |
+
|
1179 |
+
return false;
|
1180 |
}
|
1181 |
|
1182 |
+
/**
|
1183 |
+
* Method get_branding_title()
|
1184 |
+
*
|
1185 |
+
* Get custom title for the MainWP Child plugin.
|
1186 |
+
*
|
1187 |
+
* @return mixed If branding enabled, return custom title.
|
1188 |
+
*/
|
1189 |
+
public function get_branding_title() {
|
1190 |
if ( $this->is_branding() ) {
|
1191 |
+
$branding_header = $this->child_branding_options['branding_header'];
|
1192 |
return $branding_header['name'];
|
1193 |
}
|
1194 |
return '';
|
1195 |
}
|
1196 |
|
1197 |
+
/**
|
1198 |
+
* Method get_branding_options()
|
1199 |
+
*
|
1200 |
+
* Get branding options.
|
1201 |
+
*
|
1202 |
+
* @return array An array containing the branding options.
|
1203 |
+
*/
|
1204 |
+
public function get_branding_options() {
|
1205 |
+
return $this->child_branding_options;
|
1206 |
+
}
|
1207 |
+
|
1208 |
+
/**
|
1209 |
+
* Method save_branding_options()
|
1210 |
+
*
|
1211 |
+
* Save branding options.
|
1212 |
+
*
|
1213 |
+
* @param string $name Contains the option name.
|
1214 |
+
* @param string $val Contains the option value.
|
1215 |
+
*
|
1216 |
+
* @uses MainWP_Helper::update_option() Update database option.
|
1217 |
+
*/
|
1218 |
+
public function save_branding_options( $name, $val ) {
|
1219 |
+
$this->child_branding_options[ $name ] = $val;
|
1220 |
+
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options );
|
1221 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1222 |
|
1223 |
+
/**
|
1224 |
+
* Method branding_map_meta_cap()
|
1225 |
+
*
|
1226 |
+
* Set cutom capabilities to disable theme switching.
|
1227 |
+
*
|
1228 |
+
* @param array $caps An array of capabiilities.
|
1229 |
+
* @param string $cap Contains the capability.
|
1230 |
+
* @param int $user_id Current user ID.
|
1231 |
+
* @param array $args An array of arguments to process.
|
1232 |
+
*
|
1233 |
+
* @return array $caps An array of updated capabiilities.
|
1234 |
+
*/
|
1235 |
public function branding_map_meta_cap( $caps, $cap, $user_id, $args ) {
|
1236 |
+
if ( isset( $this->child_branding_options['disable_switching_theme'] ) && 'T' === $this->child_branding_options['disable_switching_theme'] ) {
|
|
|
1237 |
if ( 'switch_themes' === $cap ) {
|
1238 |
$caps[0] = 'do_not_allow';
|
1239 |
}
|
1241 |
return $caps;
|
1242 |
}
|
1243 |
|
1244 |
+
/**
|
1245 |
+
* Method modify_plugin_header()
|
1246 |
+
*
|
1247 |
+
* Modify plugin header to show custom plugin info.
|
1248 |
+
*
|
1249 |
+
* @param array $plugins An array of installed plugins information.
|
1250 |
+
*
|
1251 |
+
* @return array $plugins Updated array of installed plugins information.
|
1252 |
+
*/
|
1253 |
public function modify_plugin_header( $plugins ) {
|
1254 |
+
$opts = $this->child_branding_options;
|
1255 |
+
if ( is_array( $opts ) ) {
|
1256 |
+
$is_hide = isset( $opts['hide'] ) ? $opts['hide'] : '';
|
1257 |
+
$cancelled_branding = $opts['cancelled_branding'];
|
1258 |
+
$branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : '';
|
1259 |
+
|
1260 |
+
if ( $cancelled_branding ) {
|
1261 |
+
return $plugins;
|
1262 |
+
}
|
1263 |
+
|
1264 |
+
if ( 'T' === $is_hide ) {
|
1265 |
+
foreach ( $plugins as $key => $value ) {
|
1266 |
+
$plugin_slug = basename( $key, '.php' );
|
1267 |
+
if ( 'mainwp-child' === $plugin_slug ) {
|
1268 |
+
unset( $plugins[ $key ] );
|
1269 |
+
}
|
1270 |
+
}
|
1271 |
+
return $plugins;
|
1272 |
+
}
|
1273 |
+
|
1274 |
+
if ( is_array( $branding_header ) && ! empty( $branding_header['name'] ) ) {
|
1275 |
+
return $this->update_plugin_header( $plugins, $branding_header );
|
1276 |
+
} else {
|
1277 |
+
return $plugins;
|
1278 |
+
}
|
1279 |
+
}
|
|
|
|
|
|
|
1280 |
|
1281 |
+
return $plugins;
|
1282 |
+
}
|
|
|
|
|
1283 |
|
1284 |
+
/**
|
1285 |
+
* Method hide_update_notice()
|
1286 |
+
*
|
1287 |
+
* Hide the MainWP Child update notice if custom branding is applied.
|
1288 |
+
*
|
1289 |
+
* @param array $slugs An array of slugs of all installed plugins.
|
1290 |
+
*
|
1291 |
+
* @return array $slugs Updated array of slugs of all installed plugins.
|
1292 |
+
*/
|
1293 |
+
public function hide_update_notice( $slugs ) {
|
1294 |
+
$slugs[] = 'mainwp-child/mainwp-child.php';
|
1295 |
+
return $slugs;
|
1296 |
+
}
|
1297 |
|
1298 |
+
/**
|
1299 |
+
* Method remove_update_nag()
|
1300 |
+
*
|
1301 |
+
* Hide the MainWP Child update notification on the Updates page.
|
1302 |
+
*
|
1303 |
+
* @param object $value Object containing the updates info.
|
1304 |
+
*
|
1305 |
+
* @return object $value Updated object containing the updates info.
|
1306 |
+
*/
|
1307 |
+
public function remove_update_nag( $value ) {
|
1308 |
+
if ( isset( $_POST['mainwpsignature'] ) ) {
|
1309 |
return $value;
|
1310 |
}
|
1311 |
|
1312 |
+
if ( ! MainWP_Helper::is_updates_screen() ) {
|
1313 |
+
return $value;
|
1314 |
+
}
|
1315 |
|
1316 |
if ( isset( $value->response['mainwp-child/mainwp-child.php'] ) ) {
|
1317 |
unset( $value->response['mainwp-child/mainwp-child.php'] );
|
1319 |
return $value;
|
1320 |
}
|
1321 |
|
1322 |
+
|
1323 |
+
/**
|
1324 |
+
* Method update_plugin_header()
|
1325 |
+
*
|
1326 |
+
* Update plugin header to show custom plugin info.
|
1327 |
+
*
|
1328 |
+
* @param array $plugins An array of installed plugins information.
|
1329 |
+
* @param array $header An array containig plugin information.
|
1330 |
+
*
|
1331 |
+
* @return array $plugins Updated array of installed plugins information.
|
1332 |
+
*/
|
1333 |
public function update_plugin_header( $plugins, $header ) {
|
1334 |
$plugin_key = '';
|
1335 |
foreach ( $plugins as $key => $value ) {
|
1354 |
return $plugins;
|
1355 |
}
|
1356 |
}
|
|
class/class-mainwp-child-bulk-settings-manager.php
ADDED
@@ -0,0 +1,310 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Bulk Settings Manager
|
4 |
+
*
|
5 |
+
* This file handles connecting to the child site as a browser in order performs an HTTP request using the POST method and returns its response.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_Bulk_Settings_Manager
|
14 |
+
*
|
15 |
+
* Handles connecting to the child site as a browser in order performs an HTTP request using the POST method and returns its response.
|
16 |
+
*/
|
17 |
+
class MainWP_Child_Bulk_Settings_Manager {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Public static variable to hold the single instance of the class.
|
21 |
+
*
|
22 |
+
* @var mixed Default null
|
23 |
+
*/
|
24 |
+
public static $instance = null;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Public statis variable containing the synchronization information.
|
28 |
+
*
|
29 |
+
* @var array Synchronization information.
|
30 |
+
*/
|
31 |
+
public static $information = array();
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Public variable to hold the information about the language domain.
|
35 |
+
*
|
36 |
+
* @var string 'mainwp-child' languge domain.
|
37 |
+
*/
|
38 |
+
public $plugin_translate = 'mainwp-child';
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Create public static instance for MainWP_Child_Bulk_Settings_Manager.
|
42 |
+
*
|
43 |
+
* @return MainWP_Child_Bulk_Settings_Manager|null
|
44 |
+
*/
|
45 |
+
public static function instance() {
|
46 |
+
if ( null === self::$instance ) {
|
47 |
+
self::$instance = new self();
|
48 |
+
}
|
49 |
+
|
50 |
+
return self::$instance;
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Save Settings & Visit Site as Browser actions.
|
55 |
+
*/
|
56 |
+
public function action() {
|
57 |
+
|
58 |
+
/**
|
59 |
+
* MainWP bulk settings manager fatal error handler.
|
60 |
+
*/
|
61 |
+
function mainwp_bulk_settings_manager_handle_fatal_error() {
|
62 |
+
$error = error_get_last();
|
63 |
+
if ( isset( $error['type'] ) && in_array( $error['type'], array( 1, 4, 16, 64, 256 ) ) && isset( $error['message'] ) ) {
|
64 |
+
MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
register_shutdown_function( '\MainWP\Child\mainwp_bulk_settings_manager_handle_fatal_error' );
|
69 |
+
|
70 |
+
$mwp_action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
71 |
+
switch ( $mwp_action ) {
|
72 |
+
case 'skeleton_key_visit_site_as_browser': // deprecated.
|
73 |
+
$information = $this->visit_site_as_browser();
|
74 |
+
break;
|
75 |
+
case 'bulk_settings_manager_visit_site_as_browser':
|
76 |
+
$information = $this->visit_site_as_browser();
|
77 |
+
break;
|
78 |
+
case 'save_settings':
|
79 |
+
$information = $this->save_settings();
|
80 |
+
break;
|
81 |
+
default:
|
82 |
+
$information = array( 'error' => 'Unknown action' );
|
83 |
+
}
|
84 |
+
|
85 |
+
MainWP_Helper::write( $information );
|
86 |
+
exit();
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Visit site as a browser.
|
91 |
+
*
|
92 |
+
* @return array|string[] Response array or Error message string within an array.
|
93 |
+
*/
|
94 |
+
protected function visit_site_as_browser() { // phpcs:ignore -- ignore complex method notice.
|
95 |
+
if ( ! isset( $_POST['url'] ) || ! is_string( wp_unslash( $_POST['url'] ) ) || strlen( wp_unslash( $_POST['url'] ) ) < 2 ) {
|
96 |
+
return array( 'error' => 'Missing url' );
|
97 |
+
}
|
98 |
+
|
99 |
+
if ( ! isset( $_POST['args'] ) || ! is_array( $_POST['args'] ) ) {
|
100 |
+
return array( 'error' => 'Missing args' );
|
101 |
+
}
|
102 |
+
|
103 |
+
$_POST = stripslashes_deep( wp_unslash( $_POST ) );
|
104 |
+
|
105 |
+
$args = isset( $_POST['args'] ) ? wp_unslash( $_POST['args'] ) : array();
|
106 |
+
|
107 |
+
$current_user = wp_get_current_user();
|
108 |
+
|
109 |
+
$url = isset( $_POST['url'] ) ? '/' . wp_unslash( $_POST['url'] ) : '';
|
110 |
+
|
111 |
+
$expiration = time() + 600;
|
112 |
+
$manager = \WP_Session_Tokens::get_instance( $current_user->ID );
|
113 |
+
$token = $manager->create( $expiration );
|
114 |
+
|
115 |
+
$secure = is_ssl();
|
116 |
+
if ( $secure ) {
|
117 |
+
$auth_cookie_name = SECURE_AUTH_COOKIE;
|
118 |
+
$scheme = 'secure_auth';
|
119 |
+
} else {
|
120 |
+
$auth_cookie_name = AUTH_COOKIE;
|
121 |
+
$scheme = 'auth';
|
122 |
+
}
|
123 |
+
$auth_cookie = wp_generate_auth_cookie( $current_user->ID, $expiration, $scheme, $token );
|
124 |
+
$logged_in_cookie = wp_generate_auth_cookie( $current_user->ID, $expiration, 'logged_in', $token );
|
125 |
+
$_COOKIE[ $auth_cookie_name ] = $auth_cookie;
|
126 |
+
$_COOKIE[ LOGGED_IN_COOKIE ] = $logged_in_cookie;
|
127 |
+
$post_args = array();
|
128 |
+
$post_args['body'] = array();
|
129 |
+
$post_args['redirection'] = 5;
|
130 |
+
$post_args['decompress'] = false;
|
131 |
+
$post_args['cookies'] = array(
|
132 |
+
new \WP_Http_Cookie(
|
133 |
+
array(
|
134 |
+
'name' => $auth_cookie_name,
|
135 |
+
'value' => $auth_cookie,
|
136 |
+
)
|
137 |
+
),
|
138 |
+
new \WP_Http_Cookie(
|
139 |
+
array(
|
140 |
+
'name' => LOGGED_IN_COOKIE,
|
141 |
+
'value' => $logged_in_cookie,
|
142 |
+
)
|
143 |
+
),
|
144 |
+
);
|
145 |
+
|
146 |
+
if ( isset( $args['get'] ) ) {
|
147 |
+
$get_args = $args['get'];
|
148 |
+
parse_str( $args['get'], $get_args );
|
149 |
+
}
|
150 |
+
|
151 |
+
if ( ! isset( $get_args ) || ! is_array( $get_args ) ) {
|
152 |
+
$get_args = array();
|
153 |
+
}
|
154 |
+
|
155 |
+
$get_args['bulk_settings_manageruse_nonce_key'] = intval( time() );
|
156 |
+
$get_args['bulk_settings_manageruse_nonce_hmac'] = hash_hmac( 'sha256', $get_args['bulk_settings_manageruse_nonce_key'], NONCE_KEY );
|
157 |
+
|
158 |
+
$good_nonce = null;
|
159 |
+
if ( isset( $args['nonce'] ) && ! empty( $args['nonce'] ) ) {
|
160 |
+
parse_str( $args['nonce'], $temp_nonce );
|
161 |
+
$good_nonce = $this->wp_create_nonce_recursive( $temp_nonce );
|
162 |
+
$get_args = array_merge( $get_args, $good_nonce );
|
163 |
+
}
|
164 |
+
|
165 |
+
if ( isset( $args['post'] ) ) {
|
166 |
+
parse_str( $args['post'], $temp_post );
|
167 |
+
if ( ! isset( $temp_post ) || ! is_array( $temp_post ) ) {
|
168 |
+
$temp_post = array();
|
169 |
+
}
|
170 |
+
|
171 |
+
if ( ! empty( $good_nonce ) ) {
|
172 |
+
$temp_post = array_merge( $temp_post, $good_nonce );
|
173 |
+
}
|
174 |
+
|
175 |
+
$post_args['body'] = $temp_post;
|
176 |
+
}
|
177 |
+
|
178 |
+
$post_args['timeout'] = 25;
|
179 |
+
|
180 |
+
$full_url = add_query_arg( $get_args, get_site_url() . $url );
|
181 |
+
|
182 |
+
add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 );
|
183 |
+
|
184 |
+
$response = wp_remote_post( $full_url, $post_args );
|
185 |
+
|
186 |
+
if ( is_wp_error( $response ) ) {
|
187 |
+
return array( 'error' => 'wp_remote_post error: ' . $response->get_error_message() );
|
188 |
+
}
|
189 |
+
|
190 |
+
$received_content = wp_remote_retrieve_body( $response );
|
191 |
+
|
192 |
+
if ( preg_match( '/<mainwp>(.*)<\/mainwp>/', $received_content, $received_result ) > 0 ) {
|
193 |
+
$received_content_mainwp = json_decode( base64_decode( $received_result[1] ), true ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
194 |
+
if ( isset( $received_content_mainwp['error'] ) ) {
|
195 |
+
return array( 'error' => $received_content_mainwp['error'] );
|
196 |
+
}
|
197 |
+
}
|
198 |
+
|
199 |
+
$search_ok_counter = 0;
|
200 |
+
$search_fail_counter = 0;
|
201 |
+
|
202 |
+
if ( isset( $args['search']['ok'] ) ) {
|
203 |
+
foreach ( $args['search']['ok'] as $search ) {
|
204 |
+
if ( preg_match( '/' . preg_quote( $search, '/' ) . '/i', $received_content ) ) {
|
205 |
+
++ $search_ok_counter;
|
206 |
+
}
|
207 |
+
}
|
208 |
+
}
|
209 |
+
|
210 |
+
if ( isset( $args['search']['fail'] ) ) {
|
211 |
+
foreach ( $args['search']['fail'] as $search ) {
|
212 |
+
if ( preg_match( '/' . preg_quote( $search, '/' ) . '/i', $received_content ) ) {
|
213 |
+
++ $search_fail_counter;
|
214 |
+
}
|
215 |
+
}
|
216 |
+
}
|
217 |
+
unset( $get_args['bulk_settings_manageruse_nonce_key'] );
|
218 |
+
unset( $get_args['bulk_settings_manageruse_nonce_hmac'] );
|
219 |
+
|
220 |
+
return array(
|
221 |
+
'success' => 1,
|
222 |
+
'content' => $received_content,
|
223 |
+
'url' => $full_url,
|
224 |
+
'get' => $get_args,
|
225 |
+
'post' => $post_args['body'],
|
226 |
+
'search_ok_counter' => $search_ok_counter,
|
227 |
+
'search_fail_counter' => $search_fail_counter,
|
228 |
+
);
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Create WP nonce.
|
233 |
+
*
|
234 |
+
* @param array $array An array containing the nonce.
|
235 |
+
*
|
236 |
+
* @return array An array containing the nonce.
|
237 |
+
*/
|
238 |
+
private function wp_create_nonce_recursive( $array ) {
|
239 |
+
foreach ( $array as $key => $value ) {
|
240 |
+
if ( is_array( $array[ $key ] ) ) {
|
241 |
+
$array[ $key ] = $this->wp_create_nonce_recursive( $array[ $key ] );
|
242 |
+
} else {
|
243 |
+
$array[ $key ] = wp_create_nonce( $array[ $key ] );
|
244 |
+
}
|
245 |
+
}
|
246 |
+
|
247 |
+
return $array;
|
248 |
+
}
|
249 |
+
|
250 |
+
/**
|
251 |
+
* Save site settings.
|
252 |
+
*
|
253 |
+
* @return array|bool|string[] Result array ok|error or FALSE or $whitelist_options[].
|
254 |
+
*/
|
255 |
+
public function save_settings() {
|
256 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
257 |
+
|
258 |
+
if ( ! is_array( $settings ) || empty( $settings ) ) {
|
259 |
+
return array( 'error' => __( 'Invalid data. Please check and try again.', 'mainwp-child' ) );
|
260 |
+
}
|
261 |
+
|
262 |
+
$whitelist_options = array(
|
263 |
+
'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG' ),
|
264 |
+
);
|
265 |
+
|
266 |
+
if ( ! is_multisite() ) {
|
267 |
+
if ( ! defined( 'WP_SITEURL' ) ) {
|
268 |
+
$whitelist_options['general'][] = 'siteurl';
|
269 |
+
}
|
270 |
+
if ( ! defined( 'WP_HOME' ) ) {
|
271 |
+
$whitelist_options['general'][] = 'home';
|
272 |
+
}
|
273 |
+
|
274 |
+
$whitelist_options['general'][] = 'admin_email';
|
275 |
+
$whitelist_options['general'][] = 'users_can_register';
|
276 |
+
$whitelist_options['general'][] = 'default_role';
|
277 |
+
}
|
278 |
+
|
279 |
+
$whitelist_general = $whitelist_options['general'];
|
280 |
+
|
281 |
+
if ( ! empty( $settings['WPLANG'] ) ) {
|
282 |
+
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
|
283 |
+
if ( wp_can_install_language_pack() ) {
|
284 |
+
$language = wp_download_language_pack( $settings['WPLANG'] );
|
285 |
+
if ( $language ) {
|
286 |
+
$settings['WPLANG'] = $language;
|
287 |
+
}
|
288 |
+
}
|
289 |
+
}
|
290 |
+
|
291 |
+
$updated = false;
|
292 |
+
foreach ( $settings as $option => $value ) {
|
293 |
+
if ( in_array( $option, $whitelist_general ) ) {
|
294 |
+
if ( ! is_array( $value ) ) {
|
295 |
+
$value = trim( $value );
|
296 |
+
}
|
297 |
+
$value = wp_unslash( $value );
|
298 |
+
update_option( $option, $value );
|
299 |
+
$updated = true;
|
300 |
+
}
|
301 |
+
}
|
302 |
+
|
303 |
+
if ( ! $updated ) {
|
304 |
+
return false;
|
305 |
+
}
|
306 |
+
|
307 |
+
return array( 'result' => 'ok' );
|
308 |
+
}
|
309 |
+
|
310 |
+
}
|
class/class-mainwp-child-callable.php
ADDED
@@ -0,0 +1,865 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Callable Functions
|
4 |
+
*
|
5 |
+
* Manage functions that can be executed on the child site.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
// phpcs:disable WordPress.WP.AlternativeFunctions -- to use external code, third party credit.
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class MainWP_Child_Callable
|
16 |
+
*
|
17 |
+
* Manage functions that can be executed on the child site.
|
18 |
+
*/
|
19 |
+
class MainWP_Child_Callable {
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Public static variable to hold the single instance of the class.
|
23 |
+
*
|
24 |
+
* @var mixed Default null
|
25 |
+
*/
|
26 |
+
protected static $instance = null;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Private variable to hold the array of all callable functions.
|
30 |
+
*
|
31 |
+
* @var array Callable functions.
|
32 |
+
*/
|
33 |
+
private $callableFunctions = array(
|
34 |
+
'stats' => 'get_site_stats',
|
35 |
+
'upgrade' => 'upgrade_wp',
|
36 |
+
'newpost' => 'new_post',
|
37 |
+
'deactivate' => 'deactivate',
|
38 |
+
'newuser' => 'new_user',
|
39 |
+
'newadminpassword' => 'new_admin_password',
|
40 |
+
'installplugintheme' => 'install_plugin_theme',
|
41 |
+
'upgradeplugintheme' => 'upgrade_plugin_theme',
|
42 |
+
'upgradetranslation' => 'upgrade_translation',
|
43 |
+
'backup' => 'backup',
|
44 |
+
'backup_checkpid' => 'backup_checkpid',
|
45 |
+
'cloneinfo' => 'cloneinfo',
|
46 |
+
'security' => 'get_security_stats',
|
47 |
+
'securityFix' => 'do_security_fix',
|
48 |
+
'securityUnFix' => 'do_security_un_fix',
|
49 |
+
'post_action' => 'post_action',
|
50 |
+
'get_all_posts' => 'get_all_posts',
|
51 |
+
'comment_action' => 'comment_action',
|
52 |
+
'comment_bulk_action' => 'comment_bulk_action',
|
53 |
+
'get_all_comments' => 'get_all_comments',
|
54 |
+
'get_all_themes' => 'get_all_themes',
|
55 |
+
'theme_action' => 'theme_action',
|
56 |
+
'get_all_plugins' => 'get_all_plugins',
|
57 |
+
'plugin_action' => 'plugin_action',
|
58 |
+
'get_all_pages' => 'get_all_pages',
|
59 |
+
'get_all_users' => 'get_all_users',
|
60 |
+
'user_action' => 'user_action',
|
61 |
+
'search_users' => 'search_users',
|
62 |
+
'maintenance_site' => 'maintenance_site',
|
63 |
+
'branding_child_plugin' => 'branding_child_plugin',
|
64 |
+
'code_snippet' => 'code_snippet',
|
65 |
+
'uploader_action' => 'uploader_action',
|
66 |
+
'wordpress_seo' => 'wordpress_seo',
|
67 |
+
'client_report' => 'client_report',
|
68 |
+
'createBackupPoll' => 'backup_poll',
|
69 |
+
'page_speed' => 'page_speed',
|
70 |
+
'woo_com_status' => 'woo_com_status',
|
71 |
+
'links_checker' => 'links_checker',
|
72 |
+
'wordfence' => 'wordfence',
|
73 |
+
'delete_backup' => 'delete_backup',
|
74 |
+
'update_values' => 'update_child_values',
|
75 |
+
'ithemes' => 'ithemes',
|
76 |
+
'updraftplus' => 'updraftplus',
|
77 |
+
'backup_wp' => 'backup_wp',
|
78 |
+
'backwpup' => 'backwpup',
|
79 |
+
'wp_rocket' => 'wp_rocket',
|
80 |
+
'settings_tools' => 'settings_tools',
|
81 |
+
'skeleton_key' => 'bulk_settings_manager', // deprecated.
|
82 |
+
'bulk_settings_manager' => 'bulk_settings_manager',
|
83 |
+
'custom_post_type' => 'custom_post_type',
|
84 |
+
'backup_buddy' => 'backup_buddy',
|
85 |
+
'get_site_icon' => 'get_site_icon',
|
86 |
+
'vulner_checker' => 'vulner_checker',
|
87 |
+
'wp_staging' => 'wp_staging',
|
88 |
+
'disconnect' => 'disconnect',
|
89 |
+
'time_capsule' => 'time_capsule',
|
90 |
+
'extra_excution' => 'extra_execution', // deprecated!
|
91 |
+
'extra_execution' => 'extra_execution',
|
92 |
+
'wpvivid_backuprestore' => 'wpvivid_backuprestore',
|
93 |
+
);
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Private variable to hold the array of all callable functions that don't require regularl authentication.
|
97 |
+
*
|
98 |
+
* @var array Callable functions.
|
99 |
+
*/
|
100 |
+
private $callableFunctionsNoAuth = array(
|
101 |
+
'stats' => 'get_site_stats_no_auth',
|
102 |
+
);
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Method get_class_name()
|
106 |
+
*
|
107 |
+
* Get class name.
|
108 |
+
*
|
109 |
+
* @return string __CLASS__ Class name.
|
110 |
+
*/
|
111 |
+
public static function get_class_name() {
|
112 |
+
return __CLASS__;
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* MainWP_Child_Callable constructor.
|
117 |
+
*
|
118 |
+
* Run any time class is called.
|
119 |
+
*/
|
120 |
+
public function __construct() {
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Method instance()
|
125 |
+
*
|
126 |
+
* Create a public static instance.
|
127 |
+
*
|
128 |
+
* @return mixed Class instance.
|
129 |
+
*/
|
130 |
+
public static function get_instance() {
|
131 |
+
if ( null === self::$instance ) {
|
132 |
+
self::$instance = new self();
|
133 |
+
}
|
134 |
+
return self::$instance;
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Method init_call_functions()
|
139 |
+
*
|
140 |
+
* Initiate callable functions.
|
141 |
+
*
|
142 |
+
* @param bool $auth If true, regular authentication is required.
|
143 |
+
*/
|
144 |
+
public function init_call_functions( $auth = false ) {
|
145 |
+
$callable = false;
|
146 |
+
$callable_no_auth = false;
|
147 |
+
$call_func = false;
|
148 |
+
|
149 |
+
// check if function is callable.
|
150 |
+
if ( isset( $_POST['function'] ) ) {
|
151 |
+
$call_func = isset( $_POST['function'] ) ? sanitize_text_field( wp_unslash( $_POST['function'] ) ) : '';
|
152 |
+
$callable = $this->is_callable_function( $call_func ); // check callable func.
|
153 |
+
$callable_no_auth = $this->is_callable_function_no_auth( $call_func ); // check callable no auth func.
|
154 |
+
}
|
155 |
+
|
156 |
+
// Fire off the called function.
|
157 |
+
if ( $auth && isset( $_POST['function'] ) && $callable ) {
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Checks whether cron is in progress.
|
161 |
+
*
|
162 |
+
* @const ( bool ) Default: true
|
163 |
+
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Callable.html
|
164 |
+
*/
|
165 |
+
define( 'DOING_CRON', true );
|
166 |
+
|
167 |
+
MainWP_Utility::handle_fatal_error();
|
168 |
+
MainWP_Utility::fix_for_custom_themes();
|
169 |
+
$this->call_function( $call_func );
|
170 |
+
} elseif ( isset( $_POST['function'] ) && $callable_no_auth ) {
|
171 |
+
|
172 |
+
/**
|
173 |
+
* Checks whether cron is in progress.
|
174 |
+
*
|
175 |
+
* @const ( bool ) Default: true
|
176 |
+
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Callable.html
|
177 |
+
*/
|
178 |
+
define( 'DOING_CRON', true );
|
179 |
+
|
180 |
+
MainWP_Utility::fix_for_custom_themes();
|
181 |
+
$this->call_function_no_auth( $call_func );
|
182 |
+
} elseif ( isset( $_POST['function'] ) && isset( $_POST['mainwpsignature'] ) && ! $callable && ! $callable_no_auth ) {
|
183 |
+
MainWP_Helper::error( __( 'Required version has not been detected. Please, make sure that you are using the latest version of the MainWP Child plugin on your site.', 'mainwp-child' ) );
|
184 |
+
}
|
185 |
+
}
|
186 |
+
|
187 |
+
/**
|
188 |
+
* Method is_callable_function()
|
189 |
+
*
|
190 |
+
* Check if the function is the list of callable functions.
|
191 |
+
*
|
192 |
+
* @param string $func Contains the name of the function to check.
|
193 |
+
*
|
194 |
+
* @return bool If callable, return true, if not, return false.
|
195 |
+
*/
|
196 |
+
public function is_callable_function( $func ) {
|
197 |
+
if ( isset( $this->callableFunctions[ $func ] ) ) {
|
198 |
+
return true;
|
199 |
+
}
|
200 |
+
return false;
|
201 |
+
}
|
202 |
+
|
203 |
+
/**
|
204 |
+
* Method is_callable_function_no_auth()
|
205 |
+
*
|
206 |
+
* Check if the function is the list of callable functions that don't require regular authentication.
|
207 |
+
*
|
208 |
+
* @param string $func Contains the name of the function to check.
|
209 |
+
*
|
210 |
+
* @return bool If callable, return true, if not, return false.
|
211 |
+
*/
|
212 |
+
public function is_callable_function_no_auth( $func ) {
|
213 |
+
if ( isset( $this->callableFunctionsNoAuth[ $func ] ) ) {
|
214 |
+
return true;
|
215 |
+
}
|
216 |
+
return false;
|
217 |
+
}
|
218 |
+
|
219 |
+
/**
|
220 |
+
* Method call_function()
|
221 |
+
*
|
222 |
+
* Call ceratin function.
|
223 |
+
*
|
224 |
+
* @param string $func Contains the name of the function to call.
|
225 |
+
*/
|
226 |
+
public function call_function( $func ) {
|
227 |
+
if ( $this->is_callable_function( $func ) ) {
|
228 |
+
call_user_func( array( $this, $this->callableFunctions[ $func ] ) );
|
229 |
+
}
|
230 |
+
}
|
231 |
+
|
232 |
+
/**
|
233 |
+
* Method call_function_no_auth()
|
234 |
+
*
|
235 |
+
* Call ceratin function without regular authentication if the function is in the $callableFunctionsNoAuth list.
|
236 |
+
*
|
237 |
+
* @param string $func Contains the name of the function to call.
|
238 |
+
*/
|
239 |
+
public function call_function_no_auth( $func ) {
|
240 |
+
if ( $this->is_callable_function_no_auth( $func ) ) {
|
241 |
+
call_user_func( array( $this, $this->callableFunctionsNoAuth[ $func ] ) );
|
242 |
+
}
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* Method get_site_stats()
|
247 |
+
*
|
248 |
+
* Fire off the get_site_stats() function.
|
249 |
+
*/
|
250 |
+
public function get_site_stats() {
|
251 |
+
MainWP_Child_Stats::get_instance()->get_site_stats();
|
252 |
+
}
|
253 |
+
|
254 |
+
/**
|
255 |
+
* Method get_site_stats_no_auth()
|
256 |
+
*
|
257 |
+
* Fire off the get_site_stats_no_auth() function.
|
258 |
+
*/
|
259 |
+
public function get_site_stats_no_auth() {
|
260 |
+
MainWP_Child_Stats::get_instance()->get_site_stats_no_auth();
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Method install_plugin_theme()
|
265 |
+
*
|
266 |
+
* Fire off the install_plugin_theme() function.
|
267 |
+
*/
|
268 |
+
public function install_plugin_theme() {
|
269 |
+
MainWP_Child_Install::get_instance()->install_plugin_theme();
|
270 |
+
}
|
271 |
+
|
272 |
+
/**
|
273 |
+
* Method upgrade_wp()
|
274 |
+
*
|
275 |
+
* Fire off the upgrade_wp() function.
|
276 |
+
*/
|
277 |
+
public function upgrade_wp() {
|
278 |
+
MainWP_Child_Updates::get_instance()->upgrade_wp();
|
279 |
+
}
|
280 |
+
|
281 |
+
/**
|
282 |
+
* Method upgrade_translation()
|
283 |
+
*
|
284 |
+
* Fire off the upgrade_translation() function.
|
285 |
+
*/
|
286 |
+
public function upgrade_translation() {
|
287 |
+
MainWP_Child_Updates::get_instance()->upgrade_translation();
|
288 |
+
}
|
289 |
+
|
290 |
+
/**
|
291 |
+
* Method upgrade_plugin_theme()
|
292 |
+
*
|
293 |
+
* Fire off the upgrade_plugin_theme() function.
|
294 |
+
*/
|
295 |
+
public function upgrade_plugin_theme() {
|
296 |
+
MainWP_Child_Updates::get_instance()->upgrade_plugin_theme();
|
297 |
+
}
|
298 |
+
|
299 |
+
/**
|
300 |
+
* Method theme_action()
|
301 |
+
*
|
302 |
+
* Fire off the theme_action() function.
|
303 |
+
*/
|
304 |
+
public function theme_action() {
|
305 |
+
MainWP_Child_Install::get_instance()->theme_action();
|
306 |
+
}
|
307 |
+
|
308 |
+
/**
|
309 |
+
* Method plugin_action()
|
310 |
+
*
|
311 |
+
* Fire off the plugin_action() function.
|
312 |
+
*/
|
313 |
+
public function plugin_action() {
|
314 |
+
MainWP_Child_Install::get_instance()->plugin_action();
|
315 |
+
}
|
316 |
+
|
317 |
+
/**
|
318 |
+
* Method get_all_plugins()
|
319 |
+
*
|
320 |
+
* Fire off the get_all_plugins() function.
|
321 |
+
*/
|
322 |
+
public function get_all_plugins() {
|
323 |
+
MainWP_Child_Stats::get_instance()->get_all_plugins();
|
324 |
+
}
|
325 |
+
|
326 |
+
/**
|
327 |
+
* Method get_all_themes()
|
328 |
+
*
|
329 |
+
* Fire off the get_all_themes() function.
|
330 |
+
*/
|
331 |
+
public function get_all_themes() {
|
332 |
+
MainWP_Child_Stats::get_instance()->get_all_themes();
|
333 |
+
}
|
334 |
+
|
335 |
+
/**
|
336 |
+
* Method get_all_users()
|
337 |
+
*
|
338 |
+
* Fire off the get_all_users() function.
|
339 |
+
*/
|
340 |
+
public function get_all_users() {
|
341 |
+
MainWP_Child_Users::get_instance()->get_all_users();
|
342 |
+
}
|
343 |
+
|
344 |
+
/**
|
345 |
+
* Method user_action()
|
346 |
+
*
|
347 |
+
* Fire off the user_action() function.
|
348 |
+
*/
|
349 |
+
public function user_action() {
|
350 |
+
MainWP_Child_Users::get_instance()->user_action();
|
351 |
+
}
|
352 |
+
|
353 |
+
/**
|
354 |
+
* Method search_users()
|
355 |
+
*
|
356 |
+
* Fire off the search_users() function.
|
357 |
+
*/
|
358 |
+
public function search_users() {
|
359 |
+
MainWP_Child_Users::get_instance()->search_users();
|
360 |
+
}
|
361 |
+
|
362 |
+
/**
|
363 |
+
* Method get_all_posts()
|
364 |
+
*
|
365 |
+
* Fire off the get_all_posts() function.
|
366 |
+
*/
|
367 |
+
public function get_all_posts() {
|
368 |
+
MainWP_Child_Posts::get_instance()->get_all_posts();
|
369 |
+
}
|
370 |
+
|
371 |
+
/**
|
372 |
+
* Method get_all_pages()
|
373 |
+
*
|
374 |
+
* Fire off the get_all_pages() function.
|
375 |
+
*/
|
376 |
+
public function get_all_pages() {
|
377 |
+
MainWP_Child_Posts::get_instance()->get_all_pages();
|
378 |
+
}
|
379 |
+
|
380 |
+
/**
|
381 |
+
* Method comment_action()
|
382 |
+
*
|
383 |
+
* Fire off the comment_action() function.
|
384 |
+
*/
|
385 |
+
public function comment_action() {
|
386 |
+
MainWP_Child_Comments::get_instance()->comment_action();
|
387 |
+
}
|
388 |
+
|
389 |
+
/**
|
390 |
+
* Method get_all_comments()
|
391 |
+
*
|
392 |
+
* Fire off the get_all_comments() function.
|
393 |
+
*/
|
394 |
+
public function get_all_comments() {
|
395 |
+
MainWP_Child_Comments::get_instance()->get_all_comments();
|
396 |
+
}
|
397 |
+
|
398 |
+
/**
|
399 |
+
* Method comment_bulk_action()
|
400 |
+
*
|
401 |
+
* Fire off the comment_bulk_action() function.
|
402 |
+
*/
|
403 |
+
public function comment_bulk_action() {
|
404 |
+
MainWP_Child_Comments::get_instance()->comment_bulk_action();
|
405 |
+
}
|
406 |
+
|
407 |
+
/**
|
408 |
+
* Method maintenance_site()
|
409 |
+
*
|
410 |
+
* Fire off the maintenance_site() function.
|
411 |
+
*/
|
412 |
+
public function maintenance_site() {
|
413 |
+
MainWP_Child_Maintenance::get_instance()->maintenance_site();
|
414 |
+
}
|
415 |
+
|
416 |
+
/**
|
417 |
+
* Method new_post()
|
418 |
+
*
|
419 |
+
* Fire off the new_post() function.
|
420 |
+
*/
|
421 |
+
public function new_post() {
|
422 |
+
MainWP_Child_Posts::get_instance()->new_post();
|
423 |
+
}
|
424 |
+
|
425 |
+
/**
|
426 |
+
* Method post_action()
|
427 |
+
*
|
428 |
+
* Fire off the post_action() function.
|
429 |
+
*/
|
430 |
+
public function post_action() {
|
431 |
+
MainWP_Child_Posts::get_instance()->post_action();
|
432 |
+
}
|
433 |
+
|
434 |
+
/**
|
435 |
+
* Method new_admin_password()
|
436 |
+
*
|
437 |
+
* Fire off the new_admin_password() function.
|
438 |
+
*/
|
439 |
+
public function new_admin_password() {
|
440 |
+
MainWP_Child_Users::get_instance()->new_admin_password();
|
441 |
+
}
|
442 |
+
|
443 |
+
/**
|
444 |
+
* Method new_user()
|
445 |
+
*
|
446 |
+
* Fire off the new_user() function.
|
447 |
+
*/
|
448 |
+
public function new_user() {
|
449 |
+
MainWP_Child_Users::get_instance()->new_user();
|
450 |
+
}
|
451 |
+
|
452 |
+
/**
|
453 |
+
* Method cloneinfo()
|
454 |
+
*
|
455 |
+
* Fire off the cloneinfo() function.
|
456 |
+
*/
|
457 |
+
public function cloneinfo() {
|
458 |
+
|
459 |
+
/**
|
460 |
+
* WordPress DB Table Prefix.
|
461 |
+
*
|
462 |
+
* @global string
|
463 |
+
*/
|
464 |
+
global $table_prefix;
|
465 |
+
|
466 |
+
$information['dbCharset'] = DB_CHARSET;
|
467 |
+
$information['dbCollate'] = DB_COLLATE;
|
468 |
+
$information['table_prefix'] = $table_prefix;
|
469 |
+
$information['site_url'] = get_option( 'site_url' );
|
470 |
+
$information['home'] = get_option( 'home' );
|
471 |
+
|
472 |
+
MainWP_Helper::write( $information );
|
473 |
+
}
|
474 |
+
|
475 |
+
/**
|
476 |
+
* Method backup_poll()
|
477 |
+
*
|
478 |
+
* Fire off the backup_poll() function.
|
479 |
+
*/
|
480 |
+
public function backup_poll() {
|
481 |
+
MainWP_Backup::get()->backup_poll();
|
482 |
+
}
|
483 |
+
|
484 |
+
/**
|
485 |
+
* Method backup_checkpid()
|
486 |
+
*
|
487 |
+
* Fire off the backup_checkpid() function.
|
488 |
+
*/
|
489 |
+
public function backup_checkpid() {
|
490 |
+
MainWP_Backup::get()->backup_checkpid();
|
491 |
+
}
|
492 |
+
|
493 |
+
/**
|
494 |
+
* Method backup()
|
495 |
+
*
|
496 |
+
* Fire off the backup() function.
|
497 |
+
*
|
498 |
+
* @param bool $write Whether or not to execute MainWP_Helper::write(), Default: true.
|
499 |
+
*
|
500 |
+
* @return array Action result.
|
501 |
+
*/
|
502 |
+
public function backup( $write = true ) {
|
503 |
+
return MainWP_Backup::get()->backup( $write );
|
504 |
+
}
|
505 |
+
|
506 |
+
/**
|
507 |
+
* Method backup_full()
|
508 |
+
*
|
509 |
+
* Fire off the backup_full() function.
|
510 |
+
*
|
511 |
+
* @param string $file_name Contains the backup file name.
|
512 |
+
*
|
513 |
+
* @return array Action result.
|
514 |
+
*/
|
515 |
+
protected function backup_full( $file_name ) {
|
516 |
+
return MainWP_Backup::get()->backup_full( $file_name );
|
517 |
+
}
|
518 |
+
|
519 |
+
/**
|
520 |
+
* Method backup_db()
|
521 |
+
*
|
522 |
+
* Fire off the backup_db() function.
|
523 |
+
*
|
524 |
+
* @param string $file_name Contains the backup file name.
|
525 |
+
* @param string $file_extension Contains the backup file extension.
|
526 |
+
*
|
527 |
+
* @return array Action result.
|
528 |
+
*/
|
529 |
+
protected function backup_db( $file_name = '', $file_extension = 'zip' ) {
|
530 |
+
return MainWP_Backup::get()->backup_db( $file_name, $file_extension );
|
531 |
+
}
|
532 |
+
|
533 |
+
/**
|
534 |
+
* Method get_site_icon()
|
535 |
+
*
|
536 |
+
* Fire off the get_site_icon() function.
|
537 |
+
*/
|
538 |
+
public function get_site_icon() {
|
539 |
+
MainWP_Child_Misc::get_instance()->get_site_icon();
|
540 |
+
}
|
541 |
+
|
542 |
+
/**
|
543 |
+
* Method get_security_stats()
|
544 |
+
*
|
545 |
+
* Fire off the get_security_stats() function.
|
546 |
+
*/
|
547 |
+
public function get_security_stats() {
|
548 |
+
MainWP_Child_Misc::get_instance()->get_security_stats();
|
549 |
+
}
|
550 |
+
|
551 |
+
/**
|
552 |
+
* Method do_security_fix()
|
553 |
+
*
|
554 |
+
* Fire off the do_security_fix() function.
|
555 |
+
*/
|
556 |
+
public function do_security_fix() {
|
557 |
+
MainWP_Child_Misc::get_instance()->do_security_fix();
|
558 |
+
}
|
559 |
+
|
560 |
+
/**
|
561 |
+
* Method do_security_un_fix()
|
562 |
+
*
|
563 |
+
* Fire off the do_security_un_fix() function.
|
564 |
+
*/
|
565 |
+
public function do_security_un_fix() {
|
566 |
+
MainWP_Child_Misc::get_instance()->do_security_un_fix();
|
567 |
+
}
|
568 |
+
|
569 |
+
/**
|
570 |
+
* Method settings_tools()
|
571 |
+
*
|
572 |
+
* Fire off the settings_tools() function.
|
573 |
+
*/
|
574 |
+
public function settings_tools() {
|
575 |
+
MainWP_Child_Misc::get_instance()->do_security_un_fix();
|
576 |
+
}
|
577 |
+
|
578 |
+
/**
|
579 |
+
* Method bulk_settings_manager()
|
580 |
+
*
|
581 |
+
* Fire off the action() function.
|
582 |
+
*/
|
583 |
+
public function bulk_settings_manager() {
|
584 |
+
MainWP_Child_Bulk_Settings_Manager::instance()->action();
|
585 |
+
}
|
586 |
+
|
587 |
+
/**
|
588 |
+
* Method custom_post_type()
|
589 |
+
*
|
590 |
+
* Fire off the action() function.
|
591 |
+
*/
|
592 |
+
public function custom_post_type() {
|
593 |
+
MainWP_Custom_Post_Type::instance()->action();
|
594 |
+
}
|
595 |
+
|
596 |
+
/**
|
597 |
+
* Method backup_buddy()
|
598 |
+
*
|
599 |
+
* Fire off the action() function.
|
600 |
+
*/
|
601 |
+
public function backup_buddy() {
|
602 |
+
MainWP_Child_Back_Up_Buddy::instance()->action();
|
603 |
+
}
|
604 |
+
|
605 |
+
/**
|
606 |
+
* Method vulner_checker()
|
607 |
+
*
|
608 |
+
* Fire off the action() function.
|
609 |
+
*/
|
610 |
+
public function vulner_checker() {
|
611 |
+
MainWP_Child_Vulnerability_Checker::instance()->action();
|
612 |
+
}
|
613 |
+
|
614 |
+
/**
|
615 |
+
* Method time_capsule()
|
616 |
+
*
|
617 |
+
* Fire off the action() function.
|
618 |
+
*/
|
619 |
+
public function time_capsule() {
|
620 |
+
MainWP_Child_Timecapsule::instance()->action();
|
621 |
+
}
|
622 |
+
|
623 |
+
/**
|
624 |
+
* Method wp_staging()
|
625 |
+
*
|
626 |
+
* Fire off the action() function.
|
627 |
+
*/
|
628 |
+
public function wp_staging() {
|
629 |
+
MainWP_Child_Staging::instance()->action();
|
630 |
+
}
|
631 |
+
|
632 |
+
/**
|
633 |
+
* Method extra_execution()
|
634 |
+
*
|
635 |
+
* Additional functions to execute.
|
636 |
+
*/
|
637 |
+
public function extra_execution() {
|
638 |
+
$post = $_POST;
|
639 |
+
$information = array();
|
640 |
+
/**
|
641 |
+
* Filter 'mainwp_child_extra_execution'
|
642 |
+
*
|
643 |
+
* Additional functions to execute through the filter.
|
644 |
+
*
|
645 |
+
* @param array $information An array containing the synchronization information.
|
646 |
+
* @param mixed $post Contains the POST request.
|
647 |
+
*
|
648 |
+
* @since 4.0
|
649 |
+
*/
|
650 |
+
$information = apply_filters( 'mainwp_child_extra_execution', $information, $post );
|
651 |
+
MainWP_Helper::write( $information );
|
652 |
+
}
|
653 |
+
|
654 |
+
/**
|
655 |
+
* Method uploader_action()
|
656 |
+
*
|
657 |
+
* Fire off the uploader_action() function.
|
658 |
+
*/
|
659 |
+
public function uploader_action() {
|
660 |
+
MainWP_Child_Misc::get_instance()->uploader_action();
|
661 |
+
}
|
662 |
+
|
663 |
+
/**
|
664 |
+
* Method wordpress_seo()
|
665 |
+
*
|
666 |
+
* Fire off the action() function.
|
667 |
+
*/
|
668 |
+
public function wordpress_seo() {
|
669 |
+
MainWP_WordPress_SEO::instance()->action();
|
670 |
+
}
|
671 |
+
|
672 |
+
/**
|
673 |
+
* Method client_report()
|
674 |
+
*
|
675 |
+
* Fire off the action() function.
|
676 |
+
*/
|
677 |
+
public function client_report() {
|
678 |
+
MainWP_Client_Report::instance()->action();
|
679 |
+
}
|
680 |
+
|
681 |
+
/**
|
682 |
+
* Method page_speed()
|
683 |
+
*
|
684 |
+
* Fire off the action() function.
|
685 |
+
*/
|
686 |
+
public function page_speed() {
|
687 |
+
MainWP_Child_Pagespeed::instance()->action();
|
688 |
+
}
|
689 |
+
|
690 |
+
/**
|
691 |
+
* Method woo_com_status()
|
692 |
+
*
|
693 |
+
* Fire off the action() function.
|
694 |
+
*/
|
695 |
+
public function woo_com_status() {
|
696 |
+
MainWP_Child_WooCommerce_Status::instance()->action();
|
697 |
+
}
|
698 |
+
|
699 |
+
/**
|
700 |
+
* Method links_checker()
|
701 |
+
*
|
702 |
+
* Fire off the action() function.
|
703 |
+
*/
|
704 |
+
public function links_checker() {
|
705 |
+
MainWP_Child_Links_Checker::instance()->action();
|
706 |
+
}
|
707 |
+
|
708 |
+
/**
|
709 |
+
* Method wordfence()
|
710 |
+
*
|
711 |
+
* Fire off the action() function.
|
712 |
+
*/
|
713 |
+
public function wordfence() {
|
714 |
+
MainWP_Child_Wordfence::instance()->action();
|
715 |
+
}
|
716 |
+
|
717 |
+
/**
|
718 |
+
* Method ithemes()
|
719 |
+
*
|
720 |
+
* Fire off the action() function.
|
721 |
+
*/
|
722 |
+
public function ithemes() {
|
723 |
+
MainWP_Child_IThemes_Security::instance()->action();
|
724 |
+
}
|
725 |
+
|
726 |
+
/**
|
727 |
+
* Method updraftplus()
|
728 |
+
*
|
729 |
+
* Fire off the action() function.
|
730 |
+
*/
|
731 |
+
public function updraftplus() {
|
732 |
+
MainWP_Child_Updraft_Plus_Backups::instance()->action();
|
733 |
+
}
|
734 |
+
|
735 |
+
/**
|
736 |
+
* Method wpvivid_backuprestore()
|
737 |
+
*
|
738 |
+
* Fire off the action() function.
|
739 |
+
*/
|
740 |
+
public function wpvivid_backuprestore() {
|
741 |
+
MainWP_Child_WPvivid_BackupRestore::instance()->action();
|
742 |
+
}
|
743 |
+
|
744 |
+
/**
|
745 |
+
* Method backup_wp()
|
746 |
+
*
|
747 |
+
* Fire off the action() function.
|
748 |
+
*/
|
749 |
+
public function backup_wp() {
|
750 |
+
if ( ! version_compare( phpversion(), '5.3', '>=' ) ) {
|
751 |
+
$error = sprintf( __( 'PHP Version %s is unsupported.', 'mainwp-child' ), phpversion() );
|
752 |
+
MainWP_Helper::write( array( 'error' => $error ) );
|
753 |
+
}
|
754 |
+
MainWP_Child_Back_Up_WordPress::instance()->action();
|
755 |
+
}
|
756 |
+
|
757 |
+
/**
|
758 |
+
* Method wp_rocket()
|
759 |
+
*
|
760 |
+
* Fire off the action() function.
|
761 |
+
*/
|
762 |
+
public function wp_rocket() {
|
763 |
+
MainWP_Child_WP_Rocket::instance()->action();
|
764 |
+
}
|
765 |
+
|
766 |
+
/**
|
767 |
+
* Method backwpup()
|
768 |
+
*
|
769 |
+
* Fire off the action() function.
|
770 |
+
*/
|
771 |
+
public function backwpup() {
|
772 |
+
MainWP_Child_Back_WP_Up::instance()->action();
|
773 |
+
}
|
774 |
+
|
775 |
+
/**
|
776 |
+
* Method delete_backup()
|
777 |
+
*
|
778 |
+
* Delete backup.
|
779 |
+
*/
|
780 |
+
public function delete_backup() {
|
781 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
782 |
+
$backupdir = $dirs[0];
|
783 |
+
|
784 |
+
$file = isset( $_REQUEST['del'] ) ? wp_unslash( $_REQUEST['del'] ) : '';
|
785 |
+
|
786 |
+
if ( file_exists( $backupdir . $file ) ) {
|
787 |
+
unlink( $backupdir . $file );
|
788 |
+
}
|
789 |
+
|
790 |
+
MainWP_Helper::write( array( 'result' => 'ok' ) );
|
791 |
+
}
|
792 |
+
|
793 |
+
/**
|
794 |
+
* Method update_child_values()
|
795 |
+
*
|
796 |
+
* Update the MainWP Child site options.
|
797 |
+
*/
|
798 |
+
public function update_child_values() {
|
799 |
+
$unique_id = isset( $_POST['uniqueId'] ) ? sanitize_text_field( wp_unslash( $_POST['uniqueId'] ) ) : '';
|
800 |
+
MainWP_Helper::update_option( 'mainwp_child_uniqueId', $unique_id );
|
801 |
+
MainWP_Helper::write( array( 'result' => 'ok' ) );
|
802 |
+
}
|
803 |
+
|
804 |
+
/**
|
805 |
+
* Method branding_child_plugin()
|
806 |
+
*
|
807 |
+
* Fire off the action() function.
|
808 |
+
*/
|
809 |
+
public function branding_child_plugin() {
|
810 |
+
MainWP_Child_Branding::instance()->action();
|
811 |
+
}
|
812 |
+
|
813 |
+
/**
|
814 |
+
* Method code_snippet()
|
815 |
+
*
|
816 |
+
* Fire off the code_snippet() function.
|
817 |
+
*/
|
818 |
+
public function code_snippet() {
|
819 |
+
MainWP_Child_Misc::get_instance()->code_snippet();
|
820 |
+
}
|
821 |
+
|
822 |
+
/**
|
823 |
+
* Method disconnect()
|
824 |
+
*
|
825 |
+
* Disconnect the child site from the current MainWP Dashboard.
|
826 |
+
*/
|
827 |
+
public function disconnect() {
|
828 |
+
|
829 |
+
/**
|
830 |
+
* MainWP Child instance.
|
831 |
+
*
|
832 |
+
* @global object
|
833 |
+
*/
|
834 |
+
global $mainWPChild;
|
835 |
+
|
836 |
+
$mainWPChild->deactivation( false );
|
837 |
+
MainWP_Helper::write( array( 'result' => 'success' ) );
|
838 |
+
}
|
839 |
+
|
840 |
+
|
841 |
+
/**
|
842 |
+
* Method deactivate()
|
843 |
+
*
|
844 |
+
* Deactivate the MainWP Child plugin in the site.
|
845 |
+
*/
|
846 |
+
public function deactivate() {
|
847 |
+
|
848 |
+
/**
|
849 |
+
* MainWP Child instance.
|
850 |
+
*
|
851 |
+
* @global object
|
852 |
+
*/
|
853 |
+
global $mainWPChild;
|
854 |
+
|
855 |
+
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
856 |
+
deactivate_plugins( $mainWPChild->plugin_slug, true );
|
857 |
+
$information = array();
|
858 |
+
if ( is_plugin_active( $mainWPChild->plugin_slug ) ) {
|
859 |
+
MainWP_Helper::error( 'Plugin still active' );
|
860 |
+
}
|
861 |
+
$information['deactivated'] = true;
|
862 |
+
MainWP_Helper::write( $information );
|
863 |
+
}
|
864 |
+
|
865 |
+
}
|
class/class-mainwp-child-comments.php
ADDED
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Comments
|
4 |
+
*
|
5 |
+
* This file handles all Child Site comment actions.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_Comments
|
14 |
+
*
|
15 |
+
* Handles all Child Site comment actions.
|
16 |
+
*/
|
17 |
+
class MainWP_Child_Comments {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Public static variable to hold the single instance of the class.
|
21 |
+
*
|
22 |
+
* @var mixed Default null
|
23 |
+
*/
|
24 |
+
protected static $instance = null;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Comments and clauses.
|
28 |
+
*
|
29 |
+
* @var string Comments and clauses.
|
30 |
+
*/
|
31 |
+
private $comments_and_clauses;
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Get Class Name.
|
35 |
+
*
|
36 |
+
* @return string
|
37 |
+
*/
|
38 |
+
public static function get_class_name() {
|
39 |
+
return __CLASS__;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* MainWP_Child_Comments constructor.
|
44 |
+
*
|
45 |
+
* Run any time class is called.
|
46 |
+
*/
|
47 |
+
public function __construct() {
|
48 |
+
$this->comments_and_clauses = '';
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Create a public static instance of ainWP_Child_Comments.
|
53 |
+
*
|
54 |
+
* @return MainWP_Child_Comments|null
|
55 |
+
*/
|
56 |
+
public static function get_instance() {
|
57 |
+
if ( null === self::$instance ) {
|
58 |
+
self::$instance = new self();
|
59 |
+
}
|
60 |
+
return self::$instance;
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* MainWP Child Comment actions: approve, unapprove, spam, unspam, trash, restore, delete.
|
65 |
+
*/
|
66 |
+
public function comment_action() {
|
67 |
+
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
68 |
+
$commentId = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
|
69 |
+
|
70 |
+
if ( 'approve' === $action ) {
|
71 |
+
wp_set_comment_status( $commentId, 'approve' );
|
72 |
+
} elseif ( 'unapprove' === $action ) {
|
73 |
+
wp_set_comment_status( $commentId, 'hold' );
|
74 |
+
} elseif ( 'spam' === $action ) {
|
75 |
+
wp_spam_comment( $commentId );
|
76 |
+
} elseif ( 'unspam' === $action ) {
|
77 |
+
wp_unspam_comment( $commentId );
|
78 |
+
} elseif ( 'trash' === $action ) {
|
79 |
+
add_action( 'trashed_comment', array( MainWP_Child_Links_Checker::get_class_name(), 'hook_trashed_comment' ), 10, 1 );
|
80 |
+
wp_trash_comment( $commentId );
|
81 |
+
} elseif ( 'restore' === $action ) {
|
82 |
+
wp_untrash_comment( $commentId );
|
83 |
+
} elseif ( 'delete' === $action ) {
|
84 |
+
wp_delete_comment( $commentId, true );
|
85 |
+
} else {
|
86 |
+
$information['status'] = 'FAIL';
|
87 |
+
}
|
88 |
+
|
89 |
+
if ( ! isset( $information['status'] ) ) {
|
90 |
+
$information['status'] = 'SUCCESS';
|
91 |
+
}
|
92 |
+
MainWP_Helper::write( $information );
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* MainWP Child Bulk Comment actions: approve, unapprove, spam, unspam, trash, restore, delete.
|
97 |
+
*/
|
98 |
+
public function comment_bulk_action() {
|
99 |
+
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
100 |
+
$commentIds = isset( $_POST['ids'] ) ? explode( ',', sanitize_text_field( wp_unslash( $_POST['ids'] ) ) ) : array();
|
101 |
+
$information['success'] = 0;
|
102 |
+
foreach ( $commentIds as $commentId ) {
|
103 |
+
if ( $commentId ) {
|
104 |
+
$information['success'] ++;
|
105 |
+
if ( 'approve' === $action ) {
|
106 |
+
wp_set_comment_status( $commentId, 'approve' );
|
107 |
+
} elseif ( 'unapprove' === $action ) {
|
108 |
+
wp_set_comment_status( $commentId, 'hold' );
|
109 |
+
} elseif ( 'spam' === $action ) {
|
110 |
+
wp_spam_comment( $commentId );
|
111 |
+
} elseif ( 'unspam' === $action ) {
|
112 |
+
wp_unspam_comment( $commentId );
|
113 |
+
} elseif ( 'trash' === $action ) {
|
114 |
+
wp_trash_comment( $commentId );
|
115 |
+
} elseif ( 'restore' === $action ) {
|
116 |
+
wp_untrash_comment( $commentId );
|
117 |
+
} elseif ( 'delete' === $action ) {
|
118 |
+
wp_delete_comment( $commentId, true );
|
119 |
+
} else {
|
120 |
+
$information['success']--;
|
121 |
+
}
|
122 |
+
}
|
123 |
+
}
|
124 |
+
MainWP_Helper::write( $information );
|
125 |
+
}
|
126 |
+
|
127 |
+
/**
|
128 |
+
* Comment WHERE Clauses.
|
129 |
+
*
|
130 |
+
* @param array $clauses MySQL WHERE Clause.
|
131 |
+
*
|
132 |
+
* @return array $clauses, Array of MySQL WHERE Clauses.
|
133 |
+
*/
|
134 |
+
public function comments_clauses( $clauses ) {
|
135 |
+
if ( $this->comments_and_clauses ) {
|
136 |
+
$clauses['where'] .= ' ' . $this->comments_and_clauses;
|
137 |
+
}
|
138 |
+
|
139 |
+
return $clauses;
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Get all comments.
|
144 |
+
*/
|
145 |
+
public function get_all_comments() {
|
146 |
+
|
147 |
+
/**
|
148 |
+
* WordPress Database instance.
|
149 |
+
*
|
150 |
+
* @global object $wpdb
|
151 |
+
*/
|
152 |
+
global $wpdb;
|
153 |
+
|
154 |
+
add_filter( 'comments_clauses', array( &$this, 'comments_clauses' ) );
|
155 |
+
|
156 |
+
if ( isset( $_POST['postId'] ) ) {
|
157 |
+
$this->comments_and_clauses .= " AND $wpdb->comments.comment_post_ID = " . sanitize_text_field( wp_unslash( $_POST['postId'] ) );
|
158 |
+
} else {
|
159 |
+
if ( isset( $_POST['keyword'] ) ) {
|
160 |
+
$this->comments_and_clauses .= " AND $wpdb->comments.comment_content LIKE '%" . sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) . "%'";
|
161 |
+
}
|
162 |
+
if ( isset( $_POST['dtsstart'] ) && '' !== $_POST['dtsstart'] ) {
|
163 |
+
$this->comments_and_clauses .= " AND $wpdb->comments.comment_date > '" . sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) . "'";
|
164 |
+
}
|
165 |
+
if ( isset( $_POST['dtsstop'] ) && '' !== $_POST['dtsstop'] ) {
|
166 |
+
$this->comments_and_clauses .= " AND $wpdb->comments.comment_date < '" . sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) . "'";
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
$maxComments = 50;
|
171 |
+
if ( defined( 'MAINWP_CHILD_NR_OF_COMMENTS' ) ) {
|
172 |
+
$maxComments = MAINWP_CHILD_NR_OF_COMMENTS; // to compatible.
|
173 |
+
}
|
174 |
+
|
175 |
+
if ( isset( $_POST['maxRecords'] ) ) {
|
176 |
+
$maxComments = ! empty( $_POST['maxRecords'] ) ? intval( $_POST['maxRecords'] ) : 0;
|
177 |
+
}
|
178 |
+
|
179 |
+
if ( 0 === $maxComments ) {
|
180 |
+
$maxComments = 99999;
|
181 |
+
}
|
182 |
+
$status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
|
183 |
+
$rslt = $this->get_recent_comments( explode( ',', $status ), $maxComments );
|
184 |
+
$this->comments_and_clauses = '';
|
185 |
+
|
186 |
+
MainWP_Helper::write( $rslt );
|
187 |
+
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* Get recent comments.
|
191 |
+
*
|
192 |
+
* @param array $pAllowedStatuses An array containing allowed comment statuses.
|
193 |
+
* @param int $pCount Number of comments to return.
|
194 |
+
*
|
195 |
+
* @return array $allComments Array of all comments found.
|
196 |
+
*/
|
197 |
+
public function get_recent_comments( $pAllowedStatuses, $pCount ) {
|
198 |
+
if ( ! function_exists( '\get_comment_author_url' ) ) {
|
199 |
+
include_once WPINC . '/comment-template.php';
|
200 |
+
}
|
201 |
+
$allComments = array();
|
202 |
+
|
203 |
+
foreach ( $pAllowedStatuses as $status ) {
|
204 |
+
$params = array( 'status' => $status );
|
205 |
+
if ( 0 !== $pCount ) {
|
206 |
+
$params['number'] = $pCount;
|
207 |
+
}
|
208 |
+
$comments = get_comments( $params );
|
209 |
+
if ( is_array( $comments ) ) {
|
210 |
+
foreach ( $comments as $comment ) {
|
211 |
+
$post = get_post( $comment->comment_post_ID );
|
212 |
+
$outComment = array();
|
213 |
+
$outComment['id'] = $comment->comment_ID;
|
214 |
+
$outComment['status'] = wp_get_comment_status( $comment->comment_ID );
|
215 |
+
$outComment['author'] = $comment->comment_author;
|
216 |
+
$outComment['author_url'] = get_comment_author_url( $comment->comment_ID );
|
217 |
+
$outComment['author_ip'] = get_comment_author_IP( $comment->comment_ID );
|
218 |
+
$outComment['author_email'] = apply_filters( 'comment_email', $comment->comment_author_email );
|
219 |
+
$outComment['postId'] = $comment->comment_post_ID;
|
220 |
+
$outComment['postName'] = $post->post_title;
|
221 |
+
$outComment['comment_count'] = $post->comment_count;
|
222 |
+
$outComment['content'] = $comment->comment_content;
|
223 |
+
$outComment['dts'] = strtotime( $comment->comment_date_gmt );
|
224 |
+
$allComments[] = $outComment;
|
225 |
+
}
|
226 |
+
}
|
227 |
+
}
|
228 |
+
|
229 |
+
return $allComments;
|
230 |
+
}
|
231 |
+
}
|
class/class-mainwp-child-db.php
CHANGED
@@ -1,83 +1,182 @@
|
|
1 |
<?php
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
class MainWP_Child_DB {
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
public static function use_mysqli() {
|
6 |
-
|
7 |
-
if ( ! function_exists( 'mysqli_connect' ) ) {
|
8 |
return false;
|
9 |
}
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
global $wpdb;
|
12 |
|
13 |
-
return ( $wpdb->dbh instanceof mysqli );
|
14 |
}
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
if ( self::use_mysqli() ) {
|
18 |
-
return mysqli_query( $link, $query );
|
19 |
} else {
|
20 |
-
return mysql_query( $query, $link );
|
21 |
}
|
22 |
}
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
public static function fetch_array( $result ) {
|
25 |
if ( self::use_mysqli() ) {
|
26 |
-
return mysqli_fetch_array( $result, MYSQLI_ASSOC );
|
27 |
} else {
|
28 |
-
return mysql_fetch_array( $result, MYSQL_ASSOC );
|
29 |
}
|
30 |
}
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
public static function num_rows( $result ) {
|
33 |
if ( self::use_mysqli() ) {
|
34 |
-
return mysqli_num_rows( $result );
|
35 |
} else {
|
36 |
-
return mysql_num_rows( $result );
|
37 |
}
|
38 |
}
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
public static function connect( $host, $user, $pass ) {
|
41 |
if ( self::use_mysqli() ) {
|
42 |
-
return mysqli_connect( $host, $user, $pass );
|
43 |
} else {
|
44 |
-
return mysql_connect( $host, $user, $pass );
|
45 |
}
|
46 |
}
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
public static function select_db( $db ) {
|
49 |
if ( self::use_mysqli() ) {
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
51 |
global $wpdb;
|
52 |
|
53 |
-
return mysqli_select_db( $wpdb->dbh, $db );
|
54 |
} else {
|
55 |
-
return mysql_select_db( $db );
|
56 |
}
|
57 |
}
|
58 |
|
|
|
|
|
|
|
|
|
|
|
59 |
public static function error() {
|
60 |
if ( self::use_mysqli() ) {
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
62 |
global $wpdb;
|
63 |
|
64 |
-
return mysqli_error( $wpdb->dbh );
|
65 |
} else {
|
66 |
-
return mysql_error();
|
67 |
}
|
68 |
}
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
public static function real_escape_string( $value ) {
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
72 |
global $wpdb;
|
73 |
|
74 |
if ( self::use_mysqli() ) {
|
75 |
-
return mysqli_real_escape_string( $wpdb->dbh, $value );
|
76 |
} else {
|
77 |
-
return mysql_real_escape_string( $value, $wpdb->dbh );
|
78 |
}
|
79 |
}
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
public static function is_result( $result ) {
|
82 |
if ( self::use_mysqli() ) {
|
83 |
return ( $result instanceof mysqli_result );
|
@@ -86,13 +185,23 @@ class MainWP_Child_DB {
|
|
86 |
}
|
87 |
}
|
88 |
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
global $wpdb;
|
92 |
|
93 |
-
$rows =
|
94 |
$size = 0;
|
95 |
-
while ( $row =
|
96 |
$size += $row['Data_length'];
|
97 |
}
|
98 |
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child DB
|
4 |
+
*
|
5 |
+
* This file handles all of the Child Plugin's DB functions.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_DB
|
14 |
+
*
|
15 |
+
* Handles all of the Child Plugin's DB functions.
|
16 |
+
*/
|
17 |
class MainWP_Child_DB {
|
18 |
+
|
19 |
+
// phpcs:disable WordPress.DB.RestrictedFunctions, WordPress.DB.PreparedSQL.NotPrepared -- unprepared SQL ok, accessing the database directly to custom database functions.
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Support old & new versions of WordPress (3.9+).
|
23 |
+
*
|
24 |
+
* @return bool|object Instantiated object of \mysqli.
|
25 |
+
*/
|
26 |
public static function use_mysqli() {
|
27 |
+
if ( ! function_exists( '\mysqli_connect' ) ) {
|
|
|
28 |
return false;
|
29 |
}
|
30 |
|
31 |
+
/**
|
32 |
+
* WordPress Database instance.
|
33 |
+
*
|
34 |
+
* @global object $wpdb
|
35 |
+
*/
|
36 |
global $wpdb;
|
37 |
|
38 |
+
return ( $wpdb->dbh instanceof \mysqli );
|
39 |
}
|
40 |
|
41 |
+
/**
|
42 |
+
* Run a mysqli query & get a result.
|
43 |
+
*
|
44 |
+
* @param string $query An SQL query.
|
45 |
+
* @param string $link A link identifier.
|
46 |
+
*
|
47 |
+
* @return bool|\mysqli_result|resource For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries, mysqli_query()
|
48 |
+
* will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.
|
49 |
+
* Returns FALSE on failure.
|
50 |
+
*/
|
51 |
+
public static function to_query( $query, $link ) {
|
52 |
if ( self::use_mysqli() ) {
|
53 |
+
return \mysqli_query( $link, $query );
|
54 |
} else {
|
55 |
+
return \mysql_query( $query, $link );
|
56 |
}
|
57 |
}
|
58 |
|
59 |
+
/**
|
60 |
+
* Fetch an array.
|
61 |
+
*
|
62 |
+
* @param array $result A result set identifier.
|
63 |
+
*
|
64 |
+
* @return array|false|null Returns an array of strings that corresponds to the fetched row, or false if there are no more rows.
|
65 |
+
*/
|
66 |
public static function fetch_array( $result ) {
|
67 |
if ( self::use_mysqli() ) {
|
68 |
+
return \mysqli_fetch_array( $result, MYSQLI_ASSOC );
|
69 |
} else {
|
70 |
+
return \mysql_fetch_array( $result, MYSQL_ASSOC );
|
71 |
}
|
72 |
}
|
73 |
|
74 |
+
/**
|
75 |
+
* Count the number of rows.
|
76 |
+
*
|
77 |
+
* @param array $result A result set identifier returned.
|
78 |
+
*
|
79 |
+
* @return false|int Returns number of rows in the result set.
|
80 |
+
*/
|
81 |
public static function num_rows( $result ) {
|
82 |
if ( self::use_mysqli() ) {
|
83 |
+
return \mysqli_num_rows( $result );
|
84 |
} else {
|
85 |
+
return \mysql_num_rows( $result );
|
86 |
}
|
87 |
}
|
88 |
|
89 |
+
/**
|
90 |
+
* Connect to Child Site Database.
|
91 |
+
*
|
92 |
+
* @param string $host Can be either a host name or an IP address.
|
93 |
+
* @param string $user The MySQL user name.
|
94 |
+
* @param string $pass The MySQL user password.
|
95 |
+
*
|
96 |
+
* @return false|\mysqli|resource object which represents the connection to a MySQL Server or false if an error occurred.
|
97 |
+
*/
|
98 |
public static function connect( $host, $user, $pass ) {
|
99 |
if ( self::use_mysqli() ) {
|
100 |
+
return \mysqli_connect( $host, $user, $pass );
|
101 |
} else {
|
102 |
+
return \mysql_connect( $host, $user, $pass );
|
103 |
}
|
104 |
}
|
105 |
|
106 |
+
/**
|
107 |
+
* Select Child Site DB.
|
108 |
+
*
|
109 |
+
* @param string $db Database name.
|
110 |
+
*
|
111 |
+
* @return bool true on success or false on failure.
|
112 |
+
*/
|
113 |
public static function select_db( $db ) {
|
114 |
if ( self::use_mysqli() ) {
|
115 |
+
|
116 |
+
/**
|
117 |
+
* WordPress Database instance.
|
118 |
+
*
|
119 |
+
* @global object $wpdb
|
120 |
+
*/
|
121 |
global $wpdb;
|
122 |
|
123 |
+
return \mysqli_select_db( $wpdb->dbh, $db );
|
124 |
} else {
|
125 |
+
return \mysql_select_db( $db );
|
126 |
}
|
127 |
}
|
128 |
|
129 |
+
/**
|
130 |
+
* Get any mysqli errors.
|
131 |
+
*
|
132 |
+
* @return string the error text from the last MySQL function, or '' (empty string) if no error occurred.
|
133 |
+
*/
|
134 |
public static function error() {
|
135 |
if ( self::use_mysqli() ) {
|
136 |
+
|
137 |
+
/**
|
138 |
+
* WordPress Database instance.
|
139 |
+
*
|
140 |
+
* @global object $wpdb
|
141 |
+
*/
|
142 |
global $wpdb;
|
143 |
|
144 |
+
return \mysqli_error( $wpdb->dbh );
|
145 |
} else {
|
146 |
+
return \mysql_error();
|
147 |
}
|
148 |
}
|
149 |
|
150 |
+
/**
|
151 |
+
* Escape a given string.
|
152 |
+
*
|
153 |
+
* @param string $value The string to be escaped. Characters encoded are NUL (ASCII 0), \n, \r, \, ', ", and Control-Z.
|
154 |
+
*
|
155 |
+
* @return false|string the escaped string, or false on error.
|
156 |
+
*/
|
157 |
public static function real_escape_string( $value ) {
|
158 |
+
|
159 |
+
/**
|
160 |
+
* WordPress Database instance.
|
161 |
+
*
|
162 |
+
* @global object $wpdb
|
163 |
+
*/
|
164 |
global $wpdb;
|
165 |
|
166 |
if ( self::use_mysqli() ) {
|
167 |
+
return \mysqli_real_escape_string( $wpdb->dbh, $value );
|
168 |
} else {
|
169 |
+
return \mysql_real_escape_string( $value, $wpdb->dbh );
|
170 |
}
|
171 |
}
|
172 |
|
173 |
+
/**
|
174 |
+
* Check if $result is an Instantiated object of \mysqli.
|
175 |
+
*
|
176 |
+
* @param resource $result Instantiated object of \mysqli.
|
177 |
+
*
|
178 |
+
* @return resource|bool Instantiated object of \mysqli, true if var is a resource, false otherwise.
|
179 |
+
*/
|
180 |
public static function is_result( $result ) {
|
181 |
if ( self::use_mysqli() ) {
|
182 |
return ( $result instanceof mysqli_result );
|
185 |
}
|
186 |
}
|
187 |
|
188 |
+
/**
|
189 |
+
* Get the size of the DB.
|
190 |
+
*
|
191 |
+
* @return int|mixed Size of the DB or false on failure.
|
192 |
+
*/
|
193 |
+
public static function get_size() {
|
194 |
+
|
195 |
+
/**
|
196 |
+
* WordPress Database instance.
|
197 |
+
*
|
198 |
+
* @global object $wpdb
|
199 |
+
*/
|
200 |
global $wpdb;
|
201 |
|
202 |
+
$rows = self::to_query( 'SHOW table STATUS', $wpdb->dbh );
|
203 |
$size = 0;
|
204 |
+
while ( $row = self::fetch_array( $rows ) ) {
|
205 |
$size += $row['Data_length'];
|
206 |
}
|
207 |
|
class/class-mainwp-child-install.php
ADDED
@@ -0,0 +1,485 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Install
|
4 |
+
*
|
5 |
+
* This file handles Plugins and Themes Activate, Deactivate and Delete process.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_Install
|
14 |
+
*
|
15 |
+
* Handles Plugins and Themes Activate, Deactivate and Delete process.
|
16 |
+
*/
|
17 |
+
class MainWP_Child_Install {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Public static variable to hold the single instance of MainWP_Child_Install.
|
21 |
+
*
|
22 |
+
* @var mixed Default null
|
23 |
+
*/
|
24 |
+
protected static $instance = null;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Get class name.
|
28 |
+
*
|
29 |
+
* @return string __CLASS__ Class name.
|
30 |
+
*/
|
31 |
+
public static function get_class_name() {
|
32 |
+
return __CLASS__;
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* MainWP_Child_Install constructor
|
37 |
+
*
|
38 |
+
* Run any time class is called.
|
39 |
+
*/
|
40 |
+
public function __construct() {
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Create a public static instance of MainWP_Child_Install.
|
45 |
+
*
|
46 |
+
* @return MainWP_Child_Install|mixed|null
|
47 |
+
*/
|
48 |
+
public static function get_instance() {
|
49 |
+
if ( null === self::$instance ) {
|
50 |
+
self::$instance = new self();
|
51 |
+
}
|
52 |
+
|
53 |
+
return self::$instance;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Method plugin_action()
|
58 |
+
*
|
59 |
+
* Plugin Activate, Deactivate & Delete actions.
|
60 |
+
*
|
61 |
+
* @uses get_plugin_data() Parses the plugin contents to retrieve plugin’s metadata.
|
62 |
+
* @see https://developer.wordpress.org/reference/functions/get_plugin_data/
|
63 |
+
*
|
64 |
+
* @uses activate_plugin() Attempts activation of plugin in a “sandbox” and redirects on success.
|
65 |
+
* @see https://developer.wordpress.org/reference/functions/activate_plugin/
|
66 |
+
*
|
67 |
+
* @uses deactivate_plugin() Deactivate a single plugin or multiple plugins.
|
68 |
+
* @see https://developer.wordpress.org/reference/functions/deactivate_plugin/
|
69 |
+
*
|
70 |
+
* @uses MainWP_Child_Install::delete_plugins() Delete a plugin from the Child Site.
|
71 |
+
*/
|
72 |
+
public function plugin_action() {
|
73 |
+
|
74 |
+
/**
|
75 |
+
* MainWP Child instance.
|
76 |
+
*
|
77 |
+
* @global object
|
78 |
+
*/
|
79 |
+
global $mainWPChild;
|
80 |
+
|
81 |
+
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
82 |
+
$plugins = isset( $_POST['plugin'] ) ? explode( '||', wp_unslash( $_POST['plugin'] ) ) : '';
|
83 |
+
|
84 |
+
if ( 'activate' === $action ) {
|
85 |
+
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
86 |
+
|
87 |
+
foreach ( $plugins as $idx => $plugin ) {
|
88 |
+
if ( $plugin !== $mainWPChild->plugin_slug ) {
|
89 |
+
$thePlugin = get_plugin_data( $plugin );
|
90 |
+
if ( null !== $thePlugin && '' !== $thePlugin ) {
|
91 |
+
if ( 'quotes-collection/quotes-collection.php' == $plugin ) {
|
92 |
+
activate_plugin( $plugin, '', false, true );
|
93 |
+
} else {
|
94 |
+
activate_plugin( $plugin );
|
95 |
+
}
|
96 |
+
}
|
97 |
+
}
|
98 |
+
}
|
99 |
+
} elseif ( 'deactivate' === $action ) {
|
100 |
+
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
101 |
+
|
102 |
+
foreach ( $plugins as $idx => $plugin ) {
|
103 |
+
if ( $plugin !== $mainWPChild->plugin_slug ) {
|
104 |
+
$thePlugin = get_plugin_data( $plugin );
|
105 |
+
if ( null !== $thePlugin && '' !== $thePlugin ) {
|
106 |
+
deactivate_plugins( $plugin );
|
107 |
+
}
|
108 |
+
}
|
109 |
+
}
|
110 |
+
} elseif ( 'delete' === $action ) {
|
111 |
+
$this->delete_plugins( $plugins );
|
112 |
+
} else {
|
113 |
+
$information['status'] = 'FAIL';
|
114 |
+
}
|
115 |
+
|
116 |
+
if ( ! isset( $information['status'] ) ) {
|
117 |
+
$information['status'] = 'SUCCESS';
|
118 |
+
}
|
119 |
+
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
|
120 |
+
MainWP_Helper::write( $information );
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Method delete_plugins()
|
125 |
+
*
|
126 |
+
* Delete a plugin from the Child Site.
|
127 |
+
*
|
128 |
+
* @param array $plugins An array of plugins to delete.
|
129 |
+
*
|
130 |
+
* @uses get_plugin_data() Parses the plugin contents to retrieve plugin’s metadata.
|
131 |
+
* @see https://developer.wordpress.org/reference/functions/get_plugin_data/
|
132 |
+
*
|
133 |
+
* @uses deactivate_plugin() Deactivate a single plugin or multiple plugins.
|
134 |
+
* @see https://developer.wordpress.org/reference/functions/deactivate_plugin/
|
135 |
+
*
|
136 |
+
* @uses is_plugin_active() Determines whether a plugin is active.
|
137 |
+
* @see https://developer.wordpress.org/reference/functions/is_plugin_active/
|
138 |
+
*
|
139 |
+
* @used-by MainWP_Child_Install::plugin_action() Plugin Activate, Deactivate & Delete actions.
|
140 |
+
*/
|
141 |
+
private function delete_plugins( $plugins ) {
|
142 |
+
|
143 |
+
/**
|
144 |
+
* MainWP Child instance.
|
145 |
+
*
|
146 |
+
* @global object
|
147 |
+
*/
|
148 |
+
global $mainWPChild;
|
149 |
+
|
150 |
+
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
151 |
+
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
|
152 |
+
include_once ABSPATH . '/wp-admin/includes/screen.php';
|
153 |
+
}
|
154 |
+
include_once ABSPATH . '/wp-admin/includes/file.php';
|
155 |
+
include_once ABSPATH . '/wp-admin/includes/template.php';
|
156 |
+
include_once ABSPATH . '/wp-admin/includes/misc.php';
|
157 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
|
158 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php';
|
159 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php';
|
160 |
+
|
161 |
+
MainWP_Helper::check_wp_filesystem();
|
162 |
+
|
163 |
+
$pluginUpgrader = new \Plugin_Upgrader();
|
164 |
+
|
165 |
+
$all_plugins = get_plugins();
|
166 |
+
foreach ( $plugins as $idx => $plugin ) {
|
167 |
+
if ( $plugin !== $mainWPChild->plugin_slug ) {
|
168 |
+
if ( isset( $all_plugins[ $plugin ] ) ) {
|
169 |
+
if ( is_plugin_active( $plugin ) ) {
|
170 |
+
$thePlugin = get_plugin_data( $plugin );
|
171 |
+
if ( null !== $thePlugin && '' !== $thePlugin ) {
|
172 |
+
deactivate_plugins( $plugin );
|
173 |
+
}
|
174 |
+
}
|
175 |
+
$tmp['plugin'] = $plugin;
|
176 |
+
if ( true === $pluginUpgrader->delete_old_plugin( null, null, null, $tmp ) ) {
|
177 |
+
$args = array(
|
178 |
+
'action' => 'delete',
|
179 |
+
'Name' => $all_plugins[ $plugin ]['Name'],
|
180 |
+
);
|
181 |
+
do_action( 'mainwp_child_plugin_action', $args );
|
182 |
+
}
|
183 |
+
}
|
184 |
+
}
|
185 |
+
}
|
186 |
+
}
|
187 |
+
|
188 |
+
/**
|
189 |
+
* Method theme_action()
|
190 |
+
*
|
191 |
+
* Theme Activate, Deactivate & Delete actions.
|
192 |
+
*
|
193 |
+
* @uses wp_get_theme() Gets a WP_Theme object for a theme.
|
194 |
+
* @see https://developer.wordpress.org/reference/functions/wp_get_theme/
|
195 |
+
*
|
196 |
+
* @uses switch_theme() Switches the theme.
|
197 |
+
* @see https://developer.wordpress.org/reference/functions/switch_theme/
|
198 |
+
*/
|
199 |
+
public function theme_action() {
|
200 |
+
|
201 |
+
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
202 |
+
$theme = isset( $_POST['theme'] ) ? wp_unslash( $_POST['theme'] ) : '';
|
203 |
+
|
204 |
+
if ( 'activate' === $action ) {
|
205 |
+
include_once ABSPATH . '/wp-admin/includes/theme.php';
|
206 |
+
$theTheme = wp_get_theme( $theme );
|
207 |
+
if ( null !== $theTheme && '' !== $theTheme ) {
|
208 |
+
switch_theme( $theTheme['Template'], $theTheme['Stylesheet'] );
|
209 |
+
}
|
210 |
+
} elseif ( 'delete' === $action ) {
|
211 |
+
include_once ABSPATH . '/wp-admin/includes/theme.php';
|
212 |
+
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
|
213 |
+
include_once ABSPATH . '/wp-admin/includes/screen.php';
|
214 |
+
}
|
215 |
+
include_once ABSPATH . '/wp-admin/includes/file.php';
|
216 |
+
include_once ABSPATH . '/wp-admin/includes/template.php';
|
217 |
+
include_once ABSPATH . '/wp-admin/includes/misc.php';
|
218 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
|
219 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php';
|
220 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php';
|
221 |
+
|
222 |
+
MainWP_Helper::check_wp_filesystem();
|
223 |
+
|
224 |
+
$themeUpgrader = new \Theme_Upgrader();
|
225 |
+
|
226 |
+
$theme_name = wp_get_theme()->get_stylesheet();
|
227 |
+
$parent = wp_get_theme()->parent();
|
228 |
+
$parent_name = $parent ? $parent->get_stylesheet() : '';
|
229 |
+
|
230 |
+
$themes = explode( '||', $theme );
|
231 |
+
|
232 |
+
$themes = array_filter( $themes );
|
233 |
+
|
234 |
+
if ( count( $themes ) == 1 ) {
|
235 |
+
$themeToDelete = current( $themes );
|
236 |
+
if ( $themeToDelete == $theme_name ) {
|
237 |
+
$information['error']['is_activated_theme'] = $themeToDelete;
|
238 |
+
MainWP_Helper::write( $information );
|
239 |
+
return;
|
240 |
+
} elseif ( $themeToDelete == $parent_name ) {
|
241 |
+
$information['error']['is_activated_parent'] = $themeToDelete;
|
242 |
+
MainWP_Helper::write( $information );
|
243 |
+
return;
|
244 |
+
}
|
245 |
+
}
|
246 |
+
|
247 |
+
foreach ( $themes as $idx => $themeToDelete ) {
|
248 |
+
if ( $themeToDelete == $theme_name ) {
|
249 |
+
$information['error']['is_activated_theme'] = $themeToDelete;
|
250 |
+
} elseif ( $themeToDelete == $parent_name ) {
|
251 |
+
$information['error']['is_activated_parent'] = $themeToDelete;
|
252 |
+
}
|
253 |
+
if ( $themeToDelete !== $theme_name && $themeToDelete !== $parent_name ) {
|
254 |
+
$theTheme = wp_get_theme( $themeToDelete );
|
255 |
+
if ( null !== $theTheme && '' !== $theTheme ) {
|
256 |
+
$tmp['theme'] = $theTheme['Template'];
|
257 |
+
if ( true === $themeUpgrader->delete_old_theme( null, null, null, $tmp ) ) {
|
258 |
+
$args = array(
|
259 |
+
'action' => 'delete',
|
260 |
+
'Name' => $theTheme['Name'],
|
261 |
+
);
|
262 |
+
do_action( 'mainwp_child_theme_action', $args );
|
263 |
+
}
|
264 |
+
}
|
265 |
+
}
|
266 |
+
}
|
267 |
+
} else {
|
268 |
+
$information['status'] = 'FAIL';
|
269 |
+
}
|
270 |
+
|
271 |
+
if ( ! isset( $information['status'] ) ) {
|
272 |
+
$information['status'] = 'SUCCESS';
|
273 |
+
}
|
274 |
+
|
275 |
+
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
|
276 |
+
MainWP_Helper::write( $information );
|
277 |
+
}
|
278 |
+
|
279 |
+
/**
|
280 |
+
* Method install_plugin_theme()
|
281 |
+
*
|
282 |
+
* Plugin & Theme Installation functions.
|
283 |
+
*
|
284 |
+
* @uses MainWP_Child_Install::require_files() Include necessary files.
|
285 |
+
* @uses MainWP_Child_Install::after_installed() After plugin or theme has been installed.
|
286 |
+
* @uses MainWP_Child_Install::no_ssl_filter_function() Hook to set ssl verify value.
|
287 |
+
* @uses MainWP_Child_Install::try_second_install() Alternative installation method.
|
288 |
+
*/
|
289 |
+
public function install_plugin_theme() {
|
290 |
+
|
291 |
+
MainWP_Helper::check_wp_filesystem();
|
292 |
+
|
293 |
+
if ( ! isset( $_POST['type'] ) || ! isset( $_POST['url'] ) || ( 'plugin' !== $_POST['type'] && 'theme' !== $_POST['type'] ) || '' === $_POST['url'] ) {
|
294 |
+
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
|
295 |
+
}
|
296 |
+
|
297 |
+
$this->require_files();
|
298 |
+
|
299 |
+
$urlgot = isset( $_POST['url'] ) ? json_decode( stripslashes( wp_unslash( $_POST['url'] ) ) ) : '';
|
300 |
+
|
301 |
+
$urls = array();
|
302 |
+
if ( ! is_array( $urlgot ) ) {
|
303 |
+
$urls[] = $urlgot;
|
304 |
+
} else {
|
305 |
+
$urls = $urlgot;
|
306 |
+
}
|
307 |
+
|
308 |
+
$install_results = array();
|
309 |
+
$result = array();
|
310 |
+
foreach ( $urls as $url ) {
|
311 |
+
$installer = new \WP_Upgrader();
|
312 |
+
$ssl_verify = true;
|
313 |
+
// @see wp-admin/includes/class-wp-upgrader.php
|
314 |
+
if ( isset( $_POST['sslVerify'] ) && '0' === $_POST['sslVerify'] ) {
|
315 |
+
add_filter( 'http_request_args', array( self::get_class_name(), 'no_ssl_filter_function' ), 99, 2 );
|
316 |
+
$ssl_verify = false;
|
317 |
+
}
|
318 |
+
add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 );
|
319 |
+
|
320 |
+
$result = $installer->run(
|
321 |
+
array(
|
322 |
+
'package' => $url,
|
323 |
+
'destination' => ( isset( $_POST['type'] ) && 'plugin' === $_POST['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ),
|
324 |
+
'clear_destination' => ( isset( $_POST['overwrite'] ) && sanitize_text_field( wp_unslash( $_POST['overwrite'] ) ) ),
|
325 |
+
'clear_working' => true,
|
326 |
+
'hook_extra' => array(),
|
327 |
+
)
|
328 |
+
);
|
329 |
+
|
330 |
+
if ( is_wp_error( $result ) ) {
|
331 |
+
if ( true == $ssl_verify && strpos( $url, 'https://' ) === 0 ) {
|
332 |
+
$ssl_verify = false;
|
333 |
+
$result = $this->try_second_install( $url, $installer );
|
334 |
+
}
|
335 |
+
}
|
336 |
+
|
337 |
+
remove_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 );
|
338 |
+
if ( false == $ssl_verify ) {
|
339 |
+
remove_filter( 'http_request_args', array( self::get_class_name(), 'no_ssl_filter_function' ), 99 );
|
340 |
+
}
|
341 |
+
$this->after_installed( $result );
|
342 |
+
$basename = basename( rawurldecode( $url ) );
|
343 |
+
$install_results[ $basename ] = is_array( $result ) && isset( $result['destination_name'] ) ? true : false;
|
344 |
+
}
|
345 |
+
|
346 |
+
$information['installation'] = 'SUCCESS';
|
347 |
+
$information['destination_name'] = $result['destination_name'];
|
348 |
+
$information['install_results'] = $install_results;
|
349 |
+
MainWP_Helper::write( $information );
|
350 |
+
}
|
351 |
+
|
352 |
+
/**
|
353 |
+
* Method no_ssl_filter_function()
|
354 |
+
*
|
355 |
+
* Hook to set ssl verify value.
|
356 |
+
*
|
357 |
+
* @param array $r Request's array values.
|
358 |
+
* @param string $url URL request.
|
359 |
+
*
|
360 |
+
* @used-by install_plugin_theme() Plugin & Theme Installation functions.
|
361 |
+
*
|
362 |
+
* @return array $r Request's array values.
|
363 |
+
*/
|
364 |
+
public static function no_ssl_filter_function( $r, $url ) {
|
365 |
+
$r['sslverify'] = false;
|
366 |
+
return $r;
|
367 |
+
}
|
368 |
+
|
369 |
+
/**
|
370 |
+
* Method require_files()
|
371 |
+
*
|
372 |
+
* Include necessary files.
|
373 |
+
*
|
374 |
+
* @used-by install_plugin_theme() Plugin & Theme Installation functions.
|
375 |
+
*/
|
376 |
+
private function require_files() {
|
377 |
+
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
|
378 |
+
include_once ABSPATH . '/wp-admin/includes/screen.php';
|
379 |
+
}
|
380 |
+
include_once ABSPATH . '/wp-admin/includes/template.php';
|
381 |
+
include_once ABSPATH . '/wp-admin/includes/misc.php';
|
382 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
|
383 |
+
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
384 |
+
}
|
385 |
+
|
386 |
+
/**
|
387 |
+
* Method after_installed()
|
388 |
+
*
|
389 |
+
* After plugin or theme has been installed.
|
390 |
+
*
|
391 |
+
* @param array $result Results array from self::install_plugin_theme().
|
392 |
+
*
|
393 |
+
* @uses wp_cache_set() Saves the data to the cache.
|
394 |
+
* @see https://developer.wordpress.org/reference/functions/wp_cache_set/
|
395 |
+
*
|
396 |
+
* @uses activate_plugin() Attempts activation of plugin in a “sandbox” and redirects on success.
|
397 |
+
* @see https://developer.wordpress.org/reference/functions/activate_plugin/
|
398 |
+
*
|
399 |
+
* @uses get_plugin_data() Parses the plugin contents to retrieve plugin’s metadata.
|
400 |
+
* @see https://developer.wordpress.org/reference/functions/get_plugin_data/
|
401 |
+
*
|
402 |
+
* @used-by install_plugin_theme() Plugin & Theme Installation functions.
|
403 |
+
*/
|
404 |
+
private function after_installed( $result ) {
|
405 |
+
$args = array(
|
406 |
+
'success' => 1,
|
407 |
+
'action' => 'install',
|
408 |
+
);
|
409 |
+
if ( isset( $_POST['type'] ) && 'plugin' === $_POST['type'] ) {
|
410 |
+
$path = $result['destination'];
|
411 |
+
$fileName = '';
|
412 |
+
wp_cache_set( 'plugins', array(), 'plugins' );
|
413 |
+
foreach ( $result['source_files'] as $srcFile ) {
|
414 |
+
if ( is_dir( $path . $srcFile ) ) {
|
415 |
+
continue;
|
416 |
+
}
|
417 |
+
$thePlugin = get_plugin_data( $path . $srcFile );
|
418 |
+
if ( null !== $thePlugin && '' !== $thePlugin && '' !== $thePlugin['Name'] ) {
|
419 |
+
$args['type'] = 'plugin';
|
420 |
+
$args['Name'] = $thePlugin['Name'];
|
421 |
+
$args['Version'] = $thePlugin['Version'];
|
422 |
+
$args['slug'] = $result['destination_name'] . '/' . $srcFile;
|
423 |
+
$fileName = $srcFile;
|
424 |
+
break;
|
425 |
+
}
|
426 |
+
}
|
427 |
+
|
428 |
+
if ( ! empty( $fileName ) ) {
|
429 |
+
do_action_deprecated( 'mainwp_child_installPluginTheme', array( $args ), '4.0.7.1', 'mainwp_child_install_plugin_theme' );
|
430 |
+
do_action( 'mainwp_child_install_plugin_theme', $args );
|
431 |
+
|
432 |
+
if ( isset( $_POST['activatePlugin'] ) && 'yes' === $_POST['activatePlugin'] ) {
|
433 |
+
// to fix activate issue.
|
434 |
+
if ( 'quotes-collection/quotes-collection.php' == $args['slug'] ) {
|
435 |
+
activate_plugin( $path . $fileName, '', false, true );
|
436 |
+
} else {
|
437 |
+
activate_plugin( $path . $fileName, '' );
|
438 |
+
}
|
439 |
+
}
|
440 |
+
}
|
441 |
+
} else {
|
442 |
+
$args['type'] = 'theme';
|
443 |
+
$args['slug'] = $result['destination_name'];
|
444 |
+
do_action_deprecated( 'mainwp_child_installPluginTheme', array( $args ), '4.0.7.1', 'mainwp_child_install_plugin_theme' );
|
445 |
+
do_action( 'mainwp_child_install_plugin_theme', $args );
|
446 |
+
}
|
447 |
+
}
|
448 |
+
|
449 |
+
/**
|
450 |
+
* Method try_second_install()
|
451 |
+
*
|
452 |
+
* Alternative installation method.
|
453 |
+
*
|
454 |
+
* @param string $url Package URL.
|
455 |
+
* @param object $installer Instance of \WP_Upgrader.
|
456 |
+
*
|
457 |
+
* @uses is_wp_error() Check whether variable is a WordPress Error.
|
458 |
+
* @see https://developer.wordpress.org/reference/functions/is_wp_error/
|
459 |
+
*
|
460 |
+
* @used-by install_plugin_theme() Plugin & Theme Installation functions.
|
461 |
+
*
|
462 |
+
* @return object $result Return error messages or TRUE.
|
463 |
+
*/
|
464 |
+
private function try_second_install( $url, $installer ) {
|
465 |
+
$result = $installer->run(
|
466 |
+
array(
|
467 |
+
'package' => $url,
|
468 |
+
'destination' => ( isset( $_POST['type'] ) && 'plugin' === $_POST['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ),
|
469 |
+
'clear_destination' => ( isset( $_POST['overwrite'] ) && sanitize_text_field( wp_unslash( $_POST['overwrite'] ) ) ),
|
470 |
+
'clear_working' => true,
|
471 |
+
'hook_extra' => array(),
|
472 |
+
)
|
473 |
+
);
|
474 |
+
if ( is_wp_error( $result ) ) {
|
475 |
+
$err_code = $result->get_error_code();
|
476 |
+
if ( $result->get_error_data() && is_string( $result->get_error_data() ) ) {
|
477 |
+
$error = $result->get_error_data();
|
478 |
+
MainWP_Helper::error( $error, $err_code );
|
479 |
+
} else {
|
480 |
+
MainWP_Helper::error( implode( ', ', $error ), $err_code );
|
481 |
+
}
|
482 |
+
}
|
483 |
+
return $result;
|
484 |
+
}
|
485 |
+
}
|
class/class-mainwp-child-ithemes-security.php
CHANGED
@@ -1,6 +1,11 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
4 |
*
|
5 |
* Credits
|
6 |
*
|
@@ -12,60 +17,118 @@
|
|
12 |
*
|
13 |
* The code is used for the MainWP iThemes Security Extension
|
14 |
* Extension URL: https://mainwp.com/extension/ithemes-security/
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
public $is_plugin_installed = false;
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
}
|
26 |
-
|
27 |
-
return MainWP_Child_iThemes_Security::$instance;
|
28 |
}
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
}
|
35 |
|
36 |
-
|
37 |
-
|
|
|
38 |
|
39 |
-
add_filter( '
|
40 |
}
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
if ( is_array( $data ) && isset( $data['ithemeExtActivated'] ) && ( 'yes' === $data['ithemeExtActivated'] ) ) {
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
}
|
52 |
return $information;
|
53 |
}
|
54 |
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
$information = array();
|
57 |
-
if ( ! class_exists( 'ITSEC_Core' ) || !class_exists('ITSEC_Modules')) {
|
58 |
$information['error'] = 'NO_ITHEME';
|
59 |
MainWP_Helper::write( $information );
|
60 |
}
|
61 |
|
|
|
62 |
global $mainwp_itsec_modules_path;
|
63 |
|
64 |
-
$mainwp_itsec_modules_path = ITSEC_Core::get_core_dir() . '/modules/';
|
65 |
-
|
66 |
|
67 |
if ( isset( $_POST['mwp_action'] ) ) {
|
68 |
-
|
|
|
69 |
case 'set_showhide':
|
70 |
$information = $this->set_showhide();
|
71 |
break;
|
@@ -122,7 +185,14 @@ class MainWP_Child_iThemes_Security {
|
|
122 |
MainWP_Helper::write( $information );
|
123 |
}
|
124 |
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
127 |
MainWP_Helper::update_option( 'mainwp_ithemes_hide_plugin', $hide );
|
128 |
$information['result'] = 'success';
|
@@ -130,27 +200,43 @@ class MainWP_Child_iThemes_Security {
|
|
130 |
return $information;
|
131 |
}
|
132 |
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
135 |
return;
|
|
|
136 |
|
137 |
-
if ( get_option( 'mainwp_ithemes_hide_plugin' )
|
138 |
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
139 |
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
140 |
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
141 |
add_action( 'admin_head', array( &$this, 'custom_admin_css' ) );
|
142 |
-
if ( isset($_GET['page']) && ($_GET['page']
|
143 |
-
|
144 |
exit();
|
145 |
}
|
146 |
}
|
147 |
}
|
148 |
|
149 |
-
|
|
|
|
|
|
|
150 |
remove_meta_box( 'itsec-dashboard-widget', 'dashboard', 'normal' );
|
151 |
}
|
152 |
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
foreach ( $plugins as $key => $value ) {
|
155 |
$plugin_slug = basename( $key, '.php' );
|
156 |
if ( 'better-wp-security' === $plugin_slug || 'ithemes-security-pro' === $plugin_slug ) {
|
@@ -161,11 +247,17 @@ class MainWP_Child_iThemes_Security {
|
|
161 |
return $plugins;
|
162 |
}
|
163 |
|
164 |
-
|
|
|
|
|
|
|
165 |
remove_menu_page( 'itsec' );
|
166 |
}
|
167 |
|
168 |
-
|
|
|
|
|
|
|
169 |
?>
|
170 |
<style type="text/css">
|
171 |
#wp-admin-bar-itsec_admin_bar_menu{
|
@@ -175,10 +267,27 @@ class MainWP_Child_iThemes_Security {
|
|
175 |
<?php
|
176 |
}
|
177 |
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
}
|
183 |
|
184 |
$_itsec_modules = array(
|
@@ -193,245 +302,288 @@ class MainWP_Child_iThemes_Security {
|
|
193 |
'404-detection',
|
194 |
'network-brute-force',
|
195 |
'ssl',
|
196 |
-
|
197 |
-
'password-requirements',
|
198 |
'system-tweaks',
|
199 |
'wordpress-tweaks',
|
200 |
'multisite-tweaks',
|
201 |
-
|
202 |
-
//'salts',
|
203 |
-
//'content-directory',
|
204 |
);
|
205 |
|
206 |
$require_permalinks = false;
|
207 |
-
$updated
|
208 |
-
$errors
|
209 |
-
$nbf_settings
|
210 |
|
211 |
-
$update_settings
|
212 |
|
213 |
-
foreach($update_settings as $module => $settings) {
|
214 |
$do_not_save = false;
|
215 |
-
if (in_array($module, $_itsec_modules)) {
|
216 |
-
if (
|
217 |
-
$settings['last_generated'] = ITSEC_Modules::get_setting( $module, 'last_generated' );
|
218 |
-
}
|
219 |
-
$keep_olds = array( 'did_upgrade', 'log_info', 'show_new_dashboard_notice', 'show_security_check'
|
220 |
-
foreach($keep_olds as $key) {
|
221 |
-
$settings[$key] = ITSEC_Modules::get_setting( $module, $key );
|
222 |
}
|
223 |
|
224 |
-
if (!isset($settings['log_location']) || empty($settings['log_location']) ) {
|
225 |
-
$settings['log_location'] = ITSEC_Modules::get_setting( $module, 'log_location' );
|
226 |
} else {
|
227 |
-
$result = $this->validate_directory('log_location', $settings['log_location']);
|
228 |
-
if ($result
|
229 |
-
$errors[]
|
230 |
-
$settings['log_location'] = ITSEC_Modules::get_setting( $module, 'log_location' );
|
231 |
}
|
232 |
}
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
$settings['location'] = ITSEC_Modules::get_setting( $module, 'location' );
|
237 |
} else {
|
238 |
-
$result = $this->validate_directory('location', $settings['location']);
|
239 |
-
if ($result
|
240 |
-
$errors[]
|
241 |
-
$settings['location'] = ITSEC_Modules::get_setting( $module, 'location' );
|
242 |
}
|
243 |
}
|
244 |
-
if (!isset($settings['exclude']) ) {
|
245 |
-
$settings['exclude'] = ITSEC_Modules::get_setting( $module, 'exclude' )
|
|
|
246 |
}
|
247 |
-
}
|
248 |
-
if (isset($settings['enabled']) && !empty($settings['enabled'])) {
|
249 |
$permalink_structure = get_option( 'permalink_structure', false );
|
250 |
if ( empty( $permalink_structure ) && ! is_multisite() ) {
|
251 |
-
$errors[]
|
252 |
$require_permalinks = true;
|
253 |
-
$do_not_save
|
254 |
}
|
255 |
}
|
256 |
-
}
|
257 |
|
258 |
if ( isset( $settings['email'] ) ) {
|
259 |
-
$result = $this->activate_api_key($settings);
|
260 |
-
if ($result
|
261 |
$nbf_settings = $settings;
|
262 |
-
$errors[]
|
263 |
} else {
|
264 |
$nbf_settings = $result;
|
265 |
}
|
266 |
} else {
|
267 |
-
$previous_settings = ITSEC_Modules::get_settings( $module );
|
268 |
-
|
269 |
-
if (isset($settings['enable_ban'])) {
|
270 |
$previous_settings['enable_ban'] = $settings['enable_ban'];
|
271 |
-
$nbf_settings
|
272 |
} else {
|
273 |
-
$do_not_save
|
274 |
$nbf_settings = $previous_settings;
|
275 |
}
|
276 |
}
|
277 |
$settings = $nbf_settings;
|
278 |
-
}
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
if (
|
299 |
-
ITSEC_Modules::set_settings( $module, $settings );
|
300 |
-
$updated
|
301 |
}
|
302 |
}
|
303 |
}
|
304 |
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
|
313 |
-
require_once
|
314 |
|
315 |
$values = array(
|
316 |
'permalink_structure' => get_option( 'permalink_structure' ),
|
317 |
'is_multisite' => is_multisite() ? 1 : 0,
|
318 |
'users_can_register' => get_site_option( 'users_can_register' ) ? 1 : 0,
|
319 |
-
'server_nginx' => ( ITSEC_Lib::get_server() === 'nginx' ) ? 1 : 0,
|
320 |
-
'has_ssl'
|
321 |
-
'jquery_version'
|
322 |
-
'server_rules'
|
323 |
-
'config_rules'
|
324 |
'lockouts_host' => $this->get_lockouts( 'host', true ),
|
325 |
'lockouts_user' => $this->get_lockouts( 'user', true ),
|
326 |
'lockouts_username' => $this->get_lockouts( 'username', true ),
|
327 |
-
'default_log_location'
|
328 |
-
'default_location'
|
329 |
-
'excludable_tables'
|
330 |
-
|
331 |
);
|
332 |
|
333 |
-
|
334 |
-
'site_status' => $values
|
335 |
);
|
336 |
|
337 |
-
if ($require_permalinks) {
|
338 |
$return['require_permalinks'] = 1;
|
339 |
}
|
340 |
|
341 |
$return['nbf_settings'] = $nbf_settings;
|
342 |
|
343 |
-
if (!empty($errors)) {
|
344 |
$return['extra_message'] = $errors;
|
345 |
}
|
346 |
|
347 |
-
if ($updated)
|
348 |
$return['result'] = 'success';
|
349 |
-
else
|
350 |
-
$return['error'] = __('Not Updated', 'mainwp-child' );
|
|
|
351 |
|
352 |
return $return;
|
353 |
}
|
354 |
|
355 |
-
|
356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
$information = array();
|
358 |
-
if (is_array($data)) {
|
359 |
-
$settings
|
360 |
-
$settings['email']
|
361 |
$settings['updates_optin'] = $data['updates_optin'];
|
362 |
-
$settings['api_nag']
|
363 |
-
$results
|
364 |
if ( is_wp_error( $results ) ) {
|
365 |
$information['error'] = 'Error: Active iThemes Network Brute Force Protection Api Key';
|
366 |
-
}
|
367 |
-
ITSEC_Modules::activate( 'network-brute-force' );
|
368 |
-
$nbf_settings = ITSEC_Modules::get_settings( 'network-brute-force' );
|
369 |
-
// ITSEC_Response::set_response( '<p>' . __( 'Your site is now using Network Brute Force Protection.', 'better-wp-security' ) . '</p>' );
|
370 |
}
|
371 |
}
|
372 |
-
if ($nbf_settings
|
373 |
$information['nbf_settings'] = $nbf_settings;
|
374 |
-
$information['result']
|
375 |
}
|
376 |
return $information;
|
377 |
}
|
378 |
|
379 |
-
|
380 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
$error = null;
|
382 |
-
if ( ! ITSEC_Lib_Directory::is_dir( $folder ) ) {
|
383 |
-
$result = ITSEC_Lib_Directory::create( $folder );
|
384 |
|
385 |
if ( is_wp_error( $result ) ) {
|
386 |
-
$error = sprintf( _x( 'The directory supplied in %1$s cannot be used as a valid directory. %2$s', '%1$s is the input name. %2$s is the error message.', '
|
387 |
}
|
388 |
}
|
389 |
|
390 |
-
if ( empty( $error ) && ! ITSEC_Lib_Directory::is_writable( $folder ) ) {
|
391 |
-
$error = sprintf( __( 'The directory supplied in %1$s is not writable. Please select a directory that can be written to.', '
|
392 |
}
|
393 |
|
394 |
if ( empty( $error ) ) {
|
395 |
-
ITSEC_Lib_Directory::add_file_listing_protection( $folder );
|
396 |
return true;
|
397 |
} else {
|
398 |
return $error;
|
399 |
}
|
400 |
}
|
401 |
|
402 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
403 |
global $mainwp_itsec_modules_path;
|
404 |
-
require_once ( $mainwp_itsec_modules_path . 'ipcheck/utilities.php' );
|
405 |
|
406 |
-
$
|
|
|
|
|
407 |
if ( is_wp_error( $key ) ) {
|
408 |
return false;
|
409 |
-
// $this->set_can_save( false );
|
410 |
-
// $this->add_error( $key );
|
411 |
} else {
|
412 |
-
$secret = ITSEC_Network_Brute_Force_Utilities::activate_api_key( $key );
|
413 |
|
414 |
if ( is_wp_error( $secret ) ) {
|
415 |
return false;
|
416 |
-
// $this->set_can_save( false );
|
417 |
-
// $this->add_error( $secret );
|
418 |
} else {
|
419 |
-
$settings['api_key']
|
420 |
$settings['api_secret'] = $secret;
|
421 |
|
422 |
$settings['api_nag'] = false;
|
423 |
|
424 |
-
ITSEC_Response::reload_module( 'network-brute-force' );
|
425 |
}
|
426 |
}
|
427 |
unset( $settings['email'] );
|
428 |
return $settings;
|
429 |
}
|
430 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
431 |
$status = 0;
|
432 |
-
if ( ! is_multisite() && class_exists( 'backupbuddy_api' ) && count( backupbuddy_api::getSchedules() ) >= 1 ) {
|
433 |
$status = 1;
|
434 |
-
} elseif ( ! is_multisite() && class_exists( 'backupbuddy_api' ) ) {
|
435 |
$status = 2;
|
436 |
} elseif ( $this->has_backup() === true && $this->scheduled_backup() === true ) {
|
437 |
$status = 3;
|
@@ -442,22 +594,39 @@ class MainWP_Child_iThemes_Security {
|
|
442 |
return $status;
|
443 |
}
|
444 |
|
445 |
-
|
|
|
|
|
|
|
|
|
|
|
446 |
$has_backup = false;
|
447 |
|
448 |
return apply_filters( 'itsec_has_external_backup', $has_backup );
|
449 |
}
|
450 |
|
451 |
-
|
|
|
|
|
|
|
|
|
|
|
452 |
$sceduled_backup = false;
|
453 |
|
454 |
return apply_filters( 'itsec_scheduled_external_backup', $sceduled_backup );
|
455 |
}
|
456 |
|
457 |
-
|
|
|
|
|
|
|
|
|
|
|
458 |
|
|
|
459 |
global $itsec_globals;
|
460 |
-
|
|
|
461 |
$add_temp = false;
|
462 |
$temp_ip = get_site_option( 'itsec_temp_whitelist_ip' );
|
463 |
if ( false !== $temp_ip ) {
|
@@ -478,48 +647,67 @@ class MainWP_Child_iThemes_Security {
|
|
478 |
);
|
479 |
add_site_option( 'itsec_temp_whitelist_ip', $response );
|
480 |
$response['exp_diff'] = human_time_diff( $itsec_globals['current_time'], $response['exp'] );
|
481 |
-
$response['message1'] = __( 'Your IP Address', '
|
482 |
-
$response['message2'] = __( 'is whitelisted for', '
|
483 |
|
484 |
return $response;
|
485 |
}
|
486 |
-
|
487 |
}
|
488 |
|
489 |
-
|
|
|
|
|
|
|
|
|
|
|
490 |
delete_site_option( 'itsec_temp_whitelist_ip' );
|
491 |
|
492 |
return 'success';
|
493 |
}
|
494 |
|
495 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
496 |
global $itsec_backup, $mainwp_itsec_modules_path;
|
497 |
|
498 |
if ( ! isset( $itsec_backup ) ) {
|
499 |
-
require_once
|
500 |
-
$itsec_backup = new ITSEC_Backup();
|
501 |
$itsec_backup->run();
|
502 |
}
|
503 |
|
504 |
-
$return
|
505 |
|
506 |
$str_error = '';
|
507 |
-
$result
|
508 |
|
509 |
if ( is_wp_error( $result ) ) {
|
510 |
-
$errors = ITSEC_Response::get_error_strings( $result );
|
511 |
|
512 |
foreach ( $errors as $error ) {
|
513 |
$str_error .= $error . '<br />';
|
514 |
}
|
515 |
-
}
|
516 |
-
$return['result']
|
517 |
$return['message'] = $result;
|
518 |
} else {
|
519 |
-
$str_error = sprintf( __( 'The backup request returned an unexpected response. It returned a response of type <code>%1$s</code>.', '
|
520 |
}
|
521 |
|
522 |
-
if (!empty($str_error)) {
|
523 |
$return['error'] = $str_error;
|
524 |
}
|
525 |
|
@@ -527,35 +715,58 @@ class MainWP_Child_iThemes_Security {
|
|
527 |
}
|
528 |
|
529 |
|
530 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
531 |
global $mainwp_itsec_modules_path;
|
532 |
-
|
533 |
-
|
|
|
534 |
}
|
535 |
-
$result
|
536 |
$str_error = '';
|
537 |
if ( is_wp_error( $result ) ) {
|
538 |
-
$errors = ITSEC_Response::get_error_strings( $result );
|
539 |
|
540 |
foreach ( $errors as $error ) {
|
541 |
$str_error .= $error . '<br />';
|
542 |
}
|
543 |
} else {
|
544 |
-
$return['result']
|
545 |
-
$return['message'] = __( 'The WordPress salts were successfully regenerated.', '
|
546 |
-
$last_generated
|
547 |
-
ITSEC_Modules::set_setting( 'wordpress-salts', 'last_generated', $last_generated );
|
548 |
}
|
549 |
-
if (!empty($str_error)) {
|
550 |
$return['error'] = $str_error;
|
551 |
}
|
552 |
return $return;
|
553 |
}
|
554 |
|
555 |
-
|
556 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
557 |
|
558 |
-
|
|
|
|
|
559 |
|
560 |
$path_data = array(
|
561 |
array(
|
@@ -584,23 +795,22 @@ class MainWP_Child_iThemes_Security {
|
|
584 |
),
|
585 |
array(
|
586 |
WP_PLUGIN_DIR,
|
587 |
-
0755
|
588 |
),
|
589 |
array(
|
590 |
$wp_upload_dir['basedir'],
|
591 |
0755,
|
592 |
),
|
593 |
array(
|
594 |
-
ITSEC_Lib_Config_File::get_wp_config_file_path(),
|
595 |
0444,
|
596 |
),
|
597 |
array(
|
598 |
-
ITSEC_Lib_Config_File::get_server_config_file_path(),
|
599 |
0444,
|
600 |
),
|
601 |
);
|
602 |
|
603 |
-
|
604 |
$rows = array();
|
605 |
|
606 |
foreach ( $path_data as $path ) {
|
@@ -619,41 +829,40 @@ class MainWP_Child_iThemes_Security {
|
|
619 |
$row[] = sprintf( '%o', $suggested_permissions );
|
620 |
|
621 |
$permissions = fileperms( $path ) & 0777;
|
622 |
-
$row[]
|
623 |
|
624 |
if ( ! $permissions || $permissions != $suggested_permissions ) {
|
625 |
-
$row[] = __( 'WARNING', '
|
626 |
$row[] = '<div style="background-color: #FEFF7F; border: 1px solid #E2E2E2;"> </div>';
|
627 |
} else {
|
628 |
-
$row[] = __( 'OK', '
|
629 |
$row[] = '<div style="background-color: #22EE5B; border: 1px solid #E2E2E2;"> </div>';
|
630 |
}
|
631 |
|
632 |
$rows[] = $row;
|
633 |
}
|
634 |
|
635 |
-
|
636 |
$class = 'entry-row';
|
637 |
-
|
638 |
-
|
639 |
-
<p><input type="button" id="itsec-file-permissions-reload_file_permissions" name="file-permissions[reload_file_permissions]" class="button-primary itsec-reload-module" value="<?php
|
640 |
<table class="widefat">
|
641 |
<thead>
|
642 |
<tr>
|
643 |
-
<th><?php
|
644 |
-
<th><?php
|
645 |
-
<th><?php
|
646 |
-
<th><?php
|
647 |
-
<th><?php
|
648 |
</tr>
|
649 |
</thead>
|
650 |
<tfoot>
|
651 |
<tr>
|
652 |
-
<th><?php
|
653 |
-
<th><?php
|
654 |
-
<th><?php
|
655 |
-
<th><?php
|
656 |
-
<th><?php
|
657 |
</tr>
|
658 |
</tfoot>
|
659 |
<tbody>
|
@@ -668,54 +877,76 @@ class MainWP_Child_iThemes_Security {
|
|
668 |
</tbody>
|
669 |
</table>
|
670 |
<br />
|
671 |
-
|
672 |
$html = ob_get_clean();
|
673 |
-
return array('html' => $html);
|
674 |
}
|
675 |
|
676 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
677 |
global $mainwp_itsec_modules_path;
|
678 |
-
|
679 |
-
|
|
|
680 |
}
|
681 |
-
$result = ITSEC_File_Change_Scanner::run_scan( false );
|
682 |
-
if (
|
683 |
-
$return['result']
|
684 |
$return['scan_result'] = $result;
|
685 |
}
|
686 |
return $return;
|
687 |
}
|
688 |
|
689 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
690 |
|
691 |
-
$settings = $_POST['settings'];
|
692 |
|
693 |
-
if (!is_array($settings))
|
694 |
$settings = array();
|
|
|
695 |
|
696 |
-
$new_username = isset( $settings['new_username'] )
|
697 |
-
$change_id
|
698 |
|
|
|
699 |
|
700 |
-
|
701 |
-
if ( ! class_exists( 'ITSEC_Lib' ) ) {
|
702 |
global $itsec_globals;
|
703 |
-
|
|
|
704 |
}
|
705 |
|
706 |
$username_exists = username_exists( 'admin' );
|
707 |
-
$user_id_exists = ITSEC_Lib::user_id_exists( 1 );
|
708 |
$msg = '';
|
709 |
-
|
710 |
-
global $current_user;
|
711 |
-
if ( ! $username_exists ) {
|
712 |
-
$msg = __( 'Admin user already changes.', 'mainwp-child' );
|
713 |
-
} else if ($current_user->user_login == 'admin') {
|
714 |
-
$return['result'] = 'CHILD_ADMIN';
|
715 |
-
return $return;
|
716 |
-
}
|
717 |
-
}
|
718 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
719 |
|
720 |
if ( true === $change_id && ! $user_id_exists ) {
|
721 |
if ( ! empty( $msg ) ) {
|
@@ -724,16 +955,8 @@ class MainWP_Child_iThemes_Security {
|
|
724 |
$msg .= __( 'Admin user ID already changes.', 'mainwp-child' );
|
725 |
}
|
726 |
|
727 |
-
// if ( $change_id ) {
|
728 |
-
// $user = get_user_by( 'login', $new_username );
|
729 |
-
// if ( $user && 1 === (int) $user->ID ) {
|
730 |
-
// $return['result'] = 'CHILD_ADMIN';
|
731 |
-
// return $return;
|
732 |
-
// }
|
733 |
-
// }
|
734 |
-
|
735 |
$admin_success = true;
|
736 |
-
$return
|
737 |
|
738 |
if ( strlen( $new_username ) >= 1 && $username_exists ) {
|
739 |
$admin_success = $this->change_admin_user( $new_username, $change_id );
|
@@ -750,61 +973,68 @@ class MainWP_Child_iThemes_Security {
|
|
750 |
return $return;
|
751 |
}
|
752 |
|
753 |
-
|
754 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
755 |
global $wpdb;
|
756 |
-
$itsec_files = ITSEC_Core::get_itsec_files();
|
757 |
|
758 |
-
|
759 |
-
//if ( $itsec_files->get_file_lock( 'admin_user' ) ) { //make sure it isn't already running
|
760 |
|
761 |
-
//sanitize the username
|
762 |
$new_user = sanitize_text_field( $username );
|
763 |
|
764 |
-
//Get the full user object
|
765 |
$user_object = get_user_by( 'id', '1' );
|
766 |
|
767 |
-
|
768 |
-
|
769 |
-
if ( true === $id ) { //we're changing the id too so we'll set the username
|
770 |
|
771 |
-
|
772 |
|
773 |
-
|
774 |
|
775 |
-
|
776 |
-
$wpdb->query( "UPDATE `" . $wpdb->users . "` SET user_login = '" . esc_sql( $new_user ) . "' WHERE user_login='admin';" );
|
777 |
|
778 |
-
|
779 |
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
|
|
784 |
|
785 |
-
|
786 |
-
|
787 |
|
788 |
-
|
789 |
|
790 |
-
|
791 |
-
|
792 |
|
793 |
-
|
794 |
|
795 |
-
|
796 |
|
797 |
-
|
798 |
|
799 |
-
|
800 |
|
801 |
-
|
802 |
|
803 |
-
|
804 |
|
805 |
-
|
806 |
|
807 |
-
|
|
|
|
|
808 |
'user_login' => $user_login,
|
809 |
'user_pass' => $user_object->user_pass,
|
810 |
'user_nicename' => $user_object->user_nicename,
|
@@ -814,37 +1044,43 @@ class MainWP_Child_iThemes_Security {
|
|
814 |
'user_activation_key' => $user_object->user_activation_key,
|
815 |
'user_status' => $user_object->user_status,
|
816 |
'display_name' => $user_object->display_name,
|
817 |
-
)
|
|
|
818 |
|
819 |
-
|
820 |
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
|
825 |
-
|
826 |
|
827 |
-
|
828 |
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
|
834 |
-
|
835 |
-
|
836 |
|
837 |
-
|
838 |
|
839 |
-
|
840 |
-
//}
|
841 |
|
842 |
return false;
|
843 |
-
|
844 |
}
|
845 |
|
846 |
-
|
847 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
848 |
if ( null === $input ) {
|
849 |
return $rules_array;
|
850 |
}
|
@@ -869,51 +1105,71 @@ class MainWP_Child_iThemes_Security {
|
|
869 |
'rule' => "define( 'WP_CONTENT_DIR', '" . $new_dir . "' );",
|
870 |
);
|
871 |
|
872 |
-
$rules_array[] = array(
|
|
|
|
|
|
|
|
|
873 |
|
874 |
return $rules_array;
|
875 |
-
|
876 |
}
|
877 |
|
878 |
|
879 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
880 |
global $mainwp_itsec_modules_path;
|
881 |
-
|
|
|
882 |
$str_error = '';
|
883 |
-
$return
|
884 |
|
885 |
if ( isset( $_POST['change_prefix'] ) && 'yes' === $_POST['change_prefix'] ) {
|
886 |
-
$result = ITSEC_Database_Prefix_Utility::change_database_prefix();
|
887 |
$return = $result['errors'];
|
888 |
-
if (is_array($result['errors'])) {
|
889 |
-
foreach ($result['errors'] as $error) {
|
890 |
-
$arr_errors = ITSEC_Response::get_error_strings( $error );
|
891 |
foreach ( $arr_errors as $er ) {
|
892 |
$str_error .= $er . '<br />';
|
893 |
}
|
894 |
}
|
895 |
}
|
896 |
|
897 |
-
ITSEC_Response::reload_module( 'database-prefix' );
|
898 |
|
899 |
if ( false === $result['new_prefix'] ) {
|
900 |
$return['error'] = $str_error;
|
901 |
} else {
|
902 |
-
$return['result']
|
903 |
-
$return['message'] = sprintf( __( 'The database table prefix was successfully changed to <code>%1$s</code>.', '
|
904 |
|
905 |
}
|
906 |
}
|
907 |
return $return;
|
908 |
}
|
909 |
|
910 |
-
|
|
|
|
|
|
|
|
|
|
|
911 |
$settings = get_site_option( 'itsec_ipcheck' );
|
912 |
if ( ! is_array( $settings ) ) {
|
913 |
$settings = array();
|
914 |
}
|
915 |
$settings['reset'] = true;
|
916 |
-
$return
|
917 |
if ( update_site_option( 'itsec_ipcheck', $settings ) ) {
|
918 |
$return['result'] = 'success';
|
919 |
} else {
|
@@ -923,67 +1179,121 @@ class MainWP_Child_iThemes_Security {
|
|
923 |
return $return;
|
924 |
}
|
925 |
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
934 |
|
935 |
$information = array();
|
936 |
if ( $results['saved'] ) {
|
937 |
-
$information['result']
|
938 |
-
$information['nbf_settings'] = ITSEC_Modules::get_settings( 'network-brute-force');
|
939 |
-
}
|
940 |
$information['error_reset_api'] = 1;
|
941 |
}
|
942 |
return $information;
|
943 |
}
|
944 |
|
945 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
946 |
global $mainwp_itsec_modules_path;
|
947 |
|
948 |
-
if ( ! class_exists( 'ITSEC_Malware_Scanner' ) ) {
|
949 |
-
require_once
|
950 |
-
require_once
|
951 |
}
|
952 |
|
953 |
$response = array();
|
954 |
-
if ( ! ITSEC_Core::current_user_can_manage() ) {
|
955 |
$response['error'] = 'The currently logged in user does not have sufficient permissions to run this scan.';
|
956 |
} else {
|
957 |
-
$results
|
958 |
-
$response['html'] = ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
|
959 |
}
|
960 |
|
961 |
return $response;
|
962 |
}
|
963 |
|
964 |
-
|
965 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
966 |
global $mainwp_itsec_modules_path;
|
967 |
-
|
968 |
-
|
969 |
-
require_once
|
|
|
970 |
}
|
971 |
-
$response
|
972 |
-
$results= ITSEC_Malware_Scanner::scan();
|
973 |
-
$response['html'] = ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
|
974 |
return $response;
|
975 |
}
|
976 |
|
977 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
978 |
global $wpdb;
|
|
|
979 |
$wpdb->query( 'DELETE FROM `' . $wpdb->base_prefix . 'itsec_log`;' );
|
980 |
|
981 |
return array( 'result' => 'success' );
|
982 |
}
|
983 |
|
984 |
|
985 |
-
|
986 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
987 |
global $wpdb, $itsec_globals;
|
988 |
|
989 |
if ( 'all' !== $type || true === $current ) {
|
@@ -1017,16 +1327,28 @@ class MainWP_Child_iThemes_Security {
|
|
1017 |
$and = '';
|
1018 |
}
|
1019 |
|
1020 |
-
$active = $and . " `lockout_active`=1 AND `lockout_expire_gmt` > '" .
|
1021 |
|
1022 |
} else {
|
1023 |
|
1024 |
$active = '';
|
1025 |
|
1026 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1027 |
|
1028 |
-
$results = $wpdb->get_results( 'SELECT * FROM `' . $wpdb->base_prefix . 'itsec_lockouts`' . $where . $type_statement . $active . ';', ARRAY_A );
|
1029 |
-
$output = array();
|
1030 |
if ( is_array( $results ) && count( $results ) > 0 ) {
|
1031 |
switch ( $type ) {
|
1032 |
case 'host':
|
@@ -1062,22 +1384,32 @@ class MainWP_Child_iThemes_Security {
|
|
1062 |
}
|
1063 |
|
1064 |
return $output;
|
|
|
1065 |
}
|
1066 |
|
1067 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1068 |
global $wpdb;
|
1069 |
|
1070 |
-
if ( ! class_exists( 'ITSEC_Lib' ) ) {
|
1071 |
-
require
|
1072 |
}
|
1073 |
|
1074 |
-
$lockout_ids = $_POST['lockout_ids'];
|
1075 |
if ( ! is_array( $lockout_ids ) ) {
|
1076 |
$lockout_ids = array();
|
1077 |
}
|
1078 |
|
1079 |
$type = 'updated';
|
1080 |
-
$message = __( 'The selected lockouts have been cleared.', '
|
1081 |
|
1082 |
foreach ( $lockout_ids as $value ) {
|
1083 |
$wpdb->update(
|
@@ -1091,11 +1423,11 @@ class MainWP_Child_iThemes_Security {
|
|
1091 |
);
|
1092 |
}
|
1093 |
|
1094 |
-
ITSEC_Lib::clear_caches();
|
1095 |
|
1096 |
if ( ! is_multisite() ) {
|
1097 |
if ( ! function_exists( 'add_settings_error' ) ) {
|
1098 |
-
require_once
|
1099 |
}
|
1100 |
|
1101 |
add_settings_error( 'itsec', esc_attr( 'settings_updated' ), $message, $type );
|
@@ -1106,34 +1438,57 @@ class MainWP_Child_iThemes_Security {
|
|
1106 |
);
|
1107 |
}
|
1108 |
|
1109 |
-
|
|
|
|
|
|
|
|
|
|
|
1110 |
|
1111 |
-
$active_modules = $_POST['active_modules'];
|
1112 |
|
1113 |
-
if (!is_array($active_modules))
|
1114 |
$active_modules = array();
|
|
|
1115 |
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
|
1121 |
update_site_option( 'itsec_active_modules', $current_val );
|
1122 |
-
return array('result' => 'success');
|
1123 |
-
|
1124 |
}
|
1125 |
|
1126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1127 |
return array(
|
1128 |
-
'exclude'
|
1129 |
'excludable_tables' => $this->get_excludable_tables(),
|
1130 |
-
'result'
|
1131 |
);
|
1132 |
}
|
1133 |
|
1134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1135 |
global $wpdb;
|
1136 |
-
|
|
|
1137 |
$ignored_tables = array(
|
1138 |
'commentmeta',
|
1139 |
'comments',
|
@@ -1154,7 +1509,7 @@ class MainWP_Child_iThemes_Security {
|
|
1154 |
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', "{$wpdb->base_prefix}%" );
|
1155 |
}
|
1156 |
|
1157 |
-
$tables
|
1158 |
$excludes = array();
|
1159 |
|
1160 |
foreach ( $tables as $table ) {
|
@@ -1164,30 +1519,49 @@ class MainWP_Child_iThemes_Security {
|
|
1164 |
continue;
|
1165 |
}
|
1166 |
|
1167 |
-
$excludes[$short_table] = $table[0];
|
1168 |
}
|
1169 |
|
1170 |
-
return $excludes
|
1171 |
}
|
1172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1173 |
private function security_site() {
|
|
|
|
|
1174 |
global $mainwp_itsec_modules_path;
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
|
|
1180 |
$response = ob_get_clean();
|
1181 |
-
return array(
|
|
|
|
|
|
|
1182 |
}
|
1183 |
|
1184 |
-
|
1185 |
-
|
|
|
|
|
|
|
|
|
|
|
1186 |
public function get_available_admin_users_and_roles() {
|
1187 |
if ( is_callable( 'wp_roles' ) ) {
|
1188 |
$roles = wp_roles();
|
1189 |
} else {
|
1190 |
-
$roles = new WP_Roles();
|
1191 |
}
|
1192 |
|
1193 |
$available_roles = array();
|
@@ -1195,13 +1569,13 @@ class MainWP_Child_iThemes_Security {
|
|
1195 |
|
1196 |
foreach ( $roles->roles as $role => $details ) {
|
1197 |
if ( isset( $details['capabilities']['manage_options'] ) && ( true === $details['capabilities']['manage_options'] ) ) {
|
1198 |
-
$available_roles["role:$role"] = translate_user_role( $details['name'] );
|
1199 |
|
1200 |
$users = get_users( array( 'role' => $role ) );
|
1201 |
|
1202 |
foreach ( $users as $user ) {
|
1203 |
/* translators: 1: user display name, 2: user login */
|
1204 |
-
$available_users[ $user->ID ] = sprintf( __( '%1$s (%2$s)', '
|
1205 |
}
|
1206 |
}
|
1207 |
}
|
@@ -1215,4 +1589,3 @@ class MainWP_Child_iThemes_Security {
|
|
1215 |
}
|
1216 |
|
1217 |
}
|
1218 |
-
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Ithemes Security
|
4 |
+
*
|
5 |
+
* MainWP iThemes Security Extension handler.
|
6 |
+
* Extension URL: https://mainwp.com/extension/ithemes-security/
|
7 |
+
*
|
8 |
+
* @package MainWP\Child
|
9 |
*
|
10 |
* Credits
|
11 |
*
|
17 |
*
|
18 |
* The code is used for the MainWP iThemes Security Extension
|
19 |
* Extension URL: https://mainwp.com/extension/ithemes-security/
|
20 |
+
*/
|
21 |
+
|
22 |
+
namespace MainWP\Child;
|
23 |
+
|
24 |
+
// phpcs:disable -- third party credit code.
|
25 |
+
|
26 |
|
27 |
+
/**
|
28 |
+
* Class MainWP_Child_IThemes_Security
|
29 |
+
*/
|
30 |
+
class MainWP_Child_IThemes_Security {
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Public static variable to hold the single instance of MainWP_Child_IThemes_Security.
|
34 |
+
* @var null
|
35 |
+
*/
|
36 |
+
public static $instance = null;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* @var bool Whether or not iThemes Plugin is installed or not. Default: false.
|
40 |
+
*/
|
41 |
public $is_plugin_installed = false;
|
42 |
|
43 |
+
/**
|
44 |
+
* Create a public static instance of MainWP_Child_IThemes_Security.
|
45 |
+
*
|
46 |
+
* @return MainWP_Child_IThemes_Security|null
|
47 |
+
*/
|
48 |
+
public static function instance() {
|
49 |
+
if ( null === self::$instance ) {
|
50 |
+
self::$instance = new self();
|
51 |
}
|
52 |
+
return self::$instance;
|
|
|
53 |
}
|
54 |
|
55 |
+
/**
|
56 |
+
* MainWP_Child_IThemes_Security constructor.
|
57 |
+
*
|
58 |
+
* Run any time class is called.
|
59 |
+
*
|
60 |
+
* @uses MainWP_Child_IThemes_Security::is_plugin_installed()
|
61 |
+
*/
|
62 |
+
public function __construct() {
|
63 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
64 |
+
if ( is_plugin_active( 'better-wp-security/better-wp-security.php' ) || is_plugin_active( 'ithemes-security-pro/ithemes-security-pro.php' ) ) {
|
65 |
+
$this->is_plugin_installed = true;
|
66 |
}
|
67 |
|
68 |
+
if ( ! $this->is_plugin_installed ) {
|
69 |
+
return;
|
70 |
+
}
|
71 |
|
72 |
+
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
73 |
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Sync other data from $data[] and merge with $information[]
|
77 |
+
*
|
78 |
+
* @param array $information Returned response array for MainWP BackWPup Extension actions.
|
79 |
+
* @param array $data Other data to sync to $information array.
|
80 |
+
* @return array $information Returned information array with both sets of data.
|
81 |
+
*/
|
82 |
+
public function sync_others_data( $information, $data = array() ) {
|
83 |
if ( is_array( $data ) && isset( $data['ithemeExtActivated'] ) && ( 'yes' === $data['ithemeExtActivated'] ) ) {
|
84 |
+
try {
|
85 |
+
$information['syncIThemeData'] = array(
|
86 |
+
'users_and_roles' => $this->get_available_admin_users_and_roles(),
|
87 |
+
);
|
88 |
+
} catch ( \Exception $e ) {
|
89 |
+
error_log( $e->getMessage() ); // phpcs:ignore -- debug mode only.
|
90 |
+
}
|
91 |
}
|
92 |
return $information;
|
93 |
}
|
94 |
|
95 |
+
/**
|
96 |
+
* MainWP iThemes Security Extension actions.
|
97 |
+
*
|
98 |
+
* @uses MainWP_Child_IThemes_Security::set_showhide()
|
99 |
+
* @uses MainWP_Child_IThemes_Security::save_settings()
|
100 |
+
* @uses MainWP_Child_IThemes_Security::whitelist_release()
|
101 |
+
* @uses MainWP_Child_IThemes_Security::backup_db()
|
102 |
+
* @uses MainWP_Child_IThemes_Security::admin_user()
|
103 |
+
* @uses MainWP_Child_IThemes_Security::change_database_prefix()
|
104 |
+
* @uses MainWP_Child_IThemes_Security::reset_api_key()
|
105 |
+
* @uses MainWP_Child_IThemes_Security::malware_scan()
|
106 |
+
* @uses MainWP_Child_IThemes_Security::>purge_logs()
|
107 |
+
* @uses MainWP_Child_IThemes_Security::file_change()
|
108 |
+
* @uses MainWP_Child_IThemes_Security::release_lockout()
|
109 |
+
* @uses MainWP_Child_IThemes_Security::update_module_status()
|
110 |
+
* @uses MainWP_Child_IThemes_Security::wordpress_salts()
|
111 |
+
* @uses MainWP_Child_IThemes_Security::file_permissions()
|
112 |
+
* @uses MainWP_Child_IThemes_Security::reload_backup_exclude()
|
113 |
+
* @uses MainWP_Child_IThemes_Security::security_site()
|
114 |
+
* @uses MainWP_Child_IThemes_Security::activate_network_brute_force()
|
115 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
116 |
+
*/
|
117 |
+
public function action() {
|
118 |
$information = array();
|
119 |
+
if ( ! class_exists( '\ITSEC_Core' ) || ! class_exists( '\ITSEC_Modules' ) ) {
|
120 |
$information['error'] = 'NO_ITHEME';
|
121 |
MainWP_Helper::write( $information );
|
122 |
}
|
123 |
|
124 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
125 |
global $mainwp_itsec_modules_path;
|
126 |
|
127 |
+
$mainwp_itsec_modules_path = \ITSEC_Core::get_core_dir() . '/modules/';
|
|
|
128 |
|
129 |
if ( isset( $_POST['mwp_action'] ) ) {
|
130 |
+
$mwp_action = ! empty( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
131 |
+
switch ( $mwp_action ) {
|
132 |
case 'set_showhide':
|
133 |
$information = $this->set_showhide();
|
134 |
break;
|
185 |
MainWP_Helper::write( $information );
|
186 |
}
|
187 |
|
188 |
+
/**
|
189 |
+
* Set show or hide UpdraftPlus Plugin from Admin & plugins list.
|
190 |
+
*
|
191 |
+
* @return array $information Return results.
|
192 |
+
*
|
193 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
194 |
+
*/
|
195 |
+
public function set_showhide() {
|
196 |
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
197 |
MainWP_Helper::update_option( 'mainwp_ithemes_hide_plugin', $hide );
|
198 |
$information['result'] = 'success';
|
200 |
return $information;
|
201 |
}
|
202 |
|
203 |
+
/**
|
204 |
+
* Initiate iThemes settings.
|
205 |
+
*
|
206 |
+
* @uses MainWP_Child_IThemes_Security::is_plugin_installed()
|
207 |
+
*/
|
208 |
+
public function ithemes_init() {
|
209 |
+
if ( ! $this->is_plugin_installed ) {
|
210 |
return;
|
211 |
+
}
|
212 |
|
213 |
+
if ( 'hide' === get_option( 'mainwp_ithemes_hide_plugin' ) ) {
|
214 |
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
215 |
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
216 |
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
217 |
add_action( 'admin_head', array( &$this, 'custom_admin_css' ) );
|
218 |
+
if ( isset( $_GET['page'] ) && ( 'itsec' == $_GET['page'] || 'itsec-security-check' == $_GET['page'] ) ) {
|
219 |
+
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
220 |
exit();
|
221 |
}
|
222 |
}
|
223 |
}
|
224 |
|
225 |
+
/**
|
226 |
+
* iThemes Security Admin initiation.
|
227 |
+
*/
|
228 |
+
public function admin_init() {
|
229 |
remove_meta_box( 'itsec-dashboard-widget', 'dashboard', 'normal' );
|
230 |
}
|
231 |
|
232 |
+
/**
|
233 |
+
* Remove iThemes Security from plugins page.
|
234 |
+
*
|
235 |
+
* @param array $plugins All plugins array.
|
236 |
+
*
|
237 |
+
* @return array $plugins All plugins array with iThemes Security removed.
|
238 |
+
*/
|
239 |
+
public function all_plugins( $plugins ) {
|
240 |
foreach ( $plugins as $key => $value ) {
|
241 |
$plugin_slug = basename( $key, '.php' );
|
242 |
if ( 'better-wp-security' === $plugin_slug || 'ithemes-security-pro' === $plugin_slug ) {
|
247 |
return $plugins;
|
248 |
}
|
249 |
|
250 |
+
/**
|
251 |
+
* Remove iThemes Security plugin from WP Admin menu.
|
252 |
+
*/
|
253 |
+
public function remove_menu() {
|
254 |
remove_menu_page( 'itsec' );
|
255 |
}
|
256 |
|
257 |
+
/**
|
258 |
+
* Custom admin CSS.
|
259 |
+
*/
|
260 |
+
public function custom_admin_css() {
|
261 |
?>
|
262 |
<style type="text/css">
|
263 |
#wp-admin-bar-itsec_admin_bar_menu{
|
267 |
<?php
|
268 |
}
|
269 |
|
270 |
+
/**
|
271 |
+
* Save UpdraftPlus settings.
|
272 |
+
*
|
273 |
+
* @return array[] $return Return Error message or Success Message.
|
274 |
+
*
|
275 |
+
* @uses \ITSEC_Lib::get_server()
|
276 |
+
* @uses \ITSEC_Lib::get_ssl_support_probability()
|
277 |
+
* @uses \ITSEC_Lib_Config_File::get_server_config()
|
278 |
+
* @uses \ITSEC_Lib_Config_File::get_wp_config()
|
279 |
+
* @uses \ITSEC_Modules::get_default()
|
280 |
+
* @uses \ITSEC_Modules::get_setting()
|
281 |
+
* @uses MainWP_Child_IThemes_Security::get_lockouts()
|
282 |
+
* @uses MainWP_Child_IThemes_Security::validate_directory()
|
283 |
+
* @uses MainWP_Child_IThemes_Security::activate_api_key()
|
284 |
+
* @uses MainWP_Child_IThemes_Security::get_excludable_tables()
|
285 |
+
* @uses MainWP_Child_IThemes_Security::get_available_admin_users_and_roles()
|
286 |
+
*/
|
287 |
+
public function save_settings() {
|
288 |
+
|
289 |
+
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
290 |
+
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
291 |
}
|
292 |
|
293 |
$_itsec_modules = array(
|
302 |
'404-detection',
|
303 |
'network-brute-force',
|
304 |
'ssl',
|
305 |
+
'password-requirements',
|
|
|
306 |
'system-tweaks',
|
307 |
'wordpress-tweaks',
|
308 |
'multisite-tweaks',
|
309 |
+
'notification-center',
|
|
|
|
|
310 |
);
|
311 |
|
312 |
$require_permalinks = false;
|
313 |
+
$updated = false;
|
314 |
+
$errors = array();
|
315 |
+
$nbf_settings = array();
|
316 |
|
317 |
+
$update_settings = isset( $_POST['settings'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['settings'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
318 |
|
319 |
+
foreach ( $update_settings as $module => $settings ) {
|
320 |
$do_not_save = false;
|
321 |
+
if ( in_array( $module, $_itsec_modules ) ) {
|
322 |
+
if ( 'wordpress-salts' == $module ) {
|
323 |
+
$settings['last_generated'] = \ITSEC_Modules::get_setting( $module, 'last_generated' );
|
324 |
+
} elseif ( 'global' == $module ) {
|
325 |
+
$keep_olds = array( 'did_upgrade', 'log_info', 'show_new_dashboard_notice', 'show_security_check', 'nginx_file' );
|
326 |
+
foreach ( $keep_olds as $key ) {
|
327 |
+
$settings[ $key ] = \ITSEC_Modules::get_setting( $module, $key );
|
328 |
}
|
329 |
|
330 |
+
if ( ! isset( $settings['log_location'] ) || empty( $settings['log_location'] ) ) {
|
331 |
+
$settings['log_location'] = \ITSEC_Modules::get_setting( $module, 'log_location' );
|
332 |
} else {
|
333 |
+
$result = $this->validate_directory( 'log_location', $settings['log_location'] );
|
334 |
+
if ( true !== $result ) {
|
335 |
+
$errors[] = $result;
|
336 |
+
$settings['log_location'] = \ITSEC_Modules::get_setting( $module, 'log_location' );
|
337 |
}
|
338 |
}
|
339 |
+
} elseif ( 'backup' == $module ) {
|
340 |
+
if ( ! isset( $settings['location'] ) || empty( $settings['location'] ) ) {
|
341 |
+
$settings['location'] = \ITSEC_Modules::get_setting( $module, 'location' );
|
|
|
342 |
} else {
|
343 |
+
$result = $this->validate_directory( 'location', $settings['location'] );
|
344 |
+
if ( true !== $result ) {
|
345 |
+
$errors[] = $result;
|
346 |
+
$settings['location'] = \ITSEC_Modules::get_setting( $module, 'location' );
|
347 |
}
|
348 |
}
|
349 |
+
if ( ! isset( $settings['exclude'] ) ) {
|
350 |
+
$settings['exclude'] = \ITSEC_Modules::get_setting( $module, 'exclude' );
|
351 |
+
|
352 |
}
|
353 |
+
} elseif ( 'hide-backend' == $module ) {
|
354 |
+
if ( isset( $settings['enabled'] ) && ! empty( $settings['enabled'] ) ) {
|
355 |
$permalink_structure = get_option( 'permalink_structure', false );
|
356 |
if ( empty( $permalink_structure ) && ! is_multisite() ) {
|
357 |
+
$errors[] = __( 'You must change <strong>WordPress permalinks</strong> to a setting other than "Plain" in order to use "Hide Backend" feature.', 'mainwp-child' );
|
358 |
$require_permalinks = true;
|
359 |
+
$do_not_save = true;
|
360 |
}
|
361 |
}
|
362 |
+
} elseif ( 'network-brute-force' == $module ) {
|
363 |
|
364 |
if ( isset( $settings['email'] ) ) {
|
365 |
+
$result = $this->activate_api_key( $settings );
|
366 |
+
if ( false === $result ) {
|
367 |
$nbf_settings = $settings;
|
368 |
+
$errors[] = 'Error: Active iThemes Network Brute Force Protection Api Key';
|
369 |
} else {
|
370 |
$nbf_settings = $result;
|
371 |
}
|
372 |
} else {
|
373 |
+
$previous_settings = \ITSEC_Modules::get_settings( $module );
|
374 |
+
if ( isset( $settings['enable_ban'] ) ) {
|
|
|
375 |
$previous_settings['enable_ban'] = $settings['enable_ban'];
|
376 |
+
$nbf_settings = $previous_settings;
|
377 |
} else {
|
378 |
+
$do_not_save = true;
|
379 |
$nbf_settings = $previous_settings;
|
380 |
}
|
381 |
}
|
382 |
$settings = $nbf_settings;
|
383 |
+
} elseif ( 'notification-center' == $module ) {
|
384 |
+
$current_settings = \ITSEC_Modules::get_settings( $module );
|
385 |
+
if ( isset( $settings['notifications'] ) ) {
|
386 |
+
$update_fields = array( 'schedule', 'enabled', 'subject' );
|
387 |
+
if ( isset( $_POST['is_individual'] ) && $_POST['is_individual'] ) {
|
388 |
+
$update_fields = array_merge( $update_fields, array( 'user_list', 'email_list' ) );
|
389 |
+
}
|
390 |
+
foreach ( $settings['notifications'] as $key => $val ) {
|
391 |
+
foreach ( $update_fields as $field ) {
|
392 |
+
if ( isset( $val[ $field ] ) ) {
|
393 |
+
$current_settings['notifications'][ $key ][ $field ] = $val[ $field ];
|
394 |
+
}
|
395 |
+
}
|
396 |
+
}
|
397 |
+
$updated = true;
|
398 |
+
\ITSEC_Modules::set_settings( $module, $current_settings );
|
399 |
+
}
|
400 |
+
continue;
|
401 |
+
}
|
402 |
+
|
403 |
+
if ( ! $do_not_save ) {
|
404 |
+
\ITSEC_Modules::set_settings( $module, $settings );
|
405 |
+
$updated = true;
|
406 |
}
|
407 |
}
|
408 |
}
|
409 |
|
410 |
+
if ( isset( $update_settings['itsec_active_modules'] ) ) {
|
411 |
+
$current_val = get_site_option( 'itsec_active_modules', array() );
|
412 |
+
foreach ( $update_settings['itsec_active_modules'] as $mod => $val ) {
|
413 |
+
$current_val[ $mod ] = $val;
|
414 |
+
}
|
415 |
+
update_site_option( 'itsec_active_modules', $current_val );
|
416 |
+
}
|
417 |
|
418 |
+
require_once \ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php';
|
419 |
|
420 |
$values = array(
|
421 |
'permalink_structure' => get_option( 'permalink_structure' ),
|
422 |
'is_multisite' => is_multisite() ? 1 : 0,
|
423 |
'users_can_register' => get_site_option( 'users_can_register' ) ? 1 : 0,
|
424 |
+
'server_nginx' => ( \ITSEC_Lib::get_server() === 'nginx' ) ? 1 : 0,
|
425 |
+
'has_ssl' => \ITSEC_Lib::get_ssl_support_probability(),
|
426 |
+
'jquery_version' => \ITSEC_Modules::get_setting( 'wordpress-tweaks', 'jquery_version' ),
|
427 |
+
'server_rules' => \ITSEC_Lib_Config_File::get_server_config(),
|
428 |
+
'config_rules' => \ITSEC_Lib_Config_File::get_wp_config(),
|
429 |
'lockouts_host' => $this->get_lockouts( 'host', true ),
|
430 |
'lockouts_user' => $this->get_lockouts( 'user', true ),
|
431 |
'lockouts_username' => $this->get_lockouts( 'username', true ),
|
432 |
+
'default_log_location' => \ITSEC_Modules::get_default( 'global', 'log_location' ),
|
433 |
+
'default_location' => \ITSEC_Modules::get_default( 'backup', 'location' ),
|
434 |
+
'excludable_tables' => $this->get_excludable_tables(),
|
435 |
+
'users_and_roles' => $this->get_available_admin_users_and_roles(),
|
436 |
);
|
437 |
|
438 |
+
$return = array(
|
439 |
+
'site_status' => $values,
|
440 |
);
|
441 |
|
442 |
+
if ( $require_permalinks ) {
|
443 |
$return['require_permalinks'] = 1;
|
444 |
}
|
445 |
|
446 |
$return['nbf_settings'] = $nbf_settings;
|
447 |
|
448 |
+
if ( ! empty( $errors ) ) {
|
449 |
$return['extra_message'] = $errors;
|
450 |
}
|
451 |
|
452 |
+
if ( $updated ) {
|
453 |
$return['result'] = 'success';
|
454 |
+
} else {
|
455 |
+
$return['error'] = __( 'Not Updated', 'mainwp-child' );
|
456 |
+
}
|
457 |
|
458 |
return $return;
|
459 |
}
|
460 |
|
461 |
+
/**
|
462 |
+
* Activate network brute force.
|
463 |
+
*
|
464 |
+
* @return array $information Results array.
|
465 |
+
*
|
466 |
+
* @uses \ITSEC_Modules::get_settings()
|
467 |
+
* @uses \ITSEC_Modules::activate()
|
468 |
+
*/
|
469 |
+
public static function activate_network_brute_force() {
|
470 |
+
$data = isset( $_POST['data'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['data'] ) ) ) : array(); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
471 |
$information = array();
|
472 |
+
if ( is_array( $data ) ) {
|
473 |
+
$settings = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
474 |
+
$settings['email'] = $data['email'];
|
475 |
$settings['updates_optin'] = $data['updates_optin'];
|
476 |
+
$settings['api_nag'] = false;
|
477 |
+
$results = \ITSEC_Modules::set_settings( 'network-brute-force', $settings );
|
478 |
if ( is_wp_error( $results ) ) {
|
479 |
$information['error'] = 'Error: Active iThemes Network Brute Force Protection Api Key';
|
480 |
+
} elseif ( $results['saved'] ) {
|
481 |
+
\ITSEC_Modules::activate( 'network-brute-force' );
|
482 |
+
$nbf_settings = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
|
|
483 |
}
|
484 |
}
|
485 |
+
if ( null !== $nbf_settings ) {
|
486 |
$information['nbf_settings'] = $nbf_settings;
|
487 |
+
$information['result'] = 'success';
|
488 |
}
|
489 |
return $information;
|
490 |
}
|
491 |
|
492 |
+
/**
|
493 |
+
* Validate directory.
|
494 |
+
*
|
495 |
+
* @param string $name Input name.
|
496 |
+
* @param string $folder Folder.
|
497 |
+
*
|
498 |
+
* @return bool|string Return TRUE on success or Error message on failure.
|
499 |
+
*
|
500 |
+
* @uses \ITSEC_Lib_Directory::is_dir()
|
501 |
+
* @uses \ITSEC_Lib_Directory::create()
|
502 |
+
* @uses \ITSEC_Lib_Directory::is_writable()
|
503 |
+
* @uses \ITSEC_Lib_Directory::add_file_listing_protection()
|
504 |
+
*/
|
505 |
+
private function validate_directory( $name, $folder ) {
|
506 |
+
require_once \ITSEC_Core::get_core_dir() . 'lib/class-itsec-lib-directory.php';
|
507 |
$error = null;
|
508 |
+
if ( ! \ITSEC_Lib_Directory::is_dir( $folder ) ) {
|
509 |
+
$result = \ITSEC_Lib_Directory::create( $folder );
|
510 |
|
511 |
if ( is_wp_error( $result ) ) {
|
512 |
+
$error = sprintf( _x( 'The directory supplied in %1$s cannot be used as a valid directory. %2$s', '%1$s is the input name. %2$s is the error message.', 'mainwp-child' ), $name, $result->get_error_message() );
|
513 |
}
|
514 |
}
|
515 |
|
516 |
+
if ( empty( $error ) && ! \ITSEC_Lib_Directory::is_writable( $folder ) ) {
|
517 |
+
$error = sprintf( __( 'The directory supplied in %1$s is not writable. Please select a directory that can be written to.', 'mainwp-child' ), $name );
|
518 |
}
|
519 |
|
520 |
if ( empty( $error ) ) {
|
521 |
+
\ITSEC_Lib_Directory::add_file_listing_protection( $folder );
|
522 |
return true;
|
523 |
} else {
|
524 |
return $error;
|
525 |
}
|
526 |
}
|
527 |
|
528 |
+
/**
|
529 |
+
* Activate api key.
|
530 |
+
*
|
531 |
+
* @param array $settings Setting array.
|
532 |
+
*
|
533 |
+
* @return array|bool Return $settings array or FALSE on failure.
|
534 |
+
*
|
535 |
+
* @uses \ITSEC_Network_Brute_Force_Utilities::get_api_key()
|
536 |
+
* @uses \ITSEC_Network_Brute_Force_Utilities::activate_api_key()
|
537 |
+
* @uses \ITSEC_Response::reload_module()
|
538 |
+
*/
|
539 |
+
private function activate_api_key( $settings ) {
|
540 |
+
|
541 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
542 |
global $mainwp_itsec_modules_path;
|
|
|
543 |
|
544 |
+
require_once $mainwp_itsec_modules_path . 'ipcheck/utilities.php';
|
545 |
+
|
546 |
+
$key = \ITSEC_Network_Brute_Force_Utilities::get_api_key( $settings['email'], $settings['updates_optin'] );
|
547 |
if ( is_wp_error( $key ) ) {
|
548 |
return false;
|
|
|
|
|
549 |
} else {
|
550 |
+
$secret = \ITSEC_Network_Brute_Force_Utilities::activate_api_key( $key );
|
551 |
|
552 |
if ( is_wp_error( $secret ) ) {
|
553 |
return false;
|
|
|
|
|
554 |
} else {
|
555 |
+
$settings['api_key'] = $key;
|
556 |
$settings['api_secret'] = $secret;
|
557 |
|
558 |
$settings['api_nag'] = false;
|
559 |
|
560 |
+
\ITSEC_Response::reload_module( 'network-brute-force' );
|
561 |
}
|
562 |
}
|
563 |
unset( $settings['email'] );
|
564 |
return $settings;
|
565 |
}
|
566 |
+
|
567 |
+
/**
|
568 |
+
* Backup status.
|
569 |
+
*
|
570 |
+
* @return int $status 1, 2, 3 or 4
|
571 |
+
* (1) Is not a multisite installation, backupbuddy_api exists & Scheduled backups are >=1
|
572 |
+
* (2) Is not multisite and backupbuddy_api exists
|
573 |
+
* (3) Has backup = true & schedualed backup = true
|
574 |
+
* (4) Has backup = true.
|
575 |
+
*
|
576 |
+
* @uses \backupbuddy_api::getSchedules()
|
577 |
+
* @uses MainWP_Child_IThemes_Security::has_backup()
|
578 |
+
* @uses MainWP_Child_IThemes_Security::scheduled_backup()
|
579 |
+
* @uses MainWP_Child_IThemes_Security::has_backup()
|
580 |
+
*
|
581 |
+
*/
|
582 |
+
public function backup_status() {
|
583 |
$status = 0;
|
584 |
+
if ( ! is_multisite() && class_exists( '\backupbuddy_api' ) && count( \backupbuddy_api::getSchedules() ) >= 1 ) {
|
585 |
$status = 1;
|
586 |
+
} elseif ( ! is_multisite() && class_exists( '\backupbuddy_api' ) ) {
|
587 |
$status = 2;
|
588 |
} elseif ( $this->has_backup() === true && $this->scheduled_backup() === true ) {
|
589 |
$status = 3;
|
594 |
return $status;
|
595 |
}
|
596 |
|
597 |
+
/**
|
598 |
+
* Check if backup exists.
|
599 |
+
*
|
600 |
+
* @return bool TRUE|FALSE
|
601 |
+
*/
|
602 |
+
public function has_backup() {
|
603 |
$has_backup = false;
|
604 |
|
605 |
return apply_filters( 'itsec_has_external_backup', $has_backup );
|
606 |
}
|
607 |
|
608 |
+
/**
|
609 |
+
* Check if there is a shedualed backup.
|
610 |
+
*
|
611 |
+
* @return bool TRUE|FALSE.
|
612 |
+
*/
|
613 |
+
public function scheduled_backup() {
|
614 |
$sceduled_backup = false;
|
615 |
|
616 |
return apply_filters( 'itsec_scheduled_external_backup', $sceduled_backup );
|
617 |
}
|
618 |
|
619 |
+
/**
|
620 |
+
* Whitelist Dashboard IP address.
|
621 |
+
*
|
622 |
+
* @return array|string[] Response array.
|
623 |
+
*/
|
624 |
+
public function whitelist() {
|
625 |
|
626 |
+
/** @global array $itsec_globals itsec globals. */
|
627 |
global $itsec_globals;
|
628 |
+
|
629 |
+
$ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
|
630 |
$add_temp = false;
|
631 |
$temp_ip = get_site_option( 'itsec_temp_whitelist_ip' );
|
632 |
if ( false !== $temp_ip ) {
|
647 |
);
|
648 |
add_site_option( 'itsec_temp_whitelist_ip', $response );
|
649 |
$response['exp_diff'] = human_time_diff( $itsec_globals['current_time'], $response['exp'] );
|
650 |
+
$response['message1'] = __( 'Your IP Address', 'mainwp-child' );
|
651 |
+
$response['message2'] = __( 'is whitelisted for', 'mainwp-child' );
|
652 |
|
653 |
return $response;
|
654 |
}
|
|
|
655 |
}
|
656 |
|
657 |
+
/**
|
658 |
+
* Whitelist release.
|
659 |
+
*
|
660 |
+
* @return string Return 'Success'.
|
661 |
+
*/
|
662 |
+
public function whitelist_release() {
|
663 |
delete_site_option( 'itsec_temp_whitelist_ip' );
|
664 |
|
665 |
return 'success';
|
666 |
}
|
667 |
|
668 |
+
/**
|
669 |
+
* Backup Database.
|
670 |
+
*
|
671 |
+
* @return array $return Return results array.
|
672 |
+
*
|
673 |
+
* @uses \ITSEC_Backup()
|
674 |
+
* @uses \ITSEC_Backup::run()
|
675 |
+
* @uses \ITSEC_Backup::do_backup()
|
676 |
+
* @uses \ITSEC_Response::get_error_strings()
|
677 |
+
*/
|
678 |
+
public function backup_db() {
|
679 |
+
|
680 |
+
/**
|
681 |
+
* @global string $mainwp_itsec_modules_path MainWP itsec modules path.
|
682 |
+
* @global object $itsec_backup ITsec backup class.
|
683 |
+
*/
|
684 |
global $itsec_backup, $mainwp_itsec_modules_path;
|
685 |
|
686 |
if ( ! isset( $itsec_backup ) ) {
|
687 |
+
require_once $mainwp_itsec_modules_path . 'backup/class-itsec-backup.php';
|
688 |
+
$itsec_backup = new \ITSEC_Backup();
|
689 |
$itsec_backup->run();
|
690 |
}
|
691 |
|
692 |
+
$return = array();
|
693 |
|
694 |
$str_error = '';
|
695 |
+
$result = $itsec_backup->do_backup( true );
|
696 |
|
697 |
if ( is_wp_error( $result ) ) {
|
698 |
+
$errors = \ITSEC_Response::get_error_strings( $result );
|
699 |
|
700 |
foreach ( $errors as $error ) {
|
701 |
$str_error .= $error . '<br />';
|
702 |
}
|
703 |
+
} elseif ( is_string( $result ) ) {
|
704 |
+
$return['result'] = 'success';
|
705 |
$return['message'] = $result;
|
706 |
} else {
|
707 |
+
$str_error = sprintf( __( 'The backup request returned an unexpected response. It returned a response of type <code>%1$s</code>.', 'mainwp-child' ), gettype( $result ) );
|
708 |
}
|
709 |
|
710 |
+
if ( ! empty( $str_error ) ) {
|
711 |
$return['error'] = $str_error;
|
712 |
}
|
713 |
|
715 |
}
|
716 |
|
717 |
|
718 |
+
/**
|
719 |
+
* Update WordPress Salts.
|
720 |
+
*
|
721 |
+
* @return array $return Return results array.
|
722 |
+
*
|
723 |
+
* @uses \ITSEC_WordPress_Salts_Utilities::generate_new_salts()
|
724 |
+
* @uses \ITSEC_Response::get_error_strings()
|
725 |
+
* @uses \ITSEC_Core::get_current_time_gmt()
|
726 |
+
* @uses \ITSEC_Modules::set_setting()
|
727 |
+
*/
|
728 |
+
private function wordpress_salts() {
|
729 |
+
|
730 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
731 |
global $mainwp_itsec_modules_path;
|
732 |
+
|
733 |
+
if ( ! class_exists( '\ITSEC_WordPress_Salts_Utilities' ) ) {
|
734 |
+
require $mainwp_itsec_modules_path . 'salts/utilities.php';
|
735 |
}
|
736 |
+
$result = \ITSEC_WordPress_Salts_Utilities::generate_new_salts();
|
737 |
$str_error = '';
|
738 |
if ( is_wp_error( $result ) ) {
|
739 |
+
$errors = \ITSEC_Response::get_error_strings( $result );
|
740 |
|
741 |
foreach ( $errors as $error ) {
|
742 |
$str_error .= $error . '<br />';
|
743 |
}
|
744 |
} else {
|
745 |
+
$return['result'] = 'success';
|
746 |
+
$return['message'] = __( 'The WordPress salts were successfully regenerated.', 'mainwp-child' );
|
747 |
+
$last_generated = \ITSEC_Core::get_current_time_gmt();
|
748 |
+
\ITSEC_Modules::set_setting( 'wordpress-salts', 'last_generated', $last_generated );
|
749 |
}
|
750 |
+
if ( ! empty( $str_error ) ) {
|
751 |
$return['error'] = $str_error;
|
752 |
}
|
753 |
return $return;
|
754 |
}
|
755 |
|
756 |
+
/**
|
757 |
+
* Update file permissions.
|
758 |
+
*
|
759 |
+
* @return array Return results table html.
|
760 |
+
*
|
761 |
+
* @uses \ITSEC_Core::get_wp_upload_dir()
|
762 |
+
* @uses \ITSEC_Lib_Config_File::get_wp_config_file_path()
|
763 |
+
* @uses \ITSEC_Lib_Config_File::get_server_config_file_path()
|
764 |
+
*/
|
765 |
+
private function file_permissions() {
|
766 |
|
767 |
+
require_once \ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php';
|
768 |
+
|
769 |
+
$wp_upload_dir = \ITSEC_Core::get_wp_upload_dir();
|
770 |
|
771 |
$path_data = array(
|
772 |
array(
|
795 |
),
|
796 |
array(
|
797 |
WP_PLUGIN_DIR,
|
798 |
+
0755,
|
799 |
),
|
800 |
array(
|
801 |
$wp_upload_dir['basedir'],
|
802 |
0755,
|
803 |
),
|
804 |
array(
|
805 |
+
\ITSEC_Lib_Config_File::get_wp_config_file_path(),
|
806 |
0444,
|
807 |
),
|
808 |
array(
|
809 |
+
\ITSEC_Lib_Config_File::get_server_config_file_path(),
|
810 |
0444,
|
811 |
),
|
812 |
);
|
813 |
|
|
|
814 |
$rows = array();
|
815 |
|
816 |
foreach ( $path_data as $path ) {
|
829 |
$row[] = sprintf( '%o', $suggested_permissions );
|
830 |
|
831 |
$permissions = fileperms( $path ) & 0777;
|
832 |
+
$row[] = sprintf( '%o', $permissions );
|
833 |
|
834 |
if ( ! $permissions || $permissions != $suggested_permissions ) {
|
835 |
+
$row[] = __( 'WARNING', 'mainwp-child' );
|
836 |
$row[] = '<div style="background-color: #FEFF7F; border: 1px solid #E2E2E2;"> </div>';
|
837 |
} else {
|
838 |
+
$row[] = __( 'OK', 'mainwp-child' );
|
839 |
$row[] = '<div style="background-color: #22EE5B; border: 1px solid #E2E2E2;"> </div>';
|
840 |
}
|
841 |
|
842 |
$rows[] = $row;
|
843 |
}
|
844 |
|
|
|
845 |
$class = 'entry-row';
|
846 |
+
ob_start();
|
847 |
+
?>
|
848 |
+
<p><input type="button" id="itsec-file-permissions-reload_file_permissions" name="file-permissions[reload_file_permissions]" class="button-primary itsec-reload-module" value="<?php esc_attr_e( 'Reload File Permissions Details', 'mainwp-child' ); ?>"></p>
|
849 |
<table class="widefat">
|
850 |
<thead>
|
851 |
<tr>
|
852 |
+
<th><?php esc_html_e( 'Relative Path', 'mainwp-child' ); ?></th>
|
853 |
+
<th><?php esc_html_e( 'Suggestion', 'mainwp-child' ); ?></th>
|
854 |
+
<th><?php esc_html_e( 'Value', 'mainwp-child' ); ?></th>
|
855 |
+
<th><?php esc_html_e( 'Result', 'mainwp-child' ); ?></th>
|
856 |
+
<th><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
857 |
</tr>
|
858 |
</thead>
|
859 |
<tfoot>
|
860 |
<tr>
|
861 |
+
<th><?php esc_html_e( 'Relative Path', 'mainwp-child' ); ?></th>
|
862 |
+
<th><?php esc_html_e( 'Suggestion', 'mainwp-child' ); ?></th>
|
863 |
+
<th><?php esc_html_e( 'Value', 'mainwp-child' ); ?></th>
|
864 |
+
<th><?php esc_html_e( 'Result', 'mainwp-child' ); ?></th>
|
865 |
+
<th><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
866 |
</tr>
|
867 |
</tfoot>
|
868 |
<tbody>
|
877 |
</tbody>
|
878 |
</table>
|
879 |
<br />
|
880 |
+
<?php
|
881 |
$html = ob_get_clean();
|
882 |
+
return array( 'html' => $html );
|
883 |
}
|
884 |
|
885 |
+
/**
|
886 |
+
* Run File Change scanner.
|
887 |
+
*
|
888 |
+
* @return array $return results array.
|
889 |
+
*
|
890 |
+
* @uses \ITSEC_File_Change_Scanner::run_scan()
|
891 |
+
*/
|
892 |
+
public function file_change() {
|
893 |
+
|
894 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
895 |
global $mainwp_itsec_modules_path;
|
896 |
+
|
897 |
+
if ( ! class_exists( '\ITSEC_File_Change_Scanner' ) ) {
|
898 |
+
require_once $mainwp_itsec_modules_path . 'file-change/scanner.php';
|
899 |
}
|
900 |
+
$result = \ITSEC_File_Change_Scanner::run_scan( false );
|
901 |
+
if ( false === $result || true === $result || -1 === $result ) {
|
902 |
+
$return['result'] = 'success';
|
903 |
$return['scan_result'] = $result;
|
904 |
}
|
905 |
return $return;
|
906 |
}
|
907 |
|
908 |
+
/**
|
909 |
+
* Update admin user.
|
910 |
+
*
|
911 |
+
* @return array Return Success or Fail.
|
912 |
+
*
|
913 |
+
* @uses \ITSEC_Lib::user_id_exists()
|
914 |
+
* @uses MainWP_Child_IThemes_Security::change_admin_user()
|
915 |
+
*/
|
916 |
+
public function admin_user() {
|
917 |
|
918 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
919 |
|
920 |
+
if ( ! is_array( $settings ) ) {
|
921 |
$settings = array();
|
922 |
+
}
|
923 |
|
924 |
+
$new_username = isset( $settings['new_username'] ) ? $settings['new_username'] : '';
|
925 |
+
$change_id = isset( $settings['change_id'] ) && $settings['change_id'] ? true : false;
|
926 |
|
927 |
+
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
928 |
|
929 |
+
/** @global object $itsec_globals ITsec globals. */
|
|
|
930 |
global $itsec_globals;
|
931 |
+
|
932 |
+
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
933 |
}
|
934 |
|
935 |
$username_exists = username_exists( 'admin' );
|
936 |
+
$user_id_exists = \ITSEC_Lib::user_id_exists( 1 );
|
937 |
$msg = '';
|
938 |
+
if ( strlen( $new_username ) >= 1 ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
939 |
|
940 |
+
/** @global string $current_user Current user global variable. */
|
941 |
+
global $current_user;
|
942 |
+
|
943 |
+
if ( ! $username_exists ) {
|
944 |
+
$msg = __( 'Admin user already changes.', 'mainwp-child' );
|
945 |
+
} elseif ( 'admin' == $current_user->user_login ) {
|
946 |
+
$return['result'] = 'CHILD_ADMIN';
|
947 |
+
return $return;
|
948 |
+
}
|
949 |
+
}
|
950 |
|
951 |
if ( true === $change_id && ! $user_id_exists ) {
|
952 |
if ( ! empty( $msg ) ) {
|
955 |
$msg .= __( 'Admin user ID already changes.', 'mainwp-child' );
|
956 |
}
|
957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
958 |
$admin_success = true;
|
959 |
+
$return = array();
|
960 |
|
961 |
if ( strlen( $new_username ) >= 1 && $username_exists ) {
|
962 |
$admin_success = $this->change_admin_user( $new_username, $change_id );
|
973 |
return $return;
|
974 |
}
|
975 |
|
976 |
+
/**
|
977 |
+
* Change admin user.
|
978 |
+
*
|
979 |
+
* @param string $username Username to update to. Default: null.
|
980 |
+
* @param bool $id User Id found. Default: false.
|
981 |
+
* @return bool Return TRUE on success and FALSE on failure.
|
982 |
+
*
|
983 |
+
* @uses \ITSEC_Core::get_itsec_files()
|
984 |
+
* @uses \ITSEC_Core::get_itsec_files::release_file_lock()
|
985 |
+
*/
|
986 |
+
private function change_admin_user($username = null, $id = false ) {
|
987 |
+
|
988 |
+
/** @global object $wpdb WordPress Database */
|
989 |
global $wpdb;
|
|
|
990 |
|
991 |
+
$itsec_files = \ITSEC_Core::get_itsec_files();
|
|
|
992 |
|
|
|
993 |
$new_user = sanitize_text_field( $username );
|
994 |
|
|
|
995 |
$user_object = get_user_by( 'id', '1' );
|
996 |
|
997 |
+
if ( null !== $username && validate_username( $new_user ) && false === username_exists( $new_user ) ) {
|
|
|
|
|
998 |
|
999 |
+
if ( true === $id ) {
|
1000 |
|
1001 |
+
$user_login = $new_user;
|
1002 |
|
1003 |
+
} else {
|
|
|
1004 |
|
1005 |
+
$wpdb->query( 'UPDATE `' . $wpdb->users . "` SET user_login = '" . esc_sql( $new_user ) . "' WHERE user_login='admin';" );
|
1006 |
|
1007 |
+
if ( is_multisite() ) {
|
1008 |
+
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
|
1009 |
+
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
|
1010 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = %s WHERE meta_key = 'site_admins'", $newAdmins ) );
|
1011 |
+
}
|
1012 |
|
1013 |
+
wp_clear_auth_cookie();
|
1014 |
+
$itsec_files->release_file_lock( 'admin_user' );
|
1015 |
|
1016 |
+
return true;
|
1017 |
|
1018 |
+
}
|
1019 |
+
} elseif ( null !== $username ) {
|
1020 |
|
1021 |
+
$itsec_files->release_file_lock( 'admin_user' );
|
1022 |
|
1023 |
+
return false;
|
1024 |
|
1025 |
+
} else {
|
1026 |
|
1027 |
+
$user_login = $user_object->user_login;
|
1028 |
|
1029 |
+
}
|
1030 |
|
1031 |
+
if ( true === $id ) {
|
1032 |
|
1033 |
+
$wpdb->query( 'DELETE FROM `' . $wpdb->users . '` WHERE ID = 1;' );
|
1034 |
|
1035 |
+
$wpdb->insert(
|
1036 |
+
$wpdb->users,
|
1037 |
+
array(
|
1038 |
'user_login' => $user_login,
|
1039 |
'user_pass' => $user_object->user_pass,
|
1040 |
'user_nicename' => $user_object->user_nicename,
|
1044 |
'user_activation_key' => $user_object->user_activation_key,
|
1045 |
'user_status' => $user_object->user_status,
|
1046 |
'display_name' => $user_object->display_name,
|
1047 |
+
)
|
1048 |
+
);
|
1049 |
|
1050 |
+
if ( is_multisite() && null !== $username && validate_username( $new_user ) ) {
|
1051 |
|
1052 |
+
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
|
1053 |
+
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
|
1054 |
+
$wpdb->query( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = '" . esc_sql( $newAdmins ) . "' WHERE meta_key = 'site_admins'" );
|
1055 |
|
1056 |
+
}
|
1057 |
|
1058 |
+
$new_user = $wpdb->insert_id;
|
1059 |
|
1060 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->posts . '` SET post_author = %s WHERE post_author = 1;', $new_user ) );
|
1061 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->usermeta . '` SET user_id = %s WHERE user_id = 1;', $new_user ) );
|
1062 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->comments . '` SET user_id = %s WHERE user_id = 1;', $new_user ) );
|
1063 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->links . '` SET link_owner = %s WHERE link_owner = 1;', $new_user ) );
|
1064 |
|
1065 |
+
wp_clear_auth_cookie();
|
1066 |
+
$itsec_files->release_file_lock( 'admin_user' );
|
1067 |
|
1068 |
+
return true;
|
1069 |
|
1070 |
+
}
|
|
|
1071 |
|
1072 |
return false;
|
|
|
1073 |
}
|
1074 |
|
1075 |
+
/**
|
1076 |
+
* Build WP_config rules.
|
1077 |
+
*
|
1078 |
+
* @param array $rules_array Config rules array.
|
1079 |
+
* @param null $input New directory input.
|
1080 |
+
*
|
1081 |
+
* @return array Return $rules_array.
|
1082 |
+
*/
|
1083 |
+
public function build_wpconfig_rules( $rules_array, $input = null ) {
|
1084 |
if ( null === $input ) {
|
1085 |
return $rules_array;
|
1086 |
}
|
1105 |
'rule' => "define( 'WP_CONTENT_DIR', '" . $new_dir . "' );",
|
1106 |
);
|
1107 |
|
1108 |
+
$rules_array[] = array(
|
1109 |
+
'type' => 'wpconfig',
|
1110 |
+
'name' => 'Content Directory',
|
1111 |
+
'rules' => $rules,
|
1112 |
+
);
|
1113 |
|
1114 |
return $rules_array;
|
|
|
1115 |
}
|
1116 |
|
1117 |
|
1118 |
+
/**
|
1119 |
+
* Change database prefix.
|
1120 |
+
*
|
1121 |
+
* @return array $return Return response array.
|
1122 |
+
*
|
1123 |
+
* @uses \ITSEC_Database_Prefix_Utility::change_database_prefix()
|
1124 |
+
* @uses \ITSEC_Response::get_error_strings()
|
1125 |
+
* @uses \ITSEC_Response::reload_module()
|
1126 |
+
*/
|
1127 |
+
public function change_database_prefix() {
|
1128 |
+
|
1129 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1130 |
global $mainwp_itsec_modules_path;
|
1131 |
+
|
1132 |
+
require_once $mainwp_itsec_modules_path . 'database-prefix/utility.php';
|
1133 |
$str_error = '';
|
1134 |
+
$return = array();
|
1135 |
|
1136 |
if ( isset( $_POST['change_prefix'] ) && 'yes' === $_POST['change_prefix'] ) {
|
1137 |
+
$result = \ITSEC_Database_Prefix_Utility::change_database_prefix();
|
1138 |
$return = $result['errors'];
|
1139 |
+
if ( is_array( $result['errors'] ) ) {
|
1140 |
+
foreach ( $result['errors'] as $error ) {
|
1141 |
+
$arr_errors = \ITSEC_Response::get_error_strings( $error );
|
1142 |
foreach ( $arr_errors as $er ) {
|
1143 |
$str_error .= $er . '<br />';
|
1144 |
}
|
1145 |
}
|
1146 |
}
|
1147 |
|
1148 |
+
\ITSEC_Response::reload_module( 'database-prefix' );
|
1149 |
|
1150 |
if ( false === $result['new_prefix'] ) {
|
1151 |
$return['error'] = $str_error;
|
1152 |
} else {
|
1153 |
+
$return['result'] = 'success';
|
1154 |
+
$return['message'] = sprintf( __( 'The database table prefix was successfully changed to <code>%1$s</code>.', 'mainwp-child' ), $result['new_prefix'] );
|
1155 |
|
1156 |
}
|
1157 |
}
|
1158 |
return $return;
|
1159 |
}
|
1160 |
|
1161 |
+
/**
|
1162 |
+
* Update API key.
|
1163 |
+
*
|
1164 |
+
* @return array $return Return response array. Success or nochange.
|
1165 |
+
*/
|
1166 |
+
public function api_key() {
|
1167 |
$settings = get_site_option( 'itsec_ipcheck' );
|
1168 |
if ( ! is_array( $settings ) ) {
|
1169 |
$settings = array();
|
1170 |
}
|
1171 |
$settings['reset'] = true;
|
1172 |
+
$return = array();
|
1173 |
if ( update_site_option( 'itsec_ipcheck', $settings ) ) {
|
1174 |
$return['result'] = 'success';
|
1175 |
} else {
|
1179 |
return $return;
|
1180 |
}
|
1181 |
|
1182 |
+
/**
|
1183 |
+
* Reset api key.
|
1184 |
+
*
|
1185 |
+
* @return array $information Return response array.
|
1186 |
+
*
|
1187 |
+
* @uses \ITSEC_Modules::get_defaults()
|
1188 |
+
* @uses \ITSEC_Modules::set_defaults()
|
1189 |
+
* @uses \ITSEC_Response::set_response()
|
1190 |
+
* @uses \ITSEC_Response::add_errors()
|
1191 |
+
* @uses \ITSEC_Response::add_messages()
|
1192 |
+
*/
|
1193 |
+
public function reset_api_key() {
|
1194 |
+
|
1195 |
+
$defaults = \ITSEC_Modules::get_defaults( 'network-brute-force' );
|
1196 |
+
$results = \ITSEC_Modules::set_settings( 'network-brute-force', $defaults );
|
1197 |
+
|
1198 |
+
\ITSEC_Response::set_response( $results['saved'] );
|
1199 |
+
\ITSEC_Response::add_errors( $results['errors'] );
|
1200 |
+
\ITSEC_Response::add_messages( $results['messages'] );
|
1201 |
|
1202 |
$information = array();
|
1203 |
if ( $results['saved'] ) {
|
1204 |
+
$information['result'] = 'success';
|
1205 |
+
$information['nbf_settings'] = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
1206 |
+
} elseif ( empty( $results['errors'] ) ) {
|
1207 |
$information['error_reset_api'] = 1;
|
1208 |
}
|
1209 |
return $information;
|
1210 |
}
|
1211 |
|
1212 |
+
/**
|
1213 |
+
* Malware scan.
|
1214 |
+
*
|
1215 |
+
* @return array $response Return response array.
|
1216 |
+
*
|
1217 |
+
* @uses \ITSEC_Core::current_user_can_manage()
|
1218 |
+
* @uses \ITSEC_Malware_Scanner::scan()
|
1219 |
+
* @uses \ITSEC_Malware_Scan_Results_Template::get_html()
|
1220 |
+
*/
|
1221 |
+
public function malware_scan() {
|
1222 |
+
|
1223 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1224 |
global $mainwp_itsec_modules_path;
|
1225 |
|
1226 |
+
if ( ! class_exists( '\ITSEC_Malware_Scanner' ) ) {
|
1227 |
+
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php';
|
1228 |
+
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php';
|
1229 |
}
|
1230 |
|
1231 |
$response = array();
|
1232 |
+
if ( ! \ITSEC_Core::current_user_can_manage() ) {
|
1233 |
$response['error'] = 'The currently logged in user does not have sufficient permissions to run this scan.';
|
1234 |
} else {
|
1235 |
+
$results = \ITSEC_Malware_Scanner::scan();
|
1236 |
+
$response['html'] = \ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
|
1237 |
}
|
1238 |
|
1239 |
return $response;
|
1240 |
}
|
1241 |
|
1242 |
+
/**
|
1243 |
+
* Get malware scan results.
|
1244 |
+
*
|
1245 |
+
* @return array $response Return response array.
|
1246 |
+
*
|
1247 |
+
* @uses \ITSEC_Malware_Scanner::scan()
|
1248 |
+
* @uses \ITSEC_Malware_Scan_Results_Template::get_html()
|
1249 |
+
*/
|
1250 |
+
public function malware_get_scan_results() {
|
1251 |
+
|
1252 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1253 |
global $mainwp_itsec_modules_path;
|
1254 |
+
|
1255 |
+
if ( ! class_exists( '\ITSEC_Malware_Scanner' ) ) {
|
1256 |
+
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php';
|
1257 |
+
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php';
|
1258 |
}
|
1259 |
+
$response = array();
|
1260 |
+
$results = \ITSEC_Malware_Scanner::scan();
|
1261 |
+
$response['html'] = \ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
|
1262 |
return $response;
|
1263 |
}
|
1264 |
|
1265 |
+
/**
|
1266 |
+
* Purge logs.
|
1267 |
+
*
|
1268 |
+
* @return string[] Return response array.
|
1269 |
+
*/
|
1270 |
+
public function purge_logs() {
|
1271 |
+
|
1272 |
+
/** @global object $wpdb WordPress Database object. */
|
1273 |
global $wpdb;
|
1274 |
+
|
1275 |
$wpdb->query( 'DELETE FROM `' . $wpdb->base_prefix . 'itsec_log`;' );
|
1276 |
|
1277 |
return array( 'result' => 'success' );
|
1278 |
}
|
1279 |
|
1280 |
|
1281 |
+
/**
|
1282 |
+
* Get lockouts.
|
1283 |
+
*
|
1284 |
+
* @param string $type Type of lockout: Host, user, username, Default: all.
|
1285 |
+
* @param bool $current TRUE if current. Default: FALSE.
|
1286 |
+
*
|
1287 |
+
* @return array $output Return response array.
|
1288 |
+
*
|
1289 |
+
* @uses MainWP_Child_IThemes_Security::get_lockouts_int()
|
1290 |
+
*/
|
1291 |
+
public function get_lockouts( $type = 'all', $current = false ) {
|
1292 |
+
|
1293 |
+
/**
|
1294 |
+
* @global object $wpdb WordPress Database object.
|
1295 |
+
* @global object $itsec_globals itsec globals.
|
1296 |
+
*/
|
1297 |
global $wpdb, $itsec_globals;
|
1298 |
|
1299 |
if ( 'all' !== $type || true === $current ) {
|
1327 |
$and = '';
|
1328 |
}
|
1329 |
|
1330 |
+
$active = $and . " `lockout_active`=1 AND `lockout_expire_gmt` > '" . gmdate( 'Y-m-d H:i:s', $itsec_globals['current_time_gmt'] ) . "'";
|
1331 |
|
1332 |
} else {
|
1333 |
|
1334 |
$active = '';
|
1335 |
|
1336 |
}
|
1337 |
+
$results = $wpdb->get_results( 'SELECT * FROM `' . $wpdb->base_prefix . 'itsec_lockouts`' . $where . $type_statement . $active . ';', ARRAY_A ); // phpcs:ignore -- safe query. $output = array();
|
1338 |
+
|
1339 |
+
return $this->get_lockouts_int( $results, $type );
|
1340 |
+
}
|
1341 |
+
|
1342 |
+
/**
|
1343 |
+
* Initiate get lockouts.
|
1344 |
+
*
|
1345 |
+
* @param array $results Results from MainWP_Child_IThemes_Security::get_lockouts()
|
1346 |
+
* @param string $type Type of lockout: Host, user, username, Default: all.
|
1347 |
+
*
|
1348 |
+
* @return array $output Return response array.
|
1349 |
+
*/
|
1350 |
+
private function get_lockouts_int($results, $type ){
|
1351 |
|
|
|
|
|
1352 |
if ( is_array( $results ) && count( $results ) > 0 ) {
|
1353 |
switch ( $type ) {
|
1354 |
case 'host':
|
1384 |
}
|
1385 |
|
1386 |
return $output;
|
1387 |
+
|
1388 |
}
|
1389 |
|
1390 |
+
/**
|
1391 |
+
* Release lockout.
|
1392 |
+
*
|
1393 |
+
* @return string[] Return results array.
|
1394 |
+
*
|
1395 |
+
* @uses \ITSEC_Lib::clear_caches()
|
1396 |
+
*/
|
1397 |
+
public function release_lockout() {
|
1398 |
+
|
1399 |
+
/** @global object $wpdb WordPress Database. */
|
1400 |
global $wpdb;
|
1401 |
|
1402 |
+
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
1403 |
+
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
1404 |
}
|
1405 |
|
1406 |
+
$lockout_ids = array_map( 'sanitize_text_field', wp_unslash( $_POST['lockout_ids'] ) );
|
1407 |
if ( ! is_array( $lockout_ids ) ) {
|
1408 |
$lockout_ids = array();
|
1409 |
}
|
1410 |
|
1411 |
$type = 'updated';
|
1412 |
+
$message = __( 'The selected lockouts have been cleared.', 'mainwp-child' );
|
1413 |
|
1414 |
foreach ( $lockout_ids as $value ) {
|
1415 |
$wpdb->update(
|
1423 |
);
|
1424 |
}
|
1425 |
|
1426 |
+
\ITSEC_Lib::clear_caches();
|
1427 |
|
1428 |
if ( ! is_multisite() ) {
|
1429 |
if ( ! function_exists( 'add_settings_error' ) ) {
|
1430 |
+
require_once ABSPATH . '/wp-admin/includes/template.php';
|
1431 |
}
|
1432 |
|
1433 |
add_settings_error( 'itsec', esc_attr( 'settings_updated' ), $message, $type );
|
1438 |
);
|
1439 |
}
|
1440 |
|
1441 |
+
/**
|
1442 |
+
* Update module status.
|
1443 |
+
*
|
1444 |
+
* @return string[] Return response array.
|
1445 |
+
*/
|
1446 |
+
public function update_module_status() {
|
1447 |
|
1448 |
+
$active_modules = isset( $_POST['active_modules'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['active_modules'] ) ) : array();
|
1449 |
|
1450 |
+
if ( ! is_array( $active_modules ) ) {
|
1451 |
$active_modules = array();
|
1452 |
+
}
|
1453 |
|
1454 |
+
$current_val = get_site_option( 'itsec_active_modules', array() );
|
1455 |
+
foreach ( $active_modules as $mod => $val ) {
|
1456 |
+
$current_val[ $mod ] = $val;
|
1457 |
+
}
|
1458 |
|
1459 |
update_site_option( 'itsec_active_modules', $current_val );
|
1460 |
+
return array( 'result' => 'success' );
|
|
|
1461 |
}
|
1462 |
|
1463 |
+
/**
|
1464 |
+
* Reload excluded backups table.
|
1465 |
+
*
|
1466 |
+
* @return array Return response array.
|
1467 |
+
*
|
1468 |
+
* @uses \ITSEC_Modules::get_setting()
|
1469 |
+
* @uses MainWP_Child_IThemes_Security::get_excludable_tables()
|
1470 |
+
*/
|
1471 |
+
private function reload_backup_exclude() {
|
1472 |
return array(
|
1473 |
+
'exclude' => \ITSEC_Modules::get_setting( 'backup', 'exclude' ),
|
1474 |
'excludable_tables' => $this->get_excludable_tables(),
|
1475 |
+
'result' => 'success',
|
1476 |
);
|
1477 |
}
|
1478 |
|
1479 |
+
/**
|
1480 |
+
* Get excludable backups table.
|
1481 |
+
*
|
1482 |
+
* @return array $excludes Return response array.
|
1483 |
+
*
|
1484 |
+
* @uses \ITSEC_Modules::get_setting()
|
1485 |
+
*/
|
1486 |
+
private function get_excludable_tables() {
|
1487 |
+
|
1488 |
+
/** @global object $wpdb WordPress Database. */
|
1489 |
global $wpdb;
|
1490 |
+
|
1491 |
+
$all_sites = \ITSEC_Modules::get_setting( 'backup', 'all_sites' );
|
1492 |
$ignored_tables = array(
|
1493 |
'commentmeta',
|
1494 |
'comments',
|
1509 |
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', "{$wpdb->base_prefix}%" );
|
1510 |
}
|
1511 |
|
1512 |
+
$tables = $wpdb->get_results( $query, ARRAY_N ); // phpcs:ignore -- safe query.
|
1513 |
$excludes = array();
|
1514 |
|
1515 |
foreach ( $tables as $table ) {
|
1519 |
continue;
|
1520 |
}
|
1521 |
|
1522 |
+
$excludes[ $short_table ] = $table[0];
|
1523 |
}
|
1524 |
|
1525 |
+
return $excludes;
|
1526 |
}
|
1527 |
|
1528 |
+
/**
|
1529 |
+
* Get security check results.
|
1530 |
+
*
|
1531 |
+
* @return array Return response array.
|
1532 |
+
*
|
1533 |
+
* @uses \ITSEC_Security_Check_Scanner::get_results()
|
1534 |
+
* @uses \ITSEC_Security_Check_Feedback_Renderer::render(
|
1535 |
+
*/
|
1536 |
private function security_site() {
|
1537 |
+
|
1538 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1539 |
global $mainwp_itsec_modules_path;
|
1540 |
+
|
1541 |
+
require_once $mainwp_itsec_modules_path . 'security-check/scanner.php';
|
1542 |
+
require_once $mainwp_itsec_modules_path . 'security-check/feedback-renderer.php';
|
1543 |
+
$results = \ITSEC_Security_Check_Scanner::get_results();
|
1544 |
+
ob_start();
|
1545 |
+
\ITSEC_Security_Check_Feedback_Renderer::render( $results );
|
1546 |
$response = ob_get_clean();
|
1547 |
+
return array(
|
1548 |
+
'result' => 'success',
|
1549 |
+
'response' => $response,
|
1550 |
+
);
|
1551 |
}
|
1552 |
|
1553 |
+
/**
|
1554 |
+
* Get available admin users and roles.
|
1555 |
+
*
|
1556 |
+
* @return array[] Return response array.phpdoc
|
1557 |
+
*
|
1558 |
+
* @uses \WP_Roles()
|
1559 |
+
*/
|
1560 |
public function get_available_admin_users_and_roles() {
|
1561 |
if ( is_callable( 'wp_roles' ) ) {
|
1562 |
$roles = wp_roles();
|
1563 |
} else {
|
1564 |
+
$roles = new \WP_Roles();
|
1565 |
}
|
1566 |
|
1567 |
$available_roles = array();
|
1569 |
|
1570 |
foreach ( $roles->roles as $role => $details ) {
|
1571 |
if ( isset( $details['capabilities']['manage_options'] ) && ( true === $details['capabilities']['manage_options'] ) ) {
|
1572 |
+
$available_roles[ "role:$role" ] = translate_user_role( $details['name'] );
|
1573 |
|
1574 |
$users = get_users( array( 'role' => $role ) );
|
1575 |
|
1576 |
foreach ( $users as $user ) {
|
1577 |
/* translators: 1: user display name, 2: user login */
|
1578 |
+
$available_users[ $user->ID ] = sprintf( __( '%1$s (%2$s)', 'mainwp-child' ), $user->display_name, $user->user_login );
|
1579 |
}
|
1580 |
}
|
1581 |
}
|
1589 |
}
|
1590 |
|
1591 |
}
|
|
class/class-mainwp-child-links-checker.php
CHANGED
@@ -1,44 +1,88 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
|
|
|
|
4 |
*
|
|
|
|
|
|
|
|
|
|
|
5 |
* Credits
|
6 |
*
|
7 |
* Plugin-Name: Broken Link Checker
|
8 |
* Plugin URI: https://wordpress.org/plugins/broken-link-checker/
|
9 |
* Author: Janis Elsts, Vladimir Prelovac
|
10 |
*
|
11 |
-
* The code is used for the MainWP Broken Links Checker Extension
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
|
|
|
|
|
|
|
16 |
class MainWP_Child_Links_Checker {
|
17 |
|
|
|
|
|
|
|
|
|
18 |
public static $instance = null;
|
19 |
-
public $is_plugin_installed = false;
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
}
|
25 |
|
26 |
-
return
|
27 |
}
|
28 |
|
|
|
|
|
|
|
|
|
|
|
29 |
public function __construct() {
|
30 |
-
|
31 |
if ( is_plugin_active( 'broken-link-checker/broken-link-checker.php' ) ) {
|
32 |
-
|
33 |
}
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
|
39 |
|
|
|
40 |
}
|
41 |
|
|
|
|
|
|
|
|
|
42 |
public function action() {
|
43 |
$information = array();
|
44 |
if ( ! defined( 'BLC_ACTIVE' ) || ! function_exists( 'blc_init' ) ) {
|
@@ -47,47 +91,49 @@ class MainWP_Child_Links_Checker {
|
|
47 |
}
|
48 |
blc_init();
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
}
|
89 |
|
90 |
-
|
|
|
|
|
91 |
public function init() {
|
92 |
if ( get_option( 'mainwp_linkschecker_ext_enabled' ) !== 'Y' ) {
|
93 |
return;
|
@@ -99,6 +145,11 @@ class MainWP_Child_Links_Checker {
|
|
99 |
}
|
100 |
}
|
101 |
|
|
|
|
|
|
|
|
|
|
|
102 |
public static function hook_trashed_comment( $comment_id ) {
|
103 |
if ( get_option( 'mainwp_linkschecker_ext_enabled' ) !== 'Y' ) {
|
104 |
return;
|
@@ -108,14 +159,19 @@ class MainWP_Child_Links_Checker {
|
|
108 |
return;
|
109 |
}
|
110 |
blc_init();
|
111 |
-
$container = blcContainerHelper::get_container( array( 'comment', $comment_id ) );
|
112 |
$container->delete();
|
113 |
blc_cleanup_links();
|
114 |
}
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
119 |
if ( $check_threshold > 0 ) {
|
120 |
$conf = blc_get_configuration();
|
121 |
$conf->options['check_threshold'] = $check_threshold;
|
@@ -125,7 +181,12 @@ class MainWP_Child_Links_Checker {
|
|
125 |
return $information;
|
126 |
}
|
127 |
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
129 |
$this->initiate_recheck();
|
130 |
$information = array();
|
131 |
$information['result'] = 'SUCCESS';
|
@@ -133,21 +194,30 @@ class MainWP_Child_Links_Checker {
|
|
133 |
return $information;
|
134 |
}
|
135 |
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
137 |
global $wpdb;
|
138 |
-
/** @var wpdb $wpdb */
|
139 |
|
140 |
-
//Delete all discovered instances
|
141 |
$wpdb->query( "TRUNCATE {$wpdb->prefix}blc_instances" );
|
142 |
|
143 |
-
//Delete all discovered links
|
144 |
$wpdb->query( "TRUNCATE {$wpdb->prefix}blc_links" );
|
145 |
|
146 |
-
//Mark all posts, custom fields and bookmarks for processing.
|
147 |
blc_resynch( true );
|
148 |
}
|
149 |
|
150 |
|
|
|
|
|
|
|
|
|
|
|
151 |
public static function hook_post_deleted( $post_id ) {
|
152 |
if ( get_option( 'mainwp_linkschecker_ext_enabled' ) !== 'Y' ) {
|
153 |
return;
|
@@ -158,23 +228,29 @@ class MainWP_Child_Links_Checker {
|
|
158 |
}
|
159 |
blc_init();
|
160 |
|
161 |
-
//Get the container type matching the type of the deleted post
|
162 |
$post = get_post( $post_id );
|
163 |
if ( ! $post ) {
|
164 |
return;
|
165 |
}
|
166 |
-
//Get the associated container object
|
167 |
-
$post_container = blcContainerHelper::get_container( array( $post->post_type, intval( $post_id ) ) );
|
168 |
|
169 |
if ( $post_container ) {
|
170 |
-
//Delete it
|
171 |
$post_container->delete();
|
172 |
-
//Clean up any dangling links
|
173 |
blc_cleanup_links();
|
174 |
}
|
175 |
}
|
176 |
|
177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
public function hide_plugin( $plugins ) {
|
179 |
foreach ( $plugins as $key => $value ) {
|
180 |
$plugin_slug = basename( $key, '.php' );
|
@@ -186,7 +262,13 @@ class MainWP_Child_Links_Checker {
|
|
186 |
return $plugins;
|
187 |
}
|
188 |
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
?>
|
191 |
<script>
|
192 |
jQuery( document ).ready( function () {
|
@@ -199,7 +281,12 @@ class MainWP_Child_Links_Checker {
|
|
199 |
}
|
200 |
|
201 |
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
203 |
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
204 |
MainWP_Helper::update_option( 'mainwp_linkschecker_hide_plugin', $hide );
|
205 |
$information['result'] = 'SUCCESS';
|
@@ -207,121 +294,155 @@ class MainWP_Child_Links_Checker {
|
|
207 |
return $information;
|
208 |
}
|
209 |
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
return $information;
|
220 |
}
|
221 |
|
222 |
-
|
223 |
-
|
|
|
|
|
|
|
|
|
|
|
224 |
$information = array();
|
225 |
$data = $this->get_count_links();
|
226 |
-
|
227 |
-
|
|
|
228 |
return $information;
|
229 |
}
|
230 |
|
231 |
-
|
232 |
-
|
233 |
-
|
|
|
|
|
|
|
|
|
234 |
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
|
239 |
-
|
240 |
-
|
|
|
241 |
|
242 |
-
|
243 |
-
|
244 |
|
245 |
-
|
|
|
246 |
|
247 |
-
|
248 |
|
249 |
-
|
250 |
|
|
|
251 |
|
252 |
-
$max_results = isset($_POST['max_results']) ? intval($_POST['max_results']) : 50;
|
253 |
-
$offset
|
254 |
|
255 |
-
$params
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
|
260 |
-
if (empty($offset)) {
|
261 |
$first_sync = true;
|
262 |
} else {
|
263 |
$params['offset'] = $offset;
|
264 |
}
|
265 |
|
266 |
-
$link_data = $this->links_checker_data($params);
|
267 |
|
268 |
$total_sync = 0;
|
269 |
-
if ($offset){
|
270 |
$total_sync = $offset;
|
271 |
}
|
272 |
-
$total_sync += (is_array($link_data) ? count($link_data) : 0);
|
273 |
|
274 |
-
$information = array('links_data' => $link_data);
|
275 |
|
276 |
-
if ($first_sync) {
|
277 |
$information['data'] = $this->get_count_links();
|
278 |
}
|
279 |
|
280 |
-
if ($total > $offset + $max_results ) {
|
281 |
$information['sync_offset'] = $offset + $max_results;
|
282 |
} else {
|
283 |
-
$information['last_sync']
|
284 |
$information['total_sync'] = $total_sync;
|
285 |
-
$information['data']
|
286 |
}
|
287 |
|
288 |
$information['result'] = 'success';
|
289 |
return $information;
|
290 |
}
|
291 |
|
292 |
-
|
293 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
|
295 |
-
|
296 |
-
|
297 |
|
298 |
-
|
299 |
|
300 |
-
|
301 |
-
|
302 |
|
303 |
-
|
304 |
-
|
305 |
|
306 |
-
$data
|
307 |
-
$blc_link_query
|
308 |
|
309 |
-
|
310 |
|
311 |
-
$data['broken']
|
312 |
-
$data['redirects']
|
313 |
-
$data['dismissed']
|
314 |
$data['warning'] = $blc_link_query->get_filter_links( 'warning', array( 'count_only' => true ) );
|
315 |
-
$data['all']
|
316 |
return $data;
|
317 |
}
|
318 |
|
319 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
320 |
|
321 |
-
|
322 |
-
|
323 |
|
324 |
-
$links
|
325 |
|
326 |
$filter_fields = array(
|
327 |
'link_id',
|
@@ -341,13 +462,13 @@ class MainWP_Child_Links_Checker {
|
|
341 |
'last_success',
|
342 |
'may_recheck',
|
343 |
'false_positive',
|
344 |
-
//'result_hash',
|
345 |
'dismissed',
|
346 |
'status_text',
|
347 |
'status_code',
|
348 |
-
'log'
|
349 |
);
|
350 |
-
|
|
|
351 |
|
352 |
$blc_option = get_option( 'wsblc_options' );
|
353 |
|
@@ -357,7 +478,7 @@ class MainWP_Child_Links_Checker {
|
|
357 |
|
358 |
if ( is_array( $links ) ) {
|
359 |
foreach ( $links as $link ) {
|
360 |
-
$new_link = new stdClass();
|
361 |
foreach ( $filter_fields as $field ) {
|
362 |
$new_link->$field = $link->$field;
|
363 |
}
|
@@ -370,7 +491,7 @@ class MainWP_Child_Links_Checker {
|
|
370 |
|
371 |
$days_broken = 0;
|
372 |
if ( $link->broken ) {
|
373 |
-
//Add a highlight to broken links that appear to be permanently broken
|
374 |
$days_broken = intval( ( time() - $link->first_failure ) / ( 3600 * 24 ) );
|
375 |
if ( $days_broken >= $blc_option['failure_duration_threshold'] ) {
|
376 |
$extra_info['permanently_broken'] = 1;
|
@@ -380,33 +501,31 @@ class MainWP_Child_Links_Checker {
|
|
380 |
}
|
381 |
}
|
382 |
$extra_info['days_broken'] = $days_broken;
|
383 |
-
$instances
|
384 |
|
385 |
-
$get_link = new blcLink( intval( $link->link_id ) );
|
386 |
if ( $get_link->valid() ) {
|
387 |
-
|
388 |
$instances = $get_link->get_instances();
|
389 |
}
|
390 |
|
391 |
if ( ! empty( $instances ) ) {
|
392 |
-
|
393 |
|
394 |
-
|
395 |
|
396 |
-
$new_link->link_text
|
397 |
$extra_info['count_instance'] = count( $instances );
|
398 |
-
$container
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
}
|
409 |
-
}
|
410 |
}
|
411 |
|
412 |
$can_edit_text = false;
|
@@ -429,57 +548,62 @@ class MainWP_Child_Links_Checker {
|
|
429 |
$link_texts = $can_edit_text ? $editable_link_texts : $non_editable_link_texts;
|
430 |
$data_link_text = '';
|
431 |
if ( count( $link_texts ) === 1 ) {
|
432 |
-
//All instances have the same text - use it.
|
433 |
$link_text = key( $link_texts );
|
434 |
$data_link_text = esc_attr( $link_text );
|
435 |
}
|
436 |
$extra_info['data_link_text'] = $data_link_text;
|
437 |
-
$extra_info['can_edit_url']
|
438 |
-
$extra_info['can_edit_text']
|
439 |
} else {
|
440 |
-
$new_link->link_text
|
441 |
$extra_info['count_instance'] = 0;
|
442 |
}
|
443 |
-
$new_link->extra_info = base64_encode(serialize($extra_info));
|
444 |
-
$new_link->synced
|
445 |
-
$return[]
|
446 |
}
|
447 |
} else {
|
448 |
return array();
|
449 |
}
|
450 |
|
451 |
return $return;
|
452 |
-
|
453 |
}
|
454 |
|
455 |
-
|
|
|
|
|
|
|
|
|
|
|
456 |
$information = array();
|
457 |
if ( ! current_user_can( 'edit_others_posts' ) ) {
|
458 |
$information['error'] = 'NOTALLOW';
|
459 |
|
460 |
return $information;
|
461 |
}
|
462 |
-
|
463 |
-
$
|
|
|
|
|
|
|
464 |
if ( ! $link->valid() ) {
|
465 |
-
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link
|
466 |
return $information;
|
467 |
}
|
468 |
|
469 |
-
//Validate the new URL.
|
470 |
-
$new_url = stripslashes( $_POST['new_url'] );
|
471 |
$parsed = @parse_url( $new_url );
|
472 |
if ( ! $parsed ) {
|
473 |
$information['error'] = 'URLINVALID'; // Oops, the new URL is invalid!
|
474 |
return $information;
|
475 |
}
|
476 |
|
477 |
-
$new_text =
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
if ( ! empty( $new_text ) && ! current_user_can( 'unfiltered_html' ) ) {
|
482 |
-
$new_text = stripslashes( wp_filter_post_kses( addslashes( $new_text ) ) ); //wp_filter_post_kses expects slashed data.
|
483 |
}
|
484 |
|
485 |
$rez = $link->edit( $new_url, $new_text );
|
@@ -512,10 +636,9 @@ class MainWP_Child_Links_Checker {
|
|
512 |
'ui_link_text' => isset( $new_text ) ? $ui_link_text : null,
|
513 |
'errors' => array(),
|
514 |
);
|
515 |
-
//url, status text, status code, link text, editable link text
|
516 |
|
517 |
foreach ( $rez['errors'] as $error ) {
|
518 |
-
/** @var $error WP_Error */
|
519 |
array_push( $response['errors'], implode( ', ', $error->get_error_messages() ) );
|
520 |
}
|
521 |
|
@@ -523,7 +646,12 @@ class MainWP_Child_Links_Checker {
|
|
523 |
}
|
524 |
}
|
525 |
|
526 |
-
|
|
|
|
|
|
|
|
|
|
|
527 |
$information = array();
|
528 |
if ( ! current_user_can( 'edit_others_posts' ) ) {
|
529 |
$information['error'] = 'NOTALLOW';
|
@@ -532,15 +660,17 @@ class MainWP_Child_Links_Checker {
|
|
532 |
}
|
533 |
|
534 |
if ( isset( $_POST['link_id'] ) ) {
|
535 |
-
|
536 |
-
|
|
|
|
|
537 |
|
538 |
if ( ! $link->valid() ) {
|
539 |
-
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link
|
540 |
return $information;
|
541 |
}
|
542 |
|
543 |
-
//Try and unlink it
|
544 |
$rez = $link->unlink();
|
545 |
|
546 |
if ( false === $rez ) {
|
@@ -553,7 +683,7 @@ class MainWP_Child_Links_Checker {
|
|
553 |
'errors' => array(),
|
554 |
);
|
555 |
foreach ( $rez['errors'] as $error ) {
|
556 |
-
/** @var WP_Error $error */
|
557 |
array_push( $response['errors'], implode( ', ', $error->get_error_messages() ) );
|
558 |
}
|
559 |
|
@@ -566,9 +696,14 @@ class MainWP_Child_Links_Checker {
|
|
566 |
}
|
567 |
}
|
568 |
|
|
|
|
|
|
|
|
|
|
|
569 |
private function set_link_dismissed() {
|
570 |
$information = array();
|
571 |
-
$dismiss = $_POST['dismiss'];
|
572 |
|
573 |
if ( ! current_user_can( 'edit_others_posts' ) ) {
|
574 |
$information['error'] = 'NOTALLOW';
|
@@ -577,21 +712,23 @@ class MainWP_Child_Links_Checker {
|
|
577 |
}
|
578 |
|
579 |
if ( isset( $_POST['link_id'] ) ) {
|
580 |
-
|
581 |
-
|
|
|
|
|
582 |
|
583 |
if ( ! $link->valid() ) {
|
584 |
-
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link
|
585 |
return $information;
|
586 |
}
|
587 |
|
588 |
$link->dismissed = $dismiss;
|
589 |
|
590 |
-
//Save the changes
|
591 |
if ( $link->save() ) {
|
592 |
$information = 'OK';
|
593 |
} else {
|
594 |
-
$information['error'] = 'COULDNOTMODIFY'; // Oops, couldn't modify the link
|
595 |
}
|
596 |
|
597 |
return $information;
|
@@ -602,6 +739,11 @@ class MainWP_Child_Links_Checker {
|
|
602 |
}
|
603 |
}
|
604 |
|
|
|
|
|
|
|
|
|
|
|
605 |
private function discard() {
|
606 |
$information = array();
|
607 |
if ( ! current_user_can( 'edit_others_posts' ) ) {
|
@@ -610,26 +752,28 @@ class MainWP_Child_Links_Checker {
|
|
610 |
return $information;
|
611 |
}
|
612 |
if ( isset( $_POST['link_id'] ) ) {
|
613 |
-
|
614 |
-
|
|
|
|
|
615 |
|
616 |
if ( ! $link->valid() ) {
|
617 |
-
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link
|
618 |
return $information;
|
619 |
}
|
620 |
|
621 |
-
//Make it appear "not broken"
|
622 |
$link->broken = false;
|
623 |
$link->false_positive = true;
|
624 |
$link->last_check_attempt = time();
|
625 |
$link->log = __( 'This link was manually marked as working by the user.', 'mainwp-child' );
|
626 |
|
627 |
-
//Save the changes
|
628 |
if ( $link->save() ) {
|
629 |
$information['status'] = 'OK';
|
630 |
$information['last_check_attempt'] = $link->last_check_attempt;
|
631 |
} else {
|
632 |
-
$information['error'] = 'COULDNOTMODIFY'; // Oops, couldn't modify the link
|
633 |
}
|
634 |
} else {
|
635 |
$information['error'] = __( 'Error: link_id is not specified.', 'mainwp-child' );
|
@@ -638,32 +782,48 @@ class MainWP_Child_Links_Checker {
|
|
638 |
return $information;
|
639 |
}
|
640 |
|
641 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
642 |
if ( 'comment' === $container->container_type ) {
|
643 |
return $this->ui_get_source_comment( $container, $container_field );
|
644 |
-
}
|
645 |
return $this->ui_get_source_post( $container, $container_field );
|
646 |
}
|
647 |
|
648 |
return array();
|
649 |
}
|
650 |
|
651 |
-
|
652 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
653 |
if ( 'comment_author_url' === $container_field ) {
|
654 |
$image = 'font-awesome/font-awesome-user.png';
|
655 |
} else {
|
656 |
$image = 'font-awesome/font-awesome-comment-alt.png';
|
657 |
}
|
658 |
|
659 |
-
|
660 |
-
|
|
|
661 |
|
662 |
-
|
663 |
|
664 |
-
//Display a small text sample from the comment
|
665 |
$text_sample = strip_tags( $comment->comment_content );
|
666 |
-
$text_sample = blcUtility::truncate( $text_sample, 65 );
|
667 |
|
668 |
return array(
|
669 |
'image' => $image,
|
@@ -677,12 +837,18 @@ class MainWP_Child_Links_Checker {
|
|
677 |
);
|
678 |
}
|
679 |
|
680 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
681 |
return array(
|
682 |
'post_title' => get_the_title( $container->container_id ),
|
683 |
-
'post_status'
|
684 |
'container_anypost' => true,
|
685 |
);
|
686 |
}
|
687 |
}
|
688 |
-
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Links Checker
|
4 |
+
*
|
5 |
+
* This file handles all of the actions for the Broken Link Checker Extension.
|
6 |
*
|
7 |
+
* @deprecated This Extension has been Retired @since January 2020
|
8 |
+
* @link https://mainwp.com/retired-extensions/
|
9 |
+
*/
|
10 |
+
|
11 |
+
/**
|
12 |
* Credits
|
13 |
*
|
14 |
* Plugin-Name: Broken Link Checker
|
15 |
* Plugin URI: https://wordpress.org/plugins/broken-link-checker/
|
16 |
* Author: Janis Elsts, Vladimir Prelovac
|
17 |
*
|
18 |
+
* The code is used for the MainWP Broken Links Checker Extension (Retired Extension)
|
19 |
+
*/
|
20 |
+
|
21 |
+
namespace MainWP\Child;
|
22 |
+
|
23 |
+
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- to use external code, third party credit.
|
24 |
|
25 |
+
/**
|
26 |
+
* Class MainWP_Child_Links_Checker
|
27 |
+
*/
|
28 |
class MainWP_Child_Links_Checker {
|
29 |
|
30 |
+
/**
|
31 |
+
* @static
|
32 |
+
* @var null Holds the Public static instance of MainWP_Child_Links_Checker.
|
33 |
+
*/
|
34 |
public static $instance = null;
|
|
|
35 |
|
36 |
+
/**
|
37 |
+
* @var bool Whether or not the Broken Links Checker Extension is installed. Default: false.
|
38 |
+
*/
|
39 |
+
public $is_plugin_installed = false;
|
40 |
+
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Get Class Name
|
44 |
+
*
|
45 |
+
* @return string __CLASS__
|
46 |
+
*/
|
47 |
+
public static function get_class_name() {
|
48 |
+
return __CLASS__;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Create a public static instance of MainWP_Child_Links_Checker.
|
53 |
+
*
|
54 |
+
* @return MainWP_Child_Links_Checker|null
|
55 |
+
*/
|
56 |
+
public static function instance() {
|
57 |
+
if ( null === self::$instance ) {
|
58 |
+
self::$instance = new self();
|
59 |
}
|
60 |
|
61 |
+
return self::$instance;
|
62 |
}
|
63 |
|
64 |
+
/**
|
65 |
+
* MainWP_Child_Links_Checker constructor.
|
66 |
+
*
|
67 |
+
* Run any time class is called.
|
68 |
+
*/
|
69 |
public function __construct() {
|
70 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
71 |
if ( is_plugin_active( 'broken-link-checker/broken-link-checker.php' ) ) {
|
72 |
+
$this->is_plugin_installed = true;
|
73 |
}
|
74 |
|
75 |
+
if ( ! $this->is_plugin_installed ) {
|
76 |
+
return;
|
77 |
+
}
|
|
|
78 |
|
79 |
+
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
80 |
}
|
81 |
|
82 |
+
/**
|
83 |
+
* MainWP Broken Links Checker actions: set_showhide, sync_data, sync_links_data, edit_link,
|
84 |
+
* unlink, set_dismiss, discard, save_settings, force_recheck.
|
85 |
+
*/
|
86 |
public function action() {
|
87 |
$information = array();
|
88 |
if ( ! defined( 'BLC_ACTIVE' ) || ! function_exists( 'blc_init' ) ) {
|
91 |
}
|
92 |
blc_init();
|
93 |
|
94 |
+
MainWP_Helper::update_option( 'mainwp_linkschecker_ext_enabled', 'Y', 'yes' );
|
95 |
+
try {
|
96 |
+
if ( isset( $_POST['mwp_action'] ) ) {
|
97 |
+
$mwp_action = ! empty( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
98 |
+
switch ( $mwp_action ) {
|
99 |
+
case 'set_showhide':
|
100 |
+
$information = $this->set_showhide();
|
101 |
+
break;
|
102 |
+
case 'sync_data':
|
103 |
+
$information = $this->get_sync_data();
|
104 |
+
break;
|
105 |
+
case 'sync_links_data':
|
106 |
+
$information = $this->get_links_data();
|
107 |
+
break;
|
108 |
+
case 'edit_link':
|
109 |
+
$information = $this->edit_link();
|
110 |
+
break;
|
111 |
+
case 'unlink':
|
112 |
+
$information = $this->unlink();
|
113 |
+
break;
|
114 |
+
case 'set_dismiss':
|
115 |
+
$information = $this->set_link_dismissed();
|
116 |
+
break;
|
117 |
+
case 'discard':
|
118 |
+
$information = $this->discard();
|
119 |
+
break;
|
120 |
+
case 'save_settings':
|
121 |
+
$information = $this->save_settings();
|
122 |
+
break;
|
123 |
+
case 'force_recheck':
|
124 |
+
$information = $this->force_recheck();
|
125 |
+
break;
|
126 |
+
}
|
127 |
+
}
|
128 |
+
MainWP_Helper::write( $information );
|
129 |
+
} catch ( \Exception $e ) {
|
130 |
+
MainWP_Helper::write( array( 'error' => $e->getMessage() ) );
|
131 |
+
}
|
132 |
}
|
133 |
|
134 |
+
/**
|
135 |
+
* MainWP Broken links checker init.
|
136 |
+
*/
|
137 |
public function init() {
|
138 |
if ( get_option( 'mainwp_linkschecker_ext_enabled' ) !== 'Y' ) {
|
139 |
return;
|
145 |
}
|
146 |
}
|
147 |
|
148 |
+
/**
|
149 |
+
* Method hook_trashed_comment().
|
150 |
+
*
|
151 |
+
* @param $comment_id Comment ID.
|
152 |
+
*/
|
153 |
public static function hook_trashed_comment( $comment_id ) {
|
154 |
if ( get_option( 'mainwp_linkschecker_ext_enabled' ) !== 'Y' ) {
|
155 |
return;
|
159 |
return;
|
160 |
}
|
161 |
blc_init();
|
162 |
+
$container = \blcContainerHelper::get_container( array( 'comment', $comment_id ) );
|
163 |
$container->delete();
|
164 |
blc_cleanup_links();
|
165 |
}
|
166 |
|
167 |
+
/**
|
168 |
+
* Save Settings.
|
169 |
+
*
|
170 |
+
* @return array Return $information response array.
|
171 |
+
*/
|
172 |
+
public function save_settings() {
|
173 |
+
$information = array();
|
174 |
+
$check_threshold = isset( $_POST['check_threshold'] ) ? intval( wp_unslash( $_POST['check_threshold'] ) ) : 0;
|
175 |
if ( $check_threshold > 0 ) {
|
176 |
$conf = blc_get_configuration();
|
177 |
$conf->options['check_threshold'] = $check_threshold;
|
181 |
return $information;
|
182 |
}
|
183 |
|
184 |
+
/**
|
185 |
+
* Force link recheck.
|
186 |
+
*
|
187 |
+
* @return array Return $information response array.
|
188 |
+
*/
|
189 |
+
public function force_recheck() {
|
190 |
$this->initiate_recheck();
|
191 |
$information = array();
|
192 |
$information['result'] = 'SUCCESS';
|
194 |
return $information;
|
195 |
}
|
196 |
|
197 |
+
/**
|
198 |
+
* Initiate link recheck.
|
199 |
+
*/
|
200 |
+
public function initiate_recheck() {
|
201 |
+
|
202 |
+
/** @global object $wpdb wpdb */
|
203 |
global $wpdb;
|
|
|
204 |
|
205 |
+
// Delete all discovered instances.
|
206 |
$wpdb->query( "TRUNCATE {$wpdb->prefix}blc_instances" );
|
207 |
|
208 |
+
// Delete all discovered links.
|
209 |
$wpdb->query( "TRUNCATE {$wpdb->prefix}blc_links" );
|
210 |
|
211 |
+
// Mark all posts, custom fields and bookmarks for processing.
|
212 |
blc_resynch( true );
|
213 |
}
|
214 |
|
215 |
|
216 |
+
/**
|
217 |
+
* Method hook_post_deleted().
|
218 |
+
*
|
219 |
+
* @param $post_id Post ID.
|
220 |
+
*/
|
221 |
public static function hook_post_deleted( $post_id ) {
|
222 |
if ( get_option( 'mainwp_linkschecker_ext_enabled' ) !== 'Y' ) {
|
223 |
return;
|
228 |
}
|
229 |
blc_init();
|
230 |
|
231 |
+
// Get the container type matching the type of the deleted post.
|
232 |
$post = get_post( $post_id );
|
233 |
if ( ! $post ) {
|
234 |
return;
|
235 |
}
|
236 |
+
// Get the associated container object.
|
237 |
+
$post_container = \blcContainerHelper::get_container( array( $post->post_type, intval( $post_id ) ) );
|
238 |
|
239 |
if ( $post_container ) {
|
240 |
+
// Delete it.
|
241 |
$post_container->delete();
|
242 |
+
// Clean up any dangling links.
|
243 |
blc_cleanup_links();
|
244 |
}
|
245 |
}
|
246 |
|
247 |
|
248 |
+
/**
|
249 |
+
* Method hide_plugin().
|
250 |
+
*
|
251 |
+
* @param $plugins Plugins array.
|
252 |
+
* @return mixed $plugins array.
|
253 |
+
*/
|
254 |
public function hide_plugin( $plugins ) {
|
255 |
foreach ( $plugins as $key => $value ) {
|
256 |
$plugin_slug = basename( $key, '.php' );
|
262 |
return $plugins;
|
263 |
}
|
264 |
|
265 |
+
/**
|
266 |
+
* Method update_footer().
|
267 |
+
*
|
268 |
+
* @param $text Test to add to footer.
|
269 |
+
* @return string Footer html.
|
270 |
+
*/
|
271 |
+
public function update_footer( $text ) {
|
272 |
?>
|
273 |
<script>
|
274 |
jQuery( document ).ready( function () {
|
281 |
}
|
282 |
|
283 |
|
284 |
+
/**
|
285 |
+
* Show or hide the Broken links checker plugin.
|
286 |
+
*
|
287 |
+
* @return array Return $information response array.
|
288 |
+
*/
|
289 |
+
public function set_showhide() {
|
290 |
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
291 |
MainWP_Helper::update_option( 'mainwp_linkschecker_hide_plugin', $hide );
|
292 |
$information['result'] = 'SUCCESS';
|
294 |
return $information;
|
295 |
}
|
296 |
|
297 |
+
/**
|
298 |
+
* Sync other broken links data.
|
299 |
+
*
|
300 |
+
* @param array $information Array of information to sync.
|
301 |
+
* @param array $data Array of data.
|
302 |
+
* @return array Return $information response array.
|
303 |
+
*/
|
304 |
+
public function sync_others_data( $information, $data = array() ) {
|
305 |
+
if ( isset( $data['syncBrokenLinksCheckerData'] ) && $data['syncBrokenLinksCheckerData'] ) {
|
306 |
+
try {
|
307 |
+
$information['syncBrokenLinksCheckerData'] = $this->get_sync_data();
|
308 |
+
} catch ( \Exception $e ) {
|
309 |
+
// ok!
|
310 |
+
}
|
311 |
+
}
|
312 |
return $information;
|
313 |
}
|
314 |
|
315 |
+
/**
|
316 |
+
* Get synced link data.
|
317 |
+
*
|
318 |
+
* @param string $strategy Sync method.
|
319 |
+
* @return array Return $information response array.
|
320 |
+
*/
|
321 |
+
public function get_sync_data( $strategy = '' ) {
|
322 |
$information = array();
|
323 |
$data = $this->get_count_links();
|
324 |
+
if ( is_array( $data ) ) {
|
325 |
+
$information['data'] = $data;
|
326 |
+
}
|
327 |
return $information;
|
328 |
}
|
329 |
|
330 |
+
/**
|
331 |
+
* Get links data.
|
332 |
+
*
|
333 |
+
* @return array[]|void Return $information response array or void on failure.
|
334 |
+
* @throws Exception Error exception.
|
335 |
+
*/
|
336 |
+
public function get_links_data() {
|
337 |
|
338 |
+
if ( ! defined( 'BLC_DIRECTORY' ) ) {
|
339 |
+
return;
|
340 |
+
}
|
341 |
|
342 |
+
$file_path1 = BLC_DIRECTORY . '/includes/link-query.php';
|
343 |
+
$file_path2 = BLC_DIRECTORY . '/includes/modules.php';
|
344 |
+
MainWP_Helper::check_files_exists( array( $file_path1, $file_path2 ) );
|
345 |
|
346 |
+
require_once $file_path1;
|
347 |
+
require_once $file_path2;
|
348 |
|
349 |
+
MainWP_Helper::check_classes_exists( '\blcLinkQuery' );
|
350 |
+
MainWP_Helper::check_methods( '\blcLinkQuery', 'getInstance' );
|
351 |
|
352 |
+
$blc_link_query = \blcLinkQuery::getInstance();
|
353 |
|
354 |
+
MainWP_Helper::check_methods( $blc_link_query, 'get_filter_links' );
|
355 |
|
356 |
+
$total = $blc_link_query->get_filter_links( 'all', array( 'count_only' => true ) );
|
357 |
|
358 |
+
$max_results = isset( $_POST['max_results'] ) ? intval( wp_unslash( $_POST['max_results'] ) ) : 50;
|
359 |
+
$offset = isset( $_POST['offset'] ) ? intval( wp_unslash( $_POST['offset'] ) ) : 0;
|
360 |
|
361 |
+
$params = array(
|
362 |
+
array( 'load_instances' => true ),
|
363 |
+
'max_results' => $max_results,
|
364 |
+
);
|
365 |
|
366 |
+
if ( empty( $offset ) ) {
|
367 |
$first_sync = true;
|
368 |
} else {
|
369 |
$params['offset'] = $offset;
|
370 |
}
|
371 |
|
372 |
+
$link_data = $this->links_checker_data( $params );
|
373 |
|
374 |
$total_sync = 0;
|
375 |
+
if ( $offset ) {
|
376 |
$total_sync = $offset;
|
377 |
}
|
378 |
+
$total_sync += ( is_array( $link_data ) ? count( $link_data ) : 0 );
|
379 |
|
380 |
+
$information = array( 'links_data' => $link_data );
|
381 |
|
382 |
+
if ( $first_sync ) {
|
383 |
$information['data'] = $this->get_count_links();
|
384 |
}
|
385 |
|
386 |
+
if ( $total > $offset + $max_results ) {
|
387 |
$information['sync_offset'] = $offset + $max_results;
|
388 |
} else {
|
389 |
+
$information['last_sync'] = 1;
|
390 |
$information['total_sync'] = $total_sync;
|
391 |
+
$information['data'] = $this->get_count_links();
|
392 |
}
|
393 |
|
394 |
$information['result'] = 'success';
|
395 |
return $information;
|
396 |
}
|
397 |
|
398 |
+
/**
|
399 |
+
* Count links: broken, redirects, dismissed, warning, all.
|
400 |
+
*
|
401 |
+
* @return array[]|void Return $data response array or void on failure.
|
402 |
+
* @throws Exception Error exception.
|
403 |
+
*/
|
404 |
+
public function get_count_links() {
|
405 |
+
if ( ! defined( 'BLC_DIRECTORY' ) ) {
|
406 |
+
return;
|
407 |
+
}
|
408 |
|
409 |
+
$file_path1 = BLC_DIRECTORY . '/includes/link-query.php';
|
410 |
+
$file_path2 = BLC_DIRECTORY . '/includes/modules.php';
|
411 |
|
412 |
+
MainWP_Helper::check_files_exists( array( $file_path1, $file_path2 ) );
|
413 |
|
414 |
+
require_once $file_path1;
|
415 |
+
require_once $file_path2;
|
416 |
|
417 |
+
MainWP_Helper::check_classes_exists( '\blcLinkQuery' );
|
418 |
+
MainWP_Helper::check_methods( '\blcLinkQuery', 'getInstance' );
|
419 |
|
420 |
+
$data = array();
|
421 |
+
$blc_link_query = \blcLinkQuery::getInstance();
|
422 |
|
423 |
+
MainWP_Helper::check_methods( $blc_link_query, 'get_filter_links' );
|
424 |
|
425 |
+
$data['broken'] = $blc_link_query->get_filter_links( 'broken', array( 'count_only' => true ) );
|
426 |
+
$data['redirects'] = $blc_link_query->get_filter_links( 'redirects', array( 'count_only' => true ) );
|
427 |
+
$data['dismissed'] = $blc_link_query->get_filter_links( 'dismissed', array( 'count_only' => true ) );
|
428 |
$data['warning'] = $blc_link_query->get_filter_links( 'warning', array( 'count_only' => true ) );
|
429 |
+
$data['all'] = $blc_link_query->get_filter_links( 'all', array( 'count_only' => true ) );
|
430 |
return $data;
|
431 |
}
|
432 |
|
433 |
+
/**
|
434 |
+
* Link checker data.
|
435 |
+
*
|
436 |
+
* @param mixed $params Broken Links parameters.
|
437 |
+
* @return array $return Links Array.
|
438 |
+
* @throws Exception Error Exception.
|
439 |
+
*/
|
440 |
+
public function links_checker_data( $params ) {
|
441 |
|
442 |
+
MainWP_Helper::check_functions( 'blc_get_links' );
|
443 |
+
MainWP_Helper::check_classes_exists( '\blcLink' );
|
444 |
|
445 |
+
$links = blc_get_links( $params );
|
446 |
|
447 |
$filter_fields = array(
|
448 |
'link_id',
|
462 |
'last_success',
|
463 |
'may_recheck',
|
464 |
'false_positive',
|
|
|
465 |
'dismissed',
|
466 |
'status_text',
|
467 |
'status_code',
|
468 |
+
'log',
|
469 |
);
|
470 |
+
|
471 |
+
$return = array();
|
472 |
|
473 |
$blc_option = get_option( 'wsblc_options' );
|
474 |
|
478 |
|
479 |
if ( is_array( $links ) ) {
|
480 |
foreach ( $links as $link ) {
|
481 |
+
$new_link = new \stdClass();
|
482 |
foreach ( $filter_fields as $field ) {
|
483 |
$new_link->$field = $link->$field;
|
484 |
}
|
491 |
|
492 |
$days_broken = 0;
|
493 |
if ( $link->broken ) {
|
494 |
+
// Add a highlight to broken links that appear to be permanently broken.
|
495 |
$days_broken = intval( ( time() - $link->first_failure ) / ( 3600 * 24 ) );
|
496 |
if ( $days_broken >= $blc_option['failure_duration_threshold'] ) {
|
497 |
$extra_info['permanently_broken'] = 1;
|
501 |
}
|
502 |
}
|
503 |
$extra_info['days_broken'] = $days_broken;
|
504 |
+
$instances = false;
|
505 |
|
506 |
+
$get_link = new \blcLink( intval( $link->link_id ) );
|
507 |
if ( $get_link->valid() ) {
|
508 |
+
MainWP_Helper::check_methods( $get_link, 'get_instances' );
|
509 |
$instances = $get_link->get_instances();
|
510 |
}
|
511 |
|
512 |
if ( ! empty( $instances ) ) {
|
513 |
+
$first_instance = reset( $instances );
|
514 |
|
515 |
+
MainWP_Helper::check_methods( $first_instance, array( 'ui_get_link_text', 'get_container', 'is_link_text_editable', 'is_url_editable' ) );
|
516 |
|
517 |
+
$new_link->link_text = $first_instance->ui_get_link_text();
|
518 |
$extra_info['count_instance'] = count( $instances );
|
519 |
+
$container = $first_instance->get_container();
|
520 |
+
|
521 |
+
if ( ! empty( $container ) ) {
|
522 |
+
if ( true === MainWP_Helper::check_properties( $first_instance, array( 'container_field' ), true ) ) {
|
523 |
+
if ( true === MainWP_Helper::check_properties( $container, array( 'container_type', 'container_id' ), true ) ) {
|
524 |
+
$extra_info['container_type'] = $container->container_type;
|
525 |
+
$extra_info['container_id'] = $container->container_id;
|
526 |
+
$extra_info['source_data'] = $this->ui_get_source( $container, $first_instance->container_field );
|
527 |
+
}
|
528 |
+
}
|
|
|
|
|
529 |
}
|
530 |
|
531 |
$can_edit_text = false;
|
548 |
$link_texts = $can_edit_text ? $editable_link_texts : $non_editable_link_texts;
|
549 |
$data_link_text = '';
|
550 |
if ( count( $link_texts ) === 1 ) {
|
551 |
+
// All instances have the same text - use it.
|
552 |
$link_text = key( $link_texts );
|
553 |
$data_link_text = esc_attr( $link_text );
|
554 |
}
|
555 |
$extra_info['data_link_text'] = $data_link_text;
|
556 |
+
$extra_info['can_edit_url'] = $can_edit_url;
|
557 |
+
$extra_info['can_edit_text'] = $can_edit_text;
|
558 |
} else {
|
559 |
+
$new_link->link_text = '';
|
560 |
$extra_info['count_instance'] = 0;
|
561 |
}
|
562 |
+
$new_link->extra_info = base64_encode( serialize( $extra_info ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
563 |
+
$new_link->synced = 1;
|
564 |
+
$return[] = $new_link;
|
565 |
}
|
566 |
} else {
|
567 |
return array();
|
568 |
}
|
569 |
|
570 |
return $return;
|
|
|
571 |
}
|
572 |
|
573 |
+
/**
|
574 |
+
* Edit Link.
|
575 |
+
*
|
576 |
+
* @return array Return $information response array.
|
577 |
+
*/
|
578 |
+
public function edit_link() {
|
579 |
$information = array();
|
580 |
if ( ! current_user_can( 'edit_others_posts' ) ) {
|
581 |
$information['error'] = 'NOTALLOW';
|
582 |
|
583 |
return $information;
|
584 |
}
|
585 |
+
|
586 |
+
$link_id = isset( $_POST['link_id'] ) ? sanitize_text_field( wp_unslash( $_POST['link_id'] ) ) : '';
|
587 |
+
|
588 |
+
// Load the link.
|
589 |
+
$link = new \blcLink( intval( $link_id ) );
|
590 |
if ( ! $link->valid() ) {
|
591 |
+
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link.
|
592 |
return $information;
|
593 |
}
|
594 |
|
595 |
+
// Validate the new URL.
|
596 |
+
$new_url = isset( $_POST['new_url'] ) ? stripslashes( wp_unslash( $_POST['new_url'] ) ) : '';
|
597 |
$parsed = @parse_url( $new_url );
|
598 |
if ( ! $parsed ) {
|
599 |
$information['error'] = 'URLINVALID'; // Oops, the new URL is invalid!
|
600 |
return $information;
|
601 |
}
|
602 |
|
603 |
+
$new_text = isset( $_POST['new_text'] ) ? sanitize_text_field( wp_unslash( $_POST['new_text'] ) ) : null;
|
604 |
+
|
605 |
+
if ( ! empty( $new_text ) ) {
|
606 |
+
$new_text = stripslashes( wp_filter_post_kses( addslashes( $new_text ) ) ); // wp_filter_post_kses expects slashed data.
|
|
|
|
|
607 |
}
|
608 |
|
609 |
$rez = $link->edit( $new_url, $new_text );
|
636 |
'ui_link_text' => isset( $new_text ) ? $ui_link_text : null,
|
637 |
'errors' => array(),
|
638 |
);
|
639 |
+
// url, status text, status code, link text, editable link text.
|
640 |
|
641 |
foreach ( $rez['errors'] as $error ) {
|
|
|
642 |
array_push( $response['errors'], implode( ', ', $error->get_error_messages() ) );
|
643 |
}
|
644 |
|
646 |
}
|
647 |
}
|
648 |
|
649 |
+
/**
|
650 |
+
* Unlink link.
|
651 |
+
*
|
652 |
+
* @return array Return $information response array.
|
653 |
+
*/
|
654 |
+
public function unlink() {
|
655 |
$information = array();
|
656 |
if ( ! current_user_can( 'edit_others_posts' ) ) {
|
657 |
$information['error'] = 'NOTALLOW';
|
660 |
}
|
661 |
|
662 |
if ( isset( $_POST['link_id'] ) ) {
|
663 |
+
$link_id = isset( $_POST['link_id'] ) ? intval( $_POST['link_id'] ) : '';
|
664 |
+
|
665 |
+
// Load the link.
|
666 |
+
$link = new \blcLink( $link_id );
|
667 |
|
668 |
if ( ! $link->valid() ) {
|
669 |
+
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link.
|
670 |
return $information;
|
671 |
}
|
672 |
|
673 |
+
// Try and unlink it.
|
674 |
$rez = $link->unlink();
|
675 |
|
676 |
if ( false === $rez ) {
|
683 |
'errors' => array(),
|
684 |
);
|
685 |
foreach ( $rez['errors'] as $error ) {
|
686 |
+
/** @var \WP_Error $error */
|
687 |
array_push( $response['errors'], implode( ', ', $error->get_error_messages() ) );
|
688 |
}
|
689 |
|
696 |
}
|
697 |
}
|
698 |
|
699 |
+
/**
|
700 |
+
* Set dismissed link.
|
701 |
+
*
|
702 |
+
* @return array Return $information response array.
|
703 |
+
*/
|
704 |
private function set_link_dismissed() {
|
705 |
$information = array();
|
706 |
+
$dismiss = isset( $_POST['dismiss'] ) ? sanitize_text_field( wp_unslash( $_POST['dismiss'] ) ) : '';
|
707 |
|
708 |
if ( ! current_user_can( 'edit_others_posts' ) ) {
|
709 |
$information['error'] = 'NOTALLOW';
|
712 |
}
|
713 |
|
714 |
if ( isset( $_POST['link_id'] ) ) {
|
715 |
+
$link_id = isset( $_POST['link_id'] ) ? intval( $_POST['link_id'] ) : '';
|
716 |
+
|
717 |
+
// Load the link.
|
718 |
+
$link = new \blcLink( $link_id );
|
719 |
|
720 |
if ( ! $link->valid() ) {
|
721 |
+
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link.
|
722 |
return $information;
|
723 |
}
|
724 |
|
725 |
$link->dismissed = $dismiss;
|
726 |
|
727 |
+
// Save the changes.
|
728 |
if ( $link->save() ) {
|
729 |
$information = 'OK';
|
730 |
} else {
|
731 |
+
$information['error'] = 'COULDNOTMODIFY'; // Oops, couldn't modify the link.
|
732 |
}
|
733 |
|
734 |
return $information;
|
739 |
}
|
740 |
}
|
741 |
|
742 |
+
/**
|
743 |
+
* Discard link.
|
744 |
+
*
|
745 |
+
* @return array Return $information response array.
|
746 |
+
*/
|
747 |
private function discard() {
|
748 |
$information = array();
|
749 |
if ( ! current_user_can( 'edit_others_posts' ) ) {
|
752 |
return $information;
|
753 |
}
|
754 |
if ( isset( $_POST['link_id'] ) ) {
|
755 |
+
$link_id = isset( $_POST['link_id'] ) ? intval( $_POST['link_id'] ) : '';
|
756 |
+
|
757 |
+
// Load the link.
|
758 |
+
$link = new \blcLink( $link_id );
|
759 |
|
760 |
if ( ! $link->valid() ) {
|
761 |
+
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link.
|
762 |
return $information;
|
763 |
}
|
764 |
|
765 |
+
// Make it appear "not broken".
|
766 |
$link->broken = false;
|
767 |
$link->false_positive = true;
|
768 |
$link->last_check_attempt = time();
|
769 |
$link->log = __( 'This link was manually marked as working by the user.', 'mainwp-child' );
|
770 |
|
771 |
+
// Save the changes.
|
772 |
if ( $link->save() ) {
|
773 |
$information['status'] = 'OK';
|
774 |
$information['last_check_attempt'] = $link->last_check_attempt;
|
775 |
} else {
|
776 |
+
$information['error'] = 'COULDNOTMODIFY'; // Oops, couldn't modify the link.
|
777 |
}
|
778 |
} else {
|
779 |
$information['error'] = __( 'Error: link_id is not specified.', 'mainwp-child' );
|
782 |
return $information;
|
783 |
}
|
784 |
|
785 |
+
/**
|
786 |
+
* Get post or comment source.
|
787 |
+
*
|
788 |
+
* @param object $container Instance of container.
|
789 |
+
* @param string $container_field Container fields.
|
790 |
+
* @return array|bool Array of content or FALSE on failure.
|
791 |
+
*/
|
792 |
+
public function ui_get_source( $container, $container_field = '' ) {
|
793 |
if ( 'comment' === $container->container_type ) {
|
794 |
return $this->ui_get_source_comment( $container, $container_field );
|
795 |
+
} elseif ( $container instanceof \blcAnyPostContainer ) {
|
796 |
return $this->ui_get_source_post( $container, $container_field );
|
797 |
}
|
798 |
|
799 |
return array();
|
800 |
}
|
801 |
|
802 |
+
/**
|
803 |
+
* Get comment source.
|
804 |
+
*
|
805 |
+
* @param object $container Instance of container.
|
806 |
+
* @param string $container_field Container fields.
|
807 |
+
* @return array|bool Array of content or FALSE on failure.
|
808 |
+
* @throws Exception Error Exception.
|
809 |
+
*/
|
810 |
+
public function ui_get_source_comment( $container, $container_field = '' ) {
|
811 |
+
// Display a comment icon.
|
812 |
if ( 'comment_author_url' === $container_field ) {
|
813 |
$image = 'font-awesome/font-awesome-user.png';
|
814 |
} else {
|
815 |
$image = 'font-awesome/font-awesome-comment-alt.png';
|
816 |
}
|
817 |
|
818 |
+
if ( true !== MainWP_Helper::check_methods( $container, array( 'get_wrapped_object' ), true ) ) {
|
819 |
+
return false;
|
820 |
+
}
|
821 |
|
822 |
+
$comment = $container->get_wrapped_object();
|
823 |
|
824 |
+
// Display a small text sample from the comment.
|
825 |
$text_sample = strip_tags( $comment->comment_content );
|
826 |
+
$text_sample = \blcUtility::truncate( $text_sample, 65 );
|
827 |
|
828 |
return array(
|
829 |
'image' => $image,
|
837 |
);
|
838 |
}
|
839 |
|
840 |
+
/**
|
841 |
+
* Get Post Source.
|
842 |
+
*
|
843 |
+
* @param object $container Instance of container.
|
844 |
+
* @param string $container_field Container fields.
|
845 |
+
* @return array Return array of content.
|
846 |
+
*/
|
847 |
+
public function ui_get_source_post( $container, $container_field = '' ) {
|
848 |
return array(
|
849 |
'post_title' => get_the_title( $container->container_id ),
|
850 |
+
'post_status' => get_post_status( $container->container_id ),
|
851 |
'container_anypost' => true,
|
852 |
);
|
853 |
}
|
854 |
}
|
|
class/class-mainwp-child-maintenance.php
ADDED
@@ -0,0 +1,349 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Maintenance.
|
4 |
+
*
|
5 |
+
* MainWP Maintenance extension handler.
|
6 |
+
* Extension URL: https://mainwp.com/extension/maintenance/
|
7 |
+
*
|
8 |
+
* @package MainWP\Child
|
9 |
+
*/
|
10 |
+
|
11 |
+
namespace MainWP\Child;
|
12 |
+
|
13 |
+
// phpcs:disable WordPress.WP.AlternativeFunctions -- Required to achieve desired results, pull request solutions appreciated.
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Class MainWP_Child_Maintenance
|
17 |
+
*
|
18 |
+
* MainWP Maintenance extension handler.
|
19 |
+
*/
|
20 |
+
class MainWP_Child_Maintenance {
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Public static variable to hold the single instance of the class.
|
24 |
+
*
|
25 |
+
* @var mixed Default null
|
26 |
+
*/
|
27 |
+
protected static $instance = null;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Method get_class_name()
|
31 |
+
*
|
32 |
+
* Get class name.
|
33 |
+
*
|
34 |
+
* @return string __CLASS__ Class name.
|
35 |
+
*/
|
36 |
+
public static function get_class_name() {
|
37 |
+
return __CLASS__;
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* MainWP_Child_Maintenance constructor.
|
42 |
+
*
|
43 |
+
* Run any time class is called.
|
44 |
+
*/
|
45 |
+
public function __construct() {
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Method get_instance()
|
50 |
+
*
|
51 |
+
* Create a public static instance.
|
52 |
+
*
|
53 |
+
* @return mixed Class instance.
|
54 |
+
*/
|
55 |
+
public static function get_instance() {
|
56 |
+
if ( null === self::$instance ) {
|
57 |
+
self::$instance = new self();
|
58 |
+
}
|
59 |
+
return self::$instance;
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Method maintenance_site()
|
64 |
+
*
|
65 |
+
* Fire off Child Site maintenance action and get feedback.
|
66 |
+
*
|
67 |
+
* @uses MainWP_Child_Maintenance::maintenance_action() Triggers action to perform, save_settings, enable_alert or clear_settings.
|
68 |
+
* @uses MainWP_Child_Maintenance::maintenance_db() Child site database maintenance.
|
69 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
70 |
+
*/
|
71 |
+
public function maintenance_site() {
|
72 |
+
|
73 |
+
if ( isset( $_POST['action'] ) ) {
|
74 |
+
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
75 |
+
$this->maintenance_action( $action ); // exit.
|
76 |
+
}
|
77 |
+
|
78 |
+
$maint_options = isset( $_POST['options'] ) ? wp_unslash( $_POST['options'] ) : false;
|
79 |
+
|
80 |
+
if ( ! is_array( $maint_options ) ) {
|
81 |
+
MainWP_Helper::write( array( 'status' => 'FAIL' ) ); // exit.
|
82 |
+
}
|
83 |
+
|
84 |
+
$max_revisions = isset( $_POST['revisions'] ) ? intval( wp_unslash( $_POST['revisions'] ) ) : 0;
|
85 |
+
|
86 |
+
$information = $this->maintenance_db( $maint_options, $max_revisions );
|
87 |
+
|
88 |
+
MainWP_Helper::write( $information );
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Method maintenance_db()
|
93 |
+
*
|
94 |
+
* Child site database maintenance.
|
95 |
+
*
|
96 |
+
* @param array $maint_options An array containing selected maintenance options.
|
97 |
+
* @param int $max_revisions Maximum revisions to keep.
|
98 |
+
*
|
99 |
+
* @uses MainWP_Child_Maintenance::maintenance_get_revisions() Get child sites post revisions.
|
100 |
+
* @uses MainWP_Child_Maintenance::maintenance_delete_revisions()
|
101 |
+
* @uses MainWP_Child_Maintenance::maintenance_optimize()
|
102 |
+
*
|
103 |
+
* @uses get_terms() Retrieve the terms in a given taxonomy or list of taxonomies.
|
104 |
+
* @see https://developer.wordpress.org/reference/functions/get_terms/
|
105 |
+
*
|
106 |
+
* @uses wp_delete_term() Removes a term from the database.
|
107 |
+
* @see https://developer.wordpress.org/reference/functions/wp_delete_term/
|
108 |
+
*
|
109 |
+
* @used-by MainWP_Child_Maintenance::maintenance_site() Fire off Child Site maintenance action and get feedback.
|
110 |
+
*
|
111 |
+
* @return array An array containing action feedback.
|
112 |
+
*/
|
113 |
+
private function maintenance_db( $maint_options, $max_revisions ) {
|
114 |
+
|
115 |
+
/**
|
116 |
+
* WordPress Database instance.
|
117 |
+
*
|
118 |
+
* @global object $wpdb
|
119 |
+
*/
|
120 |
+
global $wpdb;
|
121 |
+
|
122 |
+
$performed_what = array();
|
123 |
+
|
124 |
+
if ( in_array( 'revisions', $maint_options ) ) {
|
125 |
+
if ( empty( $max_revisions ) ) {
|
126 |
+
$sql_clean = "DELETE FROM $wpdb->posts WHERE post_type = 'revision'";
|
127 |
+
$wpdb->query( $sql_clean ); // phpcs:ignore -- safe sql query. required to achieve desired results, pull request solutions appreciated.
|
128 |
+
// to fix issue of meta_value short length.
|
129 |
+
$performed_what[] = 'revisions'; // 'Posts revisions deleted'.
|
130 |
+
} else {
|
131 |
+
$results = $this->maintenance_get_revisions( $max_revisions );
|
132 |
+
$this->maintenance_delete_revisions( $results, $max_revisions );
|
133 |
+
$performed_what[] = 'revisions_max'; // 'Posts revisions deleted'.
|
134 |
+
}
|
135 |
+
}
|
136 |
+
|
137 |
+
$maint_sqls = array(
|
138 |
+
'autodraft' => "DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'",
|
139 |
+
'trashpost' => "DELETE FROM $wpdb->posts WHERE post_status = 'trash'",
|
140 |
+
'spam' => "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'",
|
141 |
+
'pending' => "DELETE FROM $wpdb->comments WHERE comment_approved = '0'",
|
142 |
+
'trashcomment' => "DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'",
|
143 |
+
);
|
144 |
+
|
145 |
+
foreach ( $maint_sqls as $act => $sql_clean ) {
|
146 |
+
if ( in_array( $act, $maint_options ) ) {
|
147 |
+
$wpdb->query( $sql_clean ); // phpcs:ignore -- safe sql query. required to achieve desired results, pull request solutions appreciated.
|
148 |
+
$performed_what[] = $act; // 'Auto draft posts deleted'.
|
149 |
+
}
|
150 |
+
}
|
151 |
+
|
152 |
+
if ( in_array( 'tags', $maint_options ) ) {
|
153 |
+
$post_tags = get_terms( 'post_tag', array( 'hide_empty' => false ) );
|
154 |
+
if ( is_array( $post_tags ) ) {
|
155 |
+
foreach ( $post_tags as $tag ) {
|
156 |
+
if ( 0 === $tag->count ) {
|
157 |
+
wp_delete_term( $tag->term_id, 'post_tag' );
|
158 |
+
}
|
159 |
+
}
|
160 |
+
}
|
161 |
+
$performed_what[] = 'tags'; // 'Tags with 0 posts associated deleted'.
|
162 |
+
}
|
163 |
+
|
164 |
+
if ( in_array( 'categories', $maint_options ) ) {
|
165 |
+
$post_cats = get_terms( 'category', array( 'hide_empty' => false ) );
|
166 |
+
if ( is_array( $post_cats ) ) {
|
167 |
+
foreach ( $post_cats as $cat ) {
|
168 |
+
if ( 0 === $cat->count ) {
|
169 |
+
wp_delete_term( $cat->term_id, 'category' );
|
170 |
+
}
|
171 |
+
}
|
172 |
+
}
|
173 |
+
$performed_what[] = 'categories'; // 'Categories with 0 posts associated deleted'.
|
174 |
+
}
|
175 |
+
|
176 |
+
if ( in_array( 'optimize', $maint_options ) ) {
|
177 |
+
$this->maintenance_optimize();
|
178 |
+
$performed_what[] = 'optimize'; // 'Database optimized'.
|
179 |
+
}
|
180 |
+
|
181 |
+
if ( ! empty( $performed_what ) && has_action( 'mainwp_reports_maintenance' ) ) {
|
182 |
+
$details = implode( ',', $performed_what );
|
183 |
+
$log_time = time();
|
184 |
+
$message = 'Maintenance Performed';
|
185 |
+
$result = 'Maintenance Performed';
|
186 |
+
do_action( 'mainwp_reports_maintenance', $message, $log_time, $details, $result, $max_revisions );
|
187 |
+
}
|
188 |
+
|
189 |
+
return array( 'status' => 'SUCCESS' );
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Method maintenance_get_revisions()
|
194 |
+
*
|
195 |
+
* Get child sites post revisions.
|
196 |
+
*
|
197 |
+
* @param int $max_revisions Maximum revisions to keep.
|
198 |
+
*
|
199 |
+
* @uses wpdb::get_results() Retrieve an entire SQL result set from the database.
|
200 |
+
* @see https://developer.wordpress.org/reference/classes/wpdb/get_results/
|
201 |
+
*
|
202 |
+
* @used-by MainWP_Child_Maintenance::maintenance_db() Child site database maintenance.
|
203 |
+
*
|
204 |
+
* @return array|object|null Database query results.
|
205 |
+
*/
|
206 |
+
protected function maintenance_get_revisions( $max_revisions ) {
|
207 |
+
|
208 |
+
/**
|
209 |
+
* WordPress Database instance.
|
210 |
+
*
|
211 |
+
* @global object $wpdb
|
212 |
+
*/
|
213 |
+
global $wpdb;
|
214 |
+
|
215 |
+
return $wpdb->get_results( $wpdb->prepare( " SELECT `post_parent`, COUNT(*) cnt FROM $wpdb->posts WHERE `post_type` = 'revision' GROUP BY `post_parent` HAVING COUNT(*) > %d ", $max_revisions ) );
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* Method maintenance_delete_revisions()
|
220 |
+
*
|
221 |
+
* Delete child site post revisions.
|
222 |
+
*
|
223 |
+
* @param array|object $results Database query results.
|
224 |
+
* @param int $max_revisions Maximum revisions to keep.
|
225 |
+
*
|
226 |
+
* @uses wpdb::get_results() Retrieve an entire SQL result set from the database.
|
227 |
+
* @see https://developer.wordpress.org/reference/classes/wpdb/get_results/
|
228 |
+
*
|
229 |
+
* @used-by MainWP_Child_Maintenance::maintenance_db() Child site database maintenance.
|
230 |
+
*
|
231 |
+
* @return int Return number of revisions deleted.
|
232 |
+
*/
|
233 |
+
private function maintenance_delete_revisions( $results, $max_revisions ) {
|
234 |
+
|
235 |
+
/**
|
236 |
+
* WordPress Database instance.
|
237 |
+
*
|
238 |
+
* @global object $wpdb
|
239 |
+
*/
|
240 |
+
global $wpdb;
|
241 |
+
|
242 |
+
if ( ! is_array( $results ) || 0 === count( $results ) ) {
|
243 |
+
return;
|
244 |
+
}
|
245 |
+
$count_deleted = 0;
|
246 |
+
$results_length = count( $results );
|
247 |
+
for ( $i = 0; $i < $results_length; $i ++ ) {
|
248 |
+
$number_to_delete = $results[ $i ]->cnt - $max_revisions;
|
249 |
+
$count_deleted += $number_to_delete;
|
250 |
+
$results_posts = $wpdb->get_results( $wpdb->prepare( "SELECT `ID`, `post_modified` FROM $wpdb->posts WHERE `post_parent`= %d AND `post_type`='revision' ORDER BY `post_modified` ASC", $results[ $i ]->post_parent ) );
|
251 |
+
$delete_ids = array();
|
252 |
+
if ( is_array( $results_posts ) && count( $results_posts ) > 0 ) {
|
253 |
+
for ( $j = 0; $j < $number_to_delete; $j ++ ) {
|
254 |
+
$delete_ids[] = $results_posts[ $j ]->ID;
|
255 |
+
}
|
256 |
+
}
|
257 |
+
|
258 |
+
if ( count( $delete_ids ) > 0 ) {
|
259 |
+
$sql_delete = " DELETE FROM $wpdb->posts WHERE `ID` IN (" . implode( ',', $delete_ids ) . ")"; // phpcs:ignore -- safe
|
260 |
+
$wpdb->get_results( $sql_delete ); // phpcs:ignore -- safe
|
261 |
+
}
|
262 |
+
}
|
263 |
+
|
264 |
+
return $count_deleted;
|
265 |
+
}
|
266 |
+
|
267 |
+
/**
|
268 |
+
* Method maintenance_optimize()
|
269 |
+
*
|
270 |
+
* Optimize Child database.
|
271 |
+
*
|
272 |
+
* @uses MainWP_Child_DB::to_query() Get the size of the DB.
|
273 |
+
* @uses MainWP_Child_DB::num_rows() Count the number of rows.
|
274 |
+
* @uses MainWP_Child_DB::is_result() Check if $result is an Instantiated object of \mysqli.
|
275 |
+
* @uses MainWP_Child_DB::fetch_array() Fetch an array.
|
276 |
+
*
|
277 |
+
* @used-by MainWP_Child_Maintenance::maintenance_db() Child site database maintenance.
|
278 |
+
*/
|
279 |
+
private function maintenance_optimize() {
|
280 |
+
|
281 |
+
/**
|
282 |
+
* Object, providing access to the WordPress database.
|
283 |
+
*
|
284 |
+
* @global object $wpdb WordPress Database instance.
|
285 |
+
*/
|
286 |
+
global $wpdb;
|
287 |
+
|
288 |
+
/**
|
289 |
+
* WordPress DB table prefix.
|
290 |
+
*
|
291 |
+
* @global string $table_prefix WordPress DB table prefix.
|
292 |
+
*/
|
293 |
+
global $table_prefix;
|
294 |
+
|
295 |
+
$sql = 'SHOW TABLE STATUS FROM `' . DB_NAME . '`';
|
296 |
+
$result = MainWP_Child_DB::to_query( $sql, $wpdb->dbh );
|
297 |
+
if ( MainWP_Child_DB::num_rows( $result ) && MainWP_Child_DB::is_result( $result ) ) {
|
298 |
+
while ( $row = MainWP_Child_DB::fetch_array( $result ) ) {
|
299 |
+
if ( strpos( $row['Name'], $table_prefix ) !== false ) {
|
300 |
+
$sql = 'OPTIMIZE TABLE ' . $row['Name'];
|
301 |
+
MainWP_Child_DB::to_query( $sql, $wpdb->dbh );
|
302 |
+
}
|
303 |
+
}
|
304 |
+
}
|
305 |
+
}
|
306 |
+
|
307 |
+
/**
|
308 |
+
* Method maintenance_action()
|
309 |
+
*
|
310 |
+
* Triggers action to perform, save_settings, enable_alert or clear_settings.
|
311 |
+
*
|
312 |
+
* @param string $action Action to perform.
|
313 |
+
*
|
314 |
+
* @uses delete_option() Removes option by name. Prevents removal of protected WordPress options.
|
315 |
+
* @see https://developer.wordpress.org/reference/functions/delete_option/
|
316 |
+
*
|
317 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
318 |
+
* @uses MainWP_Helper::update_option() Update option by name.
|
319 |
+
*
|
320 |
+
* @used-by MainWP_Child_Maintenance::maintenance_site() Fire off Child Site maintenance action and get feedback.
|
321 |
+
*/
|
322 |
+
private function maintenance_action( $action ) {
|
323 |
+
$information = array();
|
324 |
+
if ( 'save_settings' === $action ) {
|
325 |
+
if ( isset( $_POST['enable_alert'] ) && '1' === $_POST['enable_alert'] ) {
|
326 |
+
MainWP_Helper::update_option( 'mainwp_maintenance_opt_alert_404', 1, 'yes' );
|
327 |
+
} else {
|
328 |
+
delete_option( 'mainwp_maintenance_opt_alert_404' );
|
329 |
+
}
|
330 |
+
$email = ! empty( $_POST['email'] ) ? wp_unslash( $_POST['email'] ) : '';
|
331 |
+
if ( ! empty( $email ) ) {
|
332 |
+
MainWP_Helper::update_option( 'mainwp_maintenance_opt_alert_404_email', $email, 'yes' );
|
333 |
+
} else {
|
334 |
+
delete_option( 'mainwp_maintenance_opt_alert_404_email' );
|
335 |
+
}
|
336 |
+
$information['result'] = 'SUCCESS';
|
337 |
+
MainWP_Helper::write( $information );
|
338 |
+
|
339 |
+
return;
|
340 |
+
} elseif ( 'clear_settings' === $action ) {
|
341 |
+
delete_option( 'mainwp_maintenance_opt_alert_404' );
|
342 |
+
delete_option( 'mainwp_maintenance_opt_alert_404_email' );
|
343 |
+
$information['result'] = 'SUCCESS';
|
344 |
+
MainWP_Helper::write( $information );
|
345 |
+
}
|
346 |
+
|
347 |
+
MainWP_Helper::write( $information );
|
348 |
+
}
|
349 |
+
}
|
class/class-mainwp-child-misc.php
ADDED
@@ -0,0 +1,729 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Misc functions
|
4 |
+
*
|
5 |
+
* This file is for misc functions that don't really belong anywhere else.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
// phpcs:disable WordPress.WP.AlternativeFunctions -- Required to achieve desired results, pull request solutions appreciated.
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class MainWP_Child_Misc
|
16 |
+
*
|
17 |
+
* Misc functions that don't really belong anywhere else.
|
18 |
+
*/
|
19 |
+
class MainWP_Child_Misc {
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Public static variable to hold the single instance of the class.
|
23 |
+
*
|
24 |
+
* @var mixed Default null
|
25 |
+
*/
|
26 |
+
protected static $instance = null;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Method get_class_name()
|
30 |
+
*
|
31 |
+
* Get class name.
|
32 |
+
*
|
33 |
+
* @return string __CLASS__ Class name.
|
34 |
+
*/
|
35 |
+
public static function get_class_name() {
|
36 |
+
return __CLASS__;
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* MainWP_Child_Misc constructor.
|
41 |
+
*
|
42 |
+
* Run any time class is called.
|
43 |
+
*/
|
44 |
+
public function __construct() {
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Method get_instance()
|
49 |
+
*
|
50 |
+
* Create a public static instance.
|
51 |
+
*
|
52 |
+
* @return mixed Class instance.
|
53 |
+
*/
|
54 |
+
public static function get_instance() {
|
55 |
+
if ( null === self::$instance ) {
|
56 |
+
self::$instance = new self();
|
57 |
+
}
|
58 |
+
return self::$instance;
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Method get_site_icon()
|
63 |
+
*
|
64 |
+
* Fire off the get favicon function and add to sync information.
|
65 |
+
*
|
66 |
+
* @uses MainWP_Child_Misc::get_favicon() Get the child site favicon.
|
67 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
68 |
+
*/
|
69 |
+
public function get_site_icon() {
|
70 |
+
$information = array();
|
71 |
+
$url = $this->get_favicon( true );
|
72 |
+
if ( ! empty( $url ) ) {
|
73 |
+
$information['faviIconUrl'] = $url;
|
74 |
+
}
|
75 |
+
MainWP_Helper::write( $information );
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Method get_favicon()
|
80 |
+
*
|
81 |
+
* Get the child site favicon.
|
82 |
+
*
|
83 |
+
* @param bool $parse_page Whether or not to parse the page. Default: false.
|
84 |
+
*
|
85 |
+
* @uses MainWP_Child_Misc::try_to_parse_favicon() Try to parse child site URL for favicon.
|
86 |
+
* @uses get_site_icon_url() Returns the Site Icon URL.
|
87 |
+
* @see https://developer.wordpress.org/reference/functions/get_site_icon_url/
|
88 |
+
*
|
89 |
+
* @used-by MainWP_Child_Misc::get_site_icon() Fire off the get favicon function and add to sync information.
|
90 |
+
*
|
91 |
+
* @return string|bool Return favicon URL on success, FALSE on failure.
|
92 |
+
*/
|
93 |
+
public function get_favicon( $parse_page = false ) {
|
94 |
+
|
95 |
+
$favi_url = '';
|
96 |
+
$favi = '';
|
97 |
+
$site_url = get_option( 'siteurl' );
|
98 |
+
if ( substr( $site_url, - 1 ) != '/' ) {
|
99 |
+
$site_url .= '/';
|
100 |
+
}
|
101 |
+
|
102 |
+
if ( function_exists( '\get_site_icon_url' ) && \has_site_icon() ) {
|
103 |
+
$favi = \get_site_icon_url();
|
104 |
+
$favi_url = $favi;
|
105 |
+
}
|
106 |
+
|
107 |
+
if ( empty( $favi ) ) {
|
108 |
+
if ( file_exists( ABSPATH . 'favicon.ico' ) ) {
|
109 |
+
$favi = 'favicon.ico';
|
110 |
+
} elseif ( file_exists( ABSPATH . 'favicon.png' ) ) {
|
111 |
+
$favi = 'favicon.png';
|
112 |
+
}
|
113 |
+
|
114 |
+
if ( ! empty( $favi ) ) {
|
115 |
+
$favi_url = $site_url . $favi;
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
if ( $parse_page ) {
|
120 |
+
// try to parse page.
|
121 |
+
if ( empty( $favi_url ) ) {
|
122 |
+
$favi_url = $this->try_to_parse_favicon( $site_url );
|
123 |
+
}
|
124 |
+
|
125 |
+
if ( ! empty( $favi_url ) ) {
|
126 |
+
return $favi_url;
|
127 |
+
} else {
|
128 |
+
return false;
|
129 |
+
}
|
130 |
+
} else {
|
131 |
+
return $favi_url;
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* Method try_to_parse_favicon()
|
137 |
+
*
|
138 |
+
* Try to parse child site URL for favicon.
|
139 |
+
*
|
140 |
+
* @param string $site_url Child site URL.
|
141 |
+
*
|
142 |
+
* @uses wp_remote_get() Performs an HTTP request using the GET method and returns its response.
|
143 |
+
* @see https://developer.wordpress.org/reference/functions/wp_remote_get/
|
144 |
+
*
|
145 |
+
* @used-by MainWP_Child_Misc::get_favicon() Get the child site favicon.
|
146 |
+
*
|
147 |
+
* @return string Parsed favicon.
|
148 |
+
*/
|
149 |
+
private function try_to_parse_favicon( $site_url ) {
|
150 |
+
$request = wp_remote_get( $site_url, array( 'timeout' => 50 ) );
|
151 |
+
$favi = '';
|
152 |
+
if ( is_array( $request ) && isset( $request['body'] ) ) {
|
153 |
+
$preg_str1 = '/(<link\s+(?:[^\>]*)(?:rel="shortcut\s+icon"\s*)(?:[^>]*)?href="([^"]+)"(?:[^>]*)?>)/is';
|
154 |
+
$preg_str2 = '/(<link\s+(?:[^\>]*)(?:rel="(?:shortcut\s+)?icon"\s*)(?:[^>]*)?href="([^"]+)"(?:[^>]*)?>)/is';
|
155 |
+
|
156 |
+
if ( preg_match( $preg_str1, $request['body'], $matches ) ) {
|
157 |
+
$favi = $matches[2];
|
158 |
+
} elseif ( preg_match( $preg_str2, $request['body'], $matches ) ) {
|
159 |
+
$favi = $matches[2];
|
160 |
+
}
|
161 |
+
}
|
162 |
+
$favi_url = '';
|
163 |
+
if ( ! empty( $favi ) ) {
|
164 |
+
if ( false === strpos( $favi, 'http' ) ) {
|
165 |
+
if ( 0 === strpos( $favi, '//' ) ) {
|
166 |
+
if ( 0 === strpos( $site_url, 'https' ) ) {
|
167 |
+
$favi_url = 'https:' . $favi;
|
168 |
+
} else {
|
169 |
+
$favi_url = 'http:' . $favi;
|
170 |
+
}
|
171 |
+
} else {
|
172 |
+
$favi_url = $site_url . $favi;
|
173 |
+
}
|
174 |
+
} else {
|
175 |
+
$favi_url = $favi;
|
176 |
+
}
|
177 |
+
}
|
178 |
+
return $favi_url;
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Method get_security_stats()
|
183 |
+
*
|
184 |
+
* Get security issues information.
|
185 |
+
*
|
186 |
+
* @param bool $return Either return or not.
|
187 |
+
*
|
188 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
189 |
+
*/
|
190 |
+
public function get_security_stats( $return = false ) {
|
191 |
+
$information = array();
|
192 |
+
|
193 |
+
$information['listing'] = ( ! MainWP_Security::prevent_listing_ok() ? 'N' : 'Y' );
|
194 |
+
$information['wp_version'] = ( ! MainWP_Security::remove_wp_version_ok() ? 'N' : 'Y' );
|
195 |
+
$information['rsd'] = ( ! MainWP_Security::remove_rsd_ok() ? 'N' : 'Y' );
|
196 |
+
$information['wlw'] = ( ! MainWP_Security::remove_wlw_ok() ? 'N' : 'Y' );
|
197 |
+
$information['db_reporting'] = ( ! MainWP_Security::remove_database_reporting_ok() ? 'N' : 'Y' );
|
198 |
+
$information['php_reporting'] = ( ! MainWP_Security::remove_php_reporting_ok() ? 'N' : 'Y' );
|
199 |
+
$information['versions'] = ( ! MainWP_Security::remove_scripts_version_ok() || ! MainWP_Security::remove_styles_version_ok() || ! MainWP_Security::remove_generator_version_ok() ? 'N' : 'Y' );
|
200 |
+
$information['registered_versions'] = ( MainWP_Security::remove_registered_versions_ok() ? 'Y' : 'N' );
|
201 |
+
$information['admin'] = ( MainWP_Security::admin_user_ok() ? 'Y' : 'N' );
|
202 |
+
$information['readme'] = ( MainWP_Security::remove_readme_ok() ? 'Y' : 'N' );
|
203 |
+
|
204 |
+
if ( $return ) {
|
205 |
+
return $information;
|
206 |
+
}
|
207 |
+
|
208 |
+
MainWP_Helper::write( $information );
|
209 |
+
}
|
210 |
+
|
211 |
+
|
212 |
+
/**
|
213 |
+
* Method do_security_fix()
|
214 |
+
*
|
215 |
+
* Fix detected security issues and set feedback to sync information.
|
216 |
+
*
|
217 |
+
* @uses MainWP_Helper::update_option() Update option by name.
|
218 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
219 |
+
* @uses MainWP_Security::prevent_listing()
|
220 |
+
* @uses MainWP_Security::prevent_listing_ok()
|
221 |
+
* @uses MainWP_Security::remove_wp_version()
|
222 |
+
* @uses MainWP_Security::remove_wp_version_ok()
|
223 |
+
* @uses MainWP_Security::remove_rsd()
|
224 |
+
* @uses MainWP_Security::remove_rsd_ok()
|
225 |
+
* @uses MainWP_Security::remove_wlw()
|
226 |
+
* @uses MainWP_Security::remove_wlw_ok()
|
227 |
+
* @uses MainWP_Security::remove_database_reporting()
|
228 |
+
* @uses MainWP_Security::remove_database_reporting_ok()
|
229 |
+
* @uses MainWP_Security::remove_php_reporting()
|
230 |
+
* @uses MainWP_Security::remove_php_reporting_ok()
|
231 |
+
* @uses MainWP_Security::remove_generator_version()
|
232 |
+
* @uses MainWP_Security::admin_user_ok()
|
233 |
+
* @uses MainWP_Security::remove_readme()
|
234 |
+
* @uses MainWP_Security::remove_readme_ok()
|
235 |
+
*/
|
236 |
+
public function do_security_fix() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
237 |
+
$sync = false;
|
238 |
+
|
239 |
+
$feature = isset( $_POST['feature'] ) ? sanitize_text_field( wp_unslash( $_POST['feature'] ) ) : '';
|
240 |
+
|
241 |
+
if ( 'all' === $feature ) {
|
242 |
+
$sync = true;
|
243 |
+
}
|
244 |
+
|
245 |
+
$skips = isset( $_POST['skip_features'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['skip_features'] ) ) : array();
|
246 |
+
if ( ! is_array( $skips ) ) {
|
247 |
+
$skips = array();
|
248 |
+
}
|
249 |
+
|
250 |
+
$information = array();
|
251 |
+
$security = get_option( 'mainwp_security' );
|
252 |
+
if ( ! is_array( $security ) ) {
|
253 |
+
$security = array();
|
254 |
+
}
|
255 |
+
|
256 |
+
if ( 'all' === $feature || 'listing' === $feature ) {
|
257 |
+
if ( ! in_array( 'listing', $skips ) ) {
|
258 |
+
MainWP_Security::prevent_listing();
|
259 |
+
}
|
260 |
+
$information['listing'] = ( ! MainWP_Security::prevent_listing_ok() ? 'N' : 'Y' );
|
261 |
+
}
|
262 |
+
|
263 |
+
if ( 'all' === $feature || 'wp_version' === $feature ) {
|
264 |
+
if ( ! in_array( 'wp_version', $skips ) ) {
|
265 |
+
$security['wp_version'] = true;
|
266 |
+
MainWP_Security::remove_wp_version( true );
|
267 |
+
}
|
268 |
+
$information['wp_version'] = ( ! MainWP_Security::remove_wp_version_ok() ? 'N' : 'Y' );
|
269 |
+
}
|
270 |
+
|
271 |
+
if ( 'all' === $feature || 'rsd' === $feature ) {
|
272 |
+
if ( ! in_array( 'rsd', $skips ) ) {
|
273 |
+
$security['rsd'] = true;
|
274 |
+
MainWP_Security::remove_rsd( true );
|
275 |
+
}
|
276 |
+
$information['rsd'] = ( ! MainWP_Security::remove_rsd_ok() ? 'N' : 'Y' );
|
277 |
+
}
|
278 |
+
|
279 |
+
if ( 'all' === $feature || 'wlw' === $feature ) {
|
280 |
+
if ( ! in_array( 'wlw', $skips ) ) {
|
281 |
+
$security['wlw'] = true;
|
282 |
+
MainWP_Security::remove_wlw( true );
|
283 |
+
}
|
284 |
+
$information['wlw'] = ( ! MainWP_Security::remove_wlw_ok() ? 'N' : 'Y' );
|
285 |
+
}
|
286 |
+
|
287 |
+
if ( 'all' === $feature || 'db_reporting' === $feature ) {
|
288 |
+
if ( ! in_array( 'db_reporting', $skips ) ) {
|
289 |
+
MainWP_Security::remove_database_reporting();
|
290 |
+
}
|
291 |
+
$information['db_reporting'] = ( ! MainWP_Security::remove_database_reporting_ok() ? 'N' : 'Y' );
|
292 |
+
}
|
293 |
+
|
294 |
+
if ( 'all' === $feature || 'php_reporting' === $feature ) {
|
295 |
+
if ( ! in_array( 'php_reporting', $skips ) ) {
|
296 |
+
$security['php_reporting'] = true;
|
297 |
+
MainWP_Security::remove_php_reporting( true );
|
298 |
+
}
|
299 |
+
$information['php_reporting'] = ( ! MainWP_Security::remove_php_reporting_ok() ? 'N' : 'Y' );
|
300 |
+
}
|
301 |
+
|
302 |
+
if ( 'all' === $feature || 'versions' === $feature ) {
|
303 |
+
if ( ! in_array( 'versions', $skips ) ) {
|
304 |
+
$security['scripts_version'] = true;
|
305 |
+
$security['styles_version'] = true;
|
306 |
+
$security['generator_version'] = true;
|
307 |
+
MainWP_Security::remove_generator_version( true );
|
308 |
+
$information['versions'] = 'Y';
|
309 |
+
}
|
310 |
+
}
|
311 |
+
|
312 |
+
if ( 'all' === $feature || 'registered_versions' === $feature ) {
|
313 |
+
if ( ! in_array( 'registered_versions', $skips ) ) {
|
314 |
+
$security['registered_versions'] = true;
|
315 |
+
$information['registered_versions'] = 'Y';
|
316 |
+
}
|
317 |
+
}
|
318 |
+
|
319 |
+
if ( 'all' === $feature || 'admin' === $feature ) {
|
320 |
+
$information['admin'] = ( ! MainWP_Security::admin_user_ok() ? 'N' : 'Y' );
|
321 |
+
}
|
322 |
+
|
323 |
+
if ( 'all' === $feature || 'readme' === $feature ) {
|
324 |
+
if ( ! in_array( 'readme', $skips ) ) {
|
325 |
+
$security['readme'] = true;
|
326 |
+
MainWP_Security::remove_readme( true );
|
327 |
+
}
|
328 |
+
$information['readme'] = ( MainWP_Security::remove_readme_ok() ? 'Y' : 'N' );
|
329 |
+
}
|
330 |
+
|
331 |
+
MainWP_Helper::update_option( 'mainwp_security', $security, 'yes' );
|
332 |
+
|
333 |
+
if ( $sync ) {
|
334 |
+
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
|
335 |
+
}
|
336 |
+
MainWP_Helper::write( $information );
|
337 |
+
}
|
338 |
+
|
339 |
+
/**
|
340 |
+
* Method do_security_un_fix()
|
341 |
+
*
|
342 |
+
* Unfix fixed child site security issues.
|
343 |
+
*
|
344 |
+
* @uses MainWP_Helper::update_option() Update option by name.
|
345 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
346 |
+
* @uses MainWP_Security::remove_readme_ok()
|
347 |
+
*/
|
348 |
+
public function do_security_un_fix() {
|
349 |
+
$information = array();
|
350 |
+
|
351 |
+
$feature = isset( $_POST['feature'] ) ? sanitize_text_field( wp_unslash( $_POST['feature'] ) ) : '';
|
352 |
+
|
353 |
+
$sync = false;
|
354 |
+
if ( 'all' === $feature ) {
|
355 |
+
$sync = true;
|
356 |
+
}
|
357 |
+
|
358 |
+
$security = get_option( 'mainwp_security' );
|
359 |
+
|
360 |
+
if ( 'all' === $feature || 'wp_version' === $feature ) {
|
361 |
+
$security['wp_version'] = false;
|
362 |
+
$information['wp_version'] = 'N';
|
363 |
+
}
|
364 |
+
|
365 |
+
if ( 'all' === $feature || 'rsd' === $feature ) {
|
366 |
+
$security['rsd'] = false;
|
367 |
+
$information['rsd'] = 'N';
|
368 |
+
}
|
369 |
+
|
370 |
+
if ( 'all' === $feature || 'wlw' === $feature ) {
|
371 |
+
$security['wlw'] = false;
|
372 |
+
$information['wlw'] = 'N';
|
373 |
+
}
|
374 |
+
|
375 |
+
if ( 'all' === $feature || 'php_reporting' === $feature ) {
|
376 |
+
$security['php_reporting'] = false;
|
377 |
+
$information['php_reporting'] = 'N';
|
378 |
+
}
|
379 |
+
|
380 |
+
if ( 'all' === $feature || 'versions' === $feature ) {
|
381 |
+
$security['scripts_version'] = false;
|
382 |
+
$security['styles_version'] = false;
|
383 |
+
$security['generator_version'] = false;
|
384 |
+
$information['versions'] = 'N';
|
385 |
+
}
|
386 |
+
|
387 |
+
if ( 'all' === $feature || 'registered_versions' === $feature ) {
|
388 |
+
$security['registered_versions'] = false;
|
389 |
+
$information['registered_versions'] = 'N';
|
390 |
+
}
|
391 |
+
if ( 'all' === $feature || 'readme' === $feature ) {
|
392 |
+
$security['readme'] = false;
|
393 |
+
$information['readme'] = MainWP_Security::remove_readme_ok();
|
394 |
+
}
|
395 |
+
|
396 |
+
MainWP_Helper::update_option( 'mainwp_security', $security, 'yes' );
|
397 |
+
|
398 |
+
if ( $sync ) {
|
399 |
+
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
|
400 |
+
}
|
401 |
+
|
402 |
+
MainWP_Helper::write( $information );
|
403 |
+
}
|
404 |
+
|
405 |
+
/**
|
406 |
+
* Method settings_tools()
|
407 |
+
*
|
408 |
+
* Fire off misc actions and set feedback to the sync information.
|
409 |
+
*
|
410 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
411 |
+
* @uses wp_destroy_all_sessions() Remove all session tokens for the current user from the database.
|
412 |
+
* @see https://developer.wordpress.org/reference/functions/wp_destroy_all_sessions/
|
413 |
+
*
|
414 |
+
* @uses wp_get_all_sessions() Retrieve a list of sessions for the current user.
|
415 |
+
* @see https://developer.wordpress.org/reference/functions/wp_get_all_sessions/
|
416 |
+
*/
|
417 |
+
public function settings_tools() {
|
418 |
+
if ( isset( $_POST['action'] ) ) {
|
419 |
+
$mwp_action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
420 |
+
switch ( $mwp_action ) {
|
421 |
+
case 'force_destroy_sessions':
|
422 |
+
if ( 0 === get_current_user_id() ) {
|
423 |
+
MainWP_Helper::write( array( 'error' => __( 'Cannot get user_id', 'mainwp-child' ) ) );
|
424 |
+
}
|
425 |
+
|
426 |
+
wp_destroy_all_sessions();
|
427 |
+
|
428 |
+
$sessions = wp_get_all_sessions();
|
429 |
+
|
430 |
+
if ( empty( $sessions ) ) {
|
431 |
+
MainWP_Helper::write( array( 'success' => 1 ) );
|
432 |
+
} else {
|
433 |
+
MainWP_Helper::write( array( 'error' => __( 'Cannot destroy sessions', 'mainwp-child' ) ) );
|
434 |
+
}
|
435 |
+
break;
|
436 |
+
|
437 |
+
default:
|
438 |
+
MainWP_Helper::write( array( 'error' => __( 'Invalid action', 'mainwp-child' ) ) );
|
439 |
+
}
|
440 |
+
} else {
|
441 |
+
MainWP_Helper::write( array( 'error' => __( 'Missing action', 'mainwp-child' ) ) );
|
442 |
+
}
|
443 |
+
}
|
444 |
+
|
445 |
+
/**
|
446 |
+
* Method uploader_action()
|
447 |
+
*
|
448 |
+
* Initiate the file upload action.
|
449 |
+
*
|
450 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
451 |
+
* @uses MainWP_Child_Misc::uploader_upload_file() Upload file from the MainWP Dashboard.
|
452 |
+
*
|
453 |
+
* @return void
|
454 |
+
*/
|
455 |
+
public function uploader_action() {
|
456 |
+
$file_url = isset( $_POST['url'] ) ? base64_decode( wp_unslash( $_POST['url'] ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- Required for backwards compatibility.
|
457 |
+
$path = isset( $_POST['path'] ) ? wp_unslash( $_POST['path'] ) : '';
|
458 |
+
$filename = isset( $_POST['filename'] ) ? wp_unslash( $_POST['filename'] ) : '';
|
459 |
+
$information = array();
|
460 |
+
|
461 |
+
if ( empty( $file_url ) || empty( $path ) ) {
|
462 |
+
MainWP_Helper::write( $information );
|
463 |
+
|
464 |
+
return;
|
465 |
+
}
|
466 |
+
|
467 |
+
if ( strpos( $path, 'wp-content' ) === 0 ) {
|
468 |
+
$path = basename( WP_CONTENT_DIR ) . substr( $path, 10 );
|
469 |
+
} elseif ( strpos( $path, 'wp-includes' ) === 0 ) {
|
470 |
+
$path = WPINC . substr( $path, 11 );
|
471 |
+
}
|
472 |
+
|
473 |
+
if ( '/' === $path ) {
|
474 |
+
$dir = ABSPATH;
|
475 |
+
} else {
|
476 |
+
$path = str_replace( ' ', '-', $path );
|
477 |
+
$path = str_replace( '.', '-', $path );
|
478 |
+
$dir = ABSPATH . $path;
|
479 |
+
}
|
480 |
+
|
481 |
+
if ( ! file_exists( $dir ) ) {
|
482 |
+
if ( false === mkdir( $dir, 0777, true ) ) {
|
483 |
+
$information['error'] = 'ERRORCREATEDIR';
|
484 |
+
MainWP_Helper::write( $information );
|
485 |
+
|
486 |
+
return;
|
487 |
+
}
|
488 |
+
}
|
489 |
+
|
490 |
+
try {
|
491 |
+
$upload = $this->uploader_upload_file( $file_url, $dir, $filename );
|
492 |
+
if ( null !== $upload ) {
|
493 |
+
$information['success'] = true;
|
494 |
+
}
|
495 |
+
} catch ( \Exception $e ) {
|
496 |
+
$information['error'] = $e->getMessage();
|
497 |
+
}
|
498 |
+
MainWP_Helper::write( $information );
|
499 |
+
}
|
500 |
+
|
501 |
+
|
502 |
+
/**
|
503 |
+
* Method uploader_upload_file()
|
504 |
+
*
|
505 |
+
* Upload file from the MainWP Dashboard.
|
506 |
+
*
|
507 |
+
* @param string $file_url URL of file to be uploaded.
|
508 |
+
* @param string $path Path to upload to.
|
509 |
+
* @param string $file_name Name of file to upload.
|
510 |
+
*
|
511 |
+
* @uses wp_remote_get() Performs an HTTP request using the GET method and returns its response.
|
512 |
+
* @see https://developer.wordpress.org/reference/functions/wp_remote_get/
|
513 |
+
*
|
514 |
+
* @uses sanitize_file_name() Sanitizes a filename, replacing whitespace with dashes.
|
515 |
+
* @see https://developer.wordpress.org/reference/functions/sanitize_file_name/
|
516 |
+
*
|
517 |
+
* @uses is_wp_error() Check whether variable is a WordPress Error.
|
518 |
+
* @see https://developer.wordpress.org/reference/functions/is_wp_error/
|
519 |
+
*
|
520 |
+
* @uses wp_remote_retrieve_response_code() Retrieve only the response code from the raw response.
|
521 |
+
* @see https://developer.wordpress.org/reference/functions/wp_remote_retrieve_response_code/
|
522 |
+
*
|
523 |
+
* @uses wp_remote_retrieve_response_message() Retrieve only the response message from the raw response.
|
524 |
+
* @see https://developer.wordpress.org/reference/functions/wp_remote_retrieve_response_message/
|
525 |
+
*
|
526 |
+
* @used-by MainWP_Child_Misc::uploader_action() Initiate the file upload action.
|
527 |
+
*
|
528 |
+
* @throws \Exception Error message.
|
529 |
+
*
|
530 |
+
* @return array Full path and file name of uploaded file.
|
531 |
+
*/
|
532 |
+
public function uploader_upload_file( $file_url, $path, $file_name ) {
|
533 |
+
// Fixes: Uploader Extension rename htaccess file issue.
|
534 |
+
if ( '.htaccess' != $file_name && '.htpasswd' != $file_name ) {
|
535 |
+
$file_name = sanitize_file_name( $file_name );
|
536 |
+
}
|
537 |
+
|
538 |
+
$full_file_name = $path . DIRECTORY_SEPARATOR . $file_name;
|
539 |
+
|
540 |
+
$response = wp_remote_get(
|
541 |
+
$file_url,
|
542 |
+
array(
|
543 |
+
'timeout' => 10 * 60 * 60,
|
544 |
+
'stream' => true,
|
545 |
+
'filename' => $full_file_name,
|
546 |
+
)
|
547 |
+
);
|
548 |
+
|
549 |
+
if ( is_wp_error( $response ) ) {
|
550 |
+
unlink( $full_file_name );
|
551 |
+
throw new \Exception( 'Error: ' . $response->get_error_message() );
|
552 |
+
}
|
553 |
+
|
554 |
+
if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
|
555 |
+
unlink( $full_file_name );
|
556 |
+
throw new \Exception( 'Error 404: ' . trim( wp_remote_retrieve_response_message( $response ) ) );
|
557 |
+
}
|
558 |
+
if ( '.phpfile.txt' === substr( $file_name, - 12 ) ) {
|
559 |
+
$new_file_name = substr( $file_name, 0, - 12 ) . '.php';
|
560 |
+
$new_file_name = $path . DIRECTORY_SEPARATOR . $new_file_name;
|
561 |
+
$moved = rename( $full_file_name, $new_file_name );
|
562 |
+
if ( $moved ) {
|
563 |
+
return array( 'path' => $new_file_name );
|
564 |
+
} else {
|
565 |
+
unlink( $full_file_name );
|
566 |
+
throw new \Exception( 'Error: Copy file.' );
|
567 |
+
}
|
568 |
+
}
|
569 |
+
|
570 |
+
return array( 'path' => $full_file_name );
|
571 |
+
}
|
572 |
+
|
573 |
+
/**
|
574 |
+
* Method code_snippet()
|
575 |
+
*
|
576 |
+
* Initiate Code Snippet actions run_snippet, save_snippet and delete_snippet.
|
577 |
+
*
|
578 |
+
* @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
|
579 |
+
* @uses MainWP_Utility::execute_snippet() Execute code snippet.
|
580 |
+
* @uses MainWP_Child_Misc::snippet_save_snippet() Save code snippet.
|
581 |
+
* @uses MainWP_Child_Misc::snippet_delete_snippet() Delete code snippet.
|
582 |
+
* @uses get_option() Retrieves an option value based on an option name.
|
583 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
584 |
+
*/
|
585 |
+
public function code_snippet() {
|
586 |
+
|
587 |
+
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
588 |
+
$type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
|
589 |
+
$slug = isset( $_POST['slug'] ) ? wp_unslash( $_POST['slug'] ) : '';
|
590 |
+
|
591 |
+
$snippets = get_option( 'mainwp_ext_code_snippets' );
|
592 |
+
|
593 |
+
if ( ! is_array( $snippets ) ) {
|
594 |
+
$snippets = array();
|
595 |
+
}
|
596 |
+
|
597 |
+
if ( 'run_snippet' === $action || 'save_snippet' === $action ) {
|
598 |
+
if ( ! isset( $_POST['code'] ) ) {
|
599 |
+
MainWP_Helper::write( array( 'status' => 'FAIL' ) );
|
600 |
+
}
|
601 |
+
}
|
602 |
+
|
603 |
+
$code = isset( $_POST['code'] ) ? stripslashes( wp_unslash( $_POST['code'] ) ) : '';
|
604 |
+
|
605 |
+
$information = array();
|
606 |
+
if ( 'run_snippet' === $action ) {
|
607 |
+
$information = MainWP_Utility::execute_snippet( $code );
|
608 |
+
} elseif ( 'save_snippet' === $action ) {
|
609 |
+
$information = $this->snippet_save_snippet( $slug, $type, $code, $snippets );
|
610 |
+
} elseif ( 'delete_snippet' === $action ) {
|
611 |
+
$information = $this->snippet_delete_snippet( $slug, $type, $snippets );
|
612 |
+
}
|
613 |
+
|
614 |
+
if ( empty( $information ) ) {
|
615 |
+
$information = array( 'status' => 'FAIL' );
|
616 |
+
}
|
617 |
+
|
618 |
+
MainWP_Helper::write( $information );
|
619 |
+
}
|
620 |
+
|
621 |
+
/**
|
622 |
+
* Method snippet_save_snippet()
|
623 |
+
*
|
624 |
+
* Save code snippet.
|
625 |
+
*
|
626 |
+
* @param string $slug Snippet slug.
|
627 |
+
* @param string $type Type of snippet.
|
628 |
+
* @param string $code Snippet code.
|
629 |
+
* @param array $snippets An array containing all snipptes.
|
630 |
+
*
|
631 |
+
* @uses MainWP_Helper::update_option() Update option by name.
|
632 |
+
* @uses MainWP_Child_Misc::snippet_update_wp_config() Update the child site wp-config.php file.
|
633 |
+
*
|
634 |
+
* @used-by MainWP_Child_Misc::code_snippet() Initiate Code Snippet actions run_snippet, save_snippet and delete_snippet.
|
635 |
+
*
|
636 |
+
* @return array $return Status response.
|
637 |
+
*/
|
638 |
+
private function snippet_save_snippet( $slug, $type, $code, $snippets ) {
|
639 |
+
$return = array();
|
640 |
+
if ( 'C' === $type ) { // save into wp-config file.
|
641 |
+
if ( false !== $this->snippet_update_wp_config( 'save', $slug, $code ) ) {
|
642 |
+
$return['status'] = 'SUCCESS';
|
643 |
+
}
|
644 |
+
} else {
|
645 |
+
$snippets[ $slug ] = $code;
|
646 |
+
if ( MainWP_Helper::update_option( 'mainwp_ext_code_snippets', $snippets ) ) {
|
647 |
+
$return['status'] = 'SUCCESS';
|
648 |
+
}
|
649 |
+
}
|
650 |
+
MainWP_Helper::update_option( 'mainwp_ext_snippets_enabled', true, 'yes' );
|
651 |
+
|
652 |
+
return $return;
|
653 |
+
}
|
654 |
+
|
655 |
+
/**
|
656 |
+
* Method snippet_delete_snippet()
|
657 |
+
*
|
658 |
+
* Delete code snippet.
|
659 |
+
*
|
660 |
+
* @param string $slug Snippet slug.
|
661 |
+
* @param string $type Type of snippet.
|
662 |
+
* @param array $snippets An array containing all snipptes.
|
663 |
+
*
|
664 |
+
* @uses MainWP_Helper::update_option() Update option by name.
|
665 |
+
* @uses MainWP_Child_Misc::snippet_update_wp_config() Update the child site wp-config.php file.
|
666 |
+
*
|
667 |
+
* @used-by MainWP_Child_Misc::code_snippet() Initiate Code Snippet actions run_snippet, save_snippet and delete_snippet.
|
668 |
+
*
|
669 |
+
* @return array $return Status response.
|
670 |
+
*/
|
671 |
+
private function snippet_delete_snippet( $slug, $type, $snippets ) {
|
672 |
+
$return = array();
|
673 |
+
if ( 'C' === $type ) { // delete in wp-config file.
|
674 |
+
if ( false !== $this->snippet_update_wp_config( 'delete', $slug ) ) {
|
675 |
+
$return['status'] = 'SUCCESS';
|
676 |
+
}
|
677 |
+
} else {
|
678 |
+
if ( isset( $snippets[ $slug ] ) ) {
|
679 |
+
unset( $snippets[ $slug ] );
|
680 |
+
if ( MainWP_Helper::update_option( 'mainwp_ext_code_snippets', $snippets ) ) {
|
681 |
+
$return['status'] = 'SUCCESS';
|
682 |
+
}
|
683 |
+
} else {
|
684 |
+
$return['status'] = 'SUCCESS';
|
685 |
+
}
|
686 |
+
}
|
687 |
+
return $return;
|
688 |
+
}
|
689 |
+
|
690 |
+
/**
|
691 |
+
* Method snippet_update_wp_config()
|
692 |
+
*
|
693 |
+
* Update the child site wp-config.php file.
|
694 |
+
*
|
695 |
+
* @param string $action Action to perform: Delete, Save.
|
696 |
+
* @param string $slug Snippet slug.
|
697 |
+
* @param string $code Code snippet.
|
698 |
+
*
|
699 |
+
* @used-by MainWP_Child_Misc::snippet_save_snippet() Save code snippet.
|
700 |
+
* @used-by MainWP_Child_Misc::snippet_delete_snippet() Delete code snippet.
|
701 |
+
*
|
702 |
+
* @return bool If remvoed, return true, if not, return false.
|
703 |
+
*/
|
704 |
+
public function snippet_update_wp_config( $action, $slug, $code = '' ) {
|
705 |
+
|
706 |
+
$config_file = '';
|
707 |
+
if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
|
708 |
+
// The config file resides in ABSPATH.
|
709 |
+
$config_file = ABSPATH . 'wp-config.php';
|
710 |
+
} elseif ( file_exists( dirname( ABSPATH ) . '/wp-config.php' ) && ! file_exists( dirname( ABSPATH ) . '/wp-settings.php' ) ) {
|
711 |
+
// The config file resides one level above ABSPATH but is not part of another install.
|
712 |
+
$config_file = dirname( ABSPATH ) . '/wp-config.php';
|
713 |
+
}
|
714 |
+
|
715 |
+
if ( ! empty( $config_file ) ) {
|
716 |
+
$wpConfig = file_get_contents( $config_file );
|
717 |
+
|
718 |
+
if ( 'delete' === $action ) {
|
719 |
+
$wpConfig = preg_replace( '/' . PHP_EOL . '{1,2}\/\*\*\*snippet_' . $slug . '\*\*\*\/(.*)\/\*\*\*end_' . $slug . '\*\*\*\/' . PHP_EOL . '/is', '', $wpConfig );
|
720 |
+
} elseif ( 'save' === $action ) {
|
721 |
+
$wpConfig = preg_replace( '/(\$table_prefix *= *[\'"][^\'|^"]*[\'"] *;)/is', '${1}' . PHP_EOL . PHP_EOL . '/***snippet_' . $slug . '***/' . PHP_EOL . $code . PHP_EOL . '/***end_' . $slug . '***/' . PHP_EOL, $wpConfig );
|
722 |
+
}
|
723 |
+
file_put_contents( $config_file, $wpConfig );
|
724 |
+
return true;
|
725 |
+
}
|
726 |
+
return false;
|
727 |
+
}
|
728 |
+
|
729 |
+
}
|
class/class-mainwp-child-pagespeed.php
CHANGED
@@ -1,97 +1,198 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
4 |
*
|
5 |
* Credits
|
6 |
*
|
7 |
* Plugin-Name: Google Pagespeed Insights
|
8 |
-
* Plugin
|
9 |
* Author: Matt Keys
|
10 |
* Author URI: http://mattkeys.me
|
11 |
-
*
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
*/
|
16 |
|
|
|
17 |
|
|
|
|
|
|
|
|
|
|
|
18 |
class MainWP_Child_Pagespeed {
|
19 |
|
|
|
|
|
|
|
|
|
|
|
20 |
public static $instance = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
public $is_plugin_installed = false;
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
27 |
|
28 |
-
return
|
29 |
}
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
public function __construct() {
|
32 |
-
require_once
|
33 |
if ( is_plugin_active( 'google-pagespeed-insights/google-pagespeed-insights.php' ) ) {
|
34 |
$this->is_plugin_installed = true;
|
35 |
}
|
36 |
|
37 |
-
|
38 |
-
|
|
|
39 |
|
40 |
-
|
41 |
|
42 |
add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) );
|
43 |
}
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
$information = $this->get_sync_data();
|
62 |
-
break;
|
63 |
-
case "check_pages":
|
64 |
-
$information = $this->check_pages();
|
65 |
-
break;
|
66 |
}
|
67 |
}
|
68 |
-
|
69 |
}
|
70 |
|
|
|
|
|
|
|
|
|
|
|
71 |
public function child_deactivation() {
|
72 |
-
|
|
|
73 |
wp_unschedule_event( $sched, 'mainwp_child_pagespeed_cron_check' );
|
74 |
}
|
75 |
}
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
public function init() {
|
78 |
-
|
79 |
-
|
|
|
80 |
|
81 |
-
if ( get_option( 'mainwp_pagespeed_hide_plugin' )
|
82 |
add_filter( 'all_plugins', array( $this, 'hide_plugin' ) );
|
83 |
-
add_action('admin_menu', array($this, 'hide_menu'), 999);
|
84 |
}
|
|
|
85 |
$this->init_cron();
|
86 |
}
|
87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
public function init_cron() {
|
89 |
-
add_action( 'mainwp_child_pagespeed_cron_check', array(
|
90 |
-
|
|
|
91 |
wp_schedule_event( time(), 'daily', 'mainwp_child_pagespeed_cron_check' );
|
92 |
}
|
93 |
}
|
94 |
|
|
|
|
|
|
|
|
|
|
|
95 |
public static function pagespeed_cron_check() {
|
96 |
$count = get_option( 'mainwp_child_pagespeed_count_checking' );
|
97 |
if ( $count >= 7 ) {
|
@@ -111,61 +212,64 @@ class MainWP_Child_Pagespeed {
|
|
111 |
wp_schedule_single_event( time(), 'googlepagespeedinsightschecknow', $worker_args );
|
112 |
}
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
}
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
132 |
break;
|
133 |
-
}
|
134 |
}
|
135 |
}
|
|
|
136 |
}
|
137 |
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
function set_showhide() {
|
151 |
-
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
152 |
-
MainWP_Helper::update_option( 'mainwp_pagespeed_hide_plugin', $hide );
|
153 |
-
$information['result'] = 'SUCCESS';
|
154 |
-
|
155 |
-
return $information;
|
156 |
-
}
|
157 |
-
|
158 |
-
function save_settings() {
|
159 |
$current_values = get_option( 'gpagespeedi_options' );
|
160 |
-
$checkstatus
|
161 |
if ( $checkstatus ) {
|
162 |
return array( 'result' => 'RUNNING' );
|
163 |
}
|
164 |
|
165 |
-
|
166 |
|
167 |
-
$settings = $_POST['settings'];
|
168 |
-
$settings = maybe_unserialize( base64_decode( $settings ) );
|
169 |
|
170 |
if ( is_array( $settings ) ) {
|
171 |
|
@@ -177,14 +281,12 @@ class MainWP_Child_Pagespeed {
|
|
177 |
$current_values['response_language'] = $settings['response_language'];
|
178 |
}
|
179 |
|
180 |
-
|
181 |
-
$current_values['strategy'] = $_POST['strategy'];
|
182 |
-
}
|
183 |
|
184 |
-
|
185 |
$current_values['store_screenshots'] = $settings['store_screenshots'];
|
186 |
}
|
187 |
-
|
188 |
$current_values['use_schedule'] = $settings['use_schedule'];
|
189 |
}
|
190 |
|
@@ -214,12 +316,15 @@ class MainWP_Child_Pagespeed {
|
|
214 |
|
215 |
if ( isset( $settings['check_report'] ) ) {
|
216 |
if ( is_array( $settings['check_report'] ) ) {
|
217 |
-
$current_values['check_pages']
|
218 |
-
$current_values['check_posts']
|
219 |
-
$current_values['check_categories']
|
220 |
-
|
221 |
} else {
|
222 |
-
$current_values['check_pages']
|
|
|
|
|
|
|
223 |
}
|
224 |
}
|
225 |
|
@@ -238,68 +343,128 @@ class MainWP_Child_Pagespeed {
|
|
238 |
|
239 |
$result = $this->get_sync_data( $strategy );
|
240 |
|
241 |
-
// if ( isset( $_POST['doaction'] ) && ( 'check_new_pages' === $_POST['doaction'] || 'recheck_all_pages' === $_POST['doaction'] ) ) {
|
242 |
-
// if ( 'recheck_all_pages' === $_POST['doaction'] ) {
|
243 |
-
// $recheck = true;
|
244 |
-
// } else {
|
245 |
-
// $recheck = false;
|
246 |
-
// }
|
247 |
-
//
|
248 |
-
//
|
249 |
-
// if ($this->do_check_pages($recheck))
|
250 |
-
// $information['checked_pages'] = 1;
|
251 |
-
// }
|
252 |
$information['data'] = $result['data'];
|
|
|
253 |
return $information;
|
254 |
}
|
255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
|
257 |
-
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
$recheck = true;
|
260 |
} else {
|
261 |
$recheck = false;
|
262 |
}
|
263 |
-
$information = $this->do_check_pages($recheck);
|
264 |
-
if (isset($information['checked_pages']) && $information['checked_pages']) {
|
265 |
$information['result'] = 'SUCCESS';
|
266 |
}
|
267 |
return $information;
|
268 |
}
|
269 |
|
270 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
$information = array();
|
272 |
if ( defined( 'GPI_DIRECTORY' ) ) {
|
273 |
$checkstatus = apply_filters( 'gpi_check_status', false );
|
274 |
if ( $checkstatus ) {
|
275 |
$information['error'] = __( 'The API is busy checking other pages, please try again later.', 'gpagespeedi' );
|
276 |
} else {
|
277 |
-
|
278 |
-
do_action( 'run_gpi', $forceRecheck ); // to fix
|
279 |
$information['checked_pages'] = 1;
|
280 |
}
|
281 |
}
|
282 |
return $information;
|
283 |
}
|
284 |
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
|
|
|
|
296 |
public function get_sync_data( $strategy = '' ) {
|
297 |
if ( empty( $strategy ) ) {
|
298 |
$strategy = 'both';
|
299 |
}
|
300 |
|
301 |
$current_values = get_option( 'gpagespeedi_options' );
|
302 |
-
$checkstatus
|
303 |
if ( $checkstatus ) {
|
304 |
return array( 'result' => 'RUNNING' );
|
305 |
}
|
@@ -309,20 +474,20 @@ class MainWP_Child_Pagespeed {
|
|
309 |
$data = array( 'bad_api_key' => $bad_key );
|
310 |
|
311 |
if ( 'both' === $strategy || 'desktop' === $strategy ) {
|
312 |
-
$result
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
}
|
319 |
if ( 'both' === $strategy || 'mobile' === $strategy ) {
|
320 |
-
$result
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
}
|
327 |
|
328 |
$information['data'] = $data;
|
@@ -330,8 +495,26 @@ class MainWP_Child_Pagespeed {
|
|
330 |
return $information;
|
331 |
}
|
332 |
|
333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
global $wpdb;
|
|
|
335 |
if ( ! defined( 'GPI_DIRECTORY' ) ) {
|
336 |
return false;
|
337 |
}
|
@@ -340,9 +523,7 @@ class MainWP_Child_Pagespeed {
|
|
340 |
return false;
|
341 |
}
|
342 |
|
343 |
-
$score_column
|
344 |
-
//$page_stats_column = $strategy . '_page_stats';
|
345 |
-
|
346 |
|
347 |
$data_typestocheck = self::get_filter_options( 'all' );
|
348 |
|
@@ -351,9 +532,7 @@ class MainWP_Child_Pagespeed {
|
|
351 |
|
352 |
$allpagedata = $wpdb->get_results(
|
353 |
$wpdb->prepare(
|
354 |
-
"SELECT ID, URL, $score_column
|
355 |
-
FROM $gpi_page_stats
|
356 |
-
WHERE ($data_typestocheck[0])",
|
357 |
$data_typestocheck[1]
|
358 |
),
|
359 |
ARRAY_A
|
@@ -369,12 +548,7 @@ class MainWP_Child_Pagespeed {
|
|
369 |
|
370 |
$allpagereports = $wpdb->get_results(
|
371 |
$wpdb->prepare(
|
372 |
-
"SELECT r.rule_key, r.rule_name
|
373 |
-
FROM $gpi_page_stats d
|
374 |
-
INNER JOIN $gpi_page_reports r
|
375 |
-
ON r.page_id = d.ID
|
376 |
-
AND r.strategy = '$strategy'
|
377 |
-
WHERE ($reports_typestocheck[0])",
|
378 |
$reports_typestocheck[1]
|
379 |
),
|
380 |
ARRAY_A
|
@@ -396,38 +570,20 @@ class MainWP_Child_Pagespeed {
|
|
396 |
$average_score = number_format( $total_scores / $total_pages );
|
397 |
}
|
398 |
|
399 |
-
// Not Null check for Report List scores
|
400 |
switch ( $strategy ) {
|
401 |
-
|
402 |
-
// case 'both':
|
403 |
-
// $nullcheck = 'desktop_score IS NOT NULL AND mobile_score IS NOT NULL';
|
404 |
-
// break;
|
405 |
-
|
406 |
case 'mobile':
|
407 |
$nullcheck = 'mobile_score IS NOT NULL';
|
408 |
$_select = ' max(mobile_last_modified) as last_modified ';
|
409 |
break;
|
410 |
-
|
411 |
case 'desktop':
|
412 |
$nullcheck = 'desktop_score IS NOT NULL';
|
413 |
$_select = ' max(desktop_last_modified) as last_modified ';
|
414 |
break;
|
415 |
-
|
416 |
}
|
417 |
|
418 |
-
// Get our Data
|
419 |
if ( ! is_null( $reports_typestocheck ) ) {
|
420 |
$gpi_page_stats = $wpdb->prefix . 'gpi_page_stats';
|
421 |
-
$data = $wpdb->get_results(
|
422 |
-
$wpdb->prepare(
|
423 |
-
"SELECT $_select
|
424 |
-
FROM $gpi_page_stats
|
425 |
-
WHERE ($reports_typestocheck[0])
|
426 |
-
AND $nullcheck",
|
427 |
-
$reports_typestocheck[1]
|
428 |
-
),
|
429 |
-
ARRAY_A
|
430 |
-
);
|
431 |
}
|
432 |
|
433 |
return array(
|
@@ -437,120 +593,106 @@ class MainWP_Child_Pagespeed {
|
|
437 |
);
|
438 |
}
|
439 |
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
$typestocheck = array();
|
445 |
|
446 |
-
if($gpi_options['check_pages']) {
|
447 |
-
if(
|
448 |
$typestocheck[] = 'type = %s';
|
449 |
-
$types[1][]
|
450 |
}
|
451 |
}
|
452 |
|
453 |
-
if($gpi_options['check_posts']) {
|
454 |
-
if(
|
455 |
$typestocheck[] = 'type = %s';
|
456 |
-
$types[1][]
|
457 |
}
|
458 |
}
|
459 |
|
460 |
-
if($gpi_options['check_categories']) {
|
461 |
-
if(
|
462 |
$typestocheck[] = 'type = %s';
|
463 |
-
$types[1][]
|
464 |
}
|
465 |
}
|
466 |
-
if($gpi_options['cpt_whitelist']) {
|
467 |
-
if(
|
468 |
|
469 |
$cpt_whitelist_arr = false;
|
470 |
-
if(!empty($gpi_options['cpt_whitelist'])) {
|
471 |
-
$cpt_whitelist_arr = unserialize($gpi_options['cpt_whitelist']);
|
472 |
}
|
473 |
-
$args=array(
|
474 |
'public' => true,
|
475 |
-
'_builtin' => false
|
476 |
);
|
477 |
-
$custom_post_types = get_post_types($args,'names','and');
|
478 |
-
if(
|
479 |
-
$restrict_type = str_replace('gpi_custom_posts-', '', $restrict_type);
|
480 |
-
foreach($custom_post_types as $post_type)
|
481 |
-
|
482 |
-
|
483 |
-
if($post_type == $restrict_type) {
|
484 |
$typestocheck[] = 'type = %s';
|
485 |
-
$types[1][]
|
486 |
}
|
487 |
}
|
488 |
}
|
489 |
} else {
|
490 |
-
foreach($custom_post_types as $post_type)
|
491 |
-
|
492 |
-
if($cpt_whitelist_arr && in_array($post_type, $cpt_whitelist_arr)) {
|
493 |
$typestocheck[] = 'type = %s';
|
494 |
-
$types[1][]
|
495 |
}
|
496 |
}
|
497 |
}
|
498 |
}
|
499 |
}
|
500 |
|
501 |
-
|
502 |
-
global $wpdb;
|
503 |
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
);
|
511 |
|
|
|
512 |
if ( ! empty( $custom_url_types ) ) {
|
513 |
foreach ( $custom_url_types as $custom_url_type ) {
|
514 |
-
|
515 |
-
|
516 |
}
|
517 |
}
|
518 |
}
|
519 |
|
520 |
-
if(!empty($typestocheck)) {
|
521 |
$types[0] = '';
|
522 |
-
foreach($typestocheck as $type)
|
523 |
-
|
524 |
-
if(!is_array($type)) {
|
525 |
$types[0] .= $type . ' OR ';
|
526 |
} else {
|
527 |
-
foreach($type as $custom_post_type)
|
528 |
-
|
529 |
-
$types[0] .= 'type = %s OR ';
|
530 |
$types[1][] = $custom_post_type;
|
531 |
}
|
532 |
}
|
533 |
}
|
534 |
-
$types[0] = rtrim($types[0], ' OR ');
|
535 |
return $types;
|
536 |
}
|
537 |
return null;
|
538 |
}
|
539 |
|
540 |
-
function delete_data( $what ) {
|
541 |
-
global $wpdb;
|
542 |
-
$gpi_page_stats = $wpdb->prefix . 'gpi_page_stats';
|
543 |
-
$gpi_page_reports = $wpdb->prefix . 'gpi_page_reports';
|
544 |
-
$gpi_page_blacklist = $wpdb->prefix . 'gpi_page_blacklist';
|
545 |
-
|
546 |
-
if ( 'purge_reports' === $what ) {
|
547 |
-
$wpdb->query( "TRUNCATE TABLE $gpi_page_stats" );
|
548 |
-
$wpdb->query( "TRUNCATE TABLE $gpi_page_reports" );
|
549 |
-
} elseif ( 'purge_everything' === $what ) {
|
550 |
-
$wpdb->query( "TRUNCATE TABLE $gpi_page_stats" );
|
551 |
-
$wpdb->query( "TRUNCATE TABLE $gpi_page_reports" );
|
552 |
-
$wpdb->query( "TRUNCATE TABLE $gpi_page_blacklist" );
|
553 |
-
}
|
554 |
-
}
|
555 |
}
|
556 |
-
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Page Speed
|
4 |
+
*
|
5 |
+
* MainWP Page Speed extension handler.
|
6 |
+
* Extension URL: https://mainwp.com/extension/page-speed/
|
7 |
+
*
|
8 |
+
* @package MainWP\Child
|
9 |
*
|
10 |
* Credits
|
11 |
*
|
12 |
* Plugin-Name: Google Pagespeed Insights
|
13 |
+
* Plugin-URI: http://mattkeys.me
|
14 |
* Author: Matt Keys
|
15 |
* Author URI: http://mattkeys.me
|
16 |
+
* License: GPLv2 or later
|
17 |
+
*/
|
18 |
+
|
19 |
+
namespace MainWP\Child;
|
|
|
20 |
|
21 |
+
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- to use external code, third party credit.
|
22 |
|
23 |
+
/**
|
24 |
+
* Class MainWP_Child_Pagespeed
|
25 |
+
*
|
26 |
+
* MainWP Page Speed extension handler.
|
27 |
+
*/
|
28 |
class MainWP_Child_Pagespeed {
|
29 |
|
30 |
+
/**
|
31 |
+
* Public static variable to hold the single instance of the class.
|
32 |
+
*
|
33 |
+
* @var mixed Default null
|
34 |
+
*/
|
35 |
public static $instance = null;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Public variable to hold the infomration if the Google Pagespeed Insights plugin is installed on the child site.
|
39 |
+
*
|
40 |
+
* @var bool If Google Pagespeed Insights intalled, return true, if not, return false.
|
41 |
+
*/
|
42 |
public $is_plugin_installed = false;
|
43 |
|
44 |
+
/**
|
45 |
+
* Method instance()
|
46 |
+
*
|
47 |
+
* Create a public static instance.
|
48 |
+
*
|
49 |
+
* @return mixed Class instance.
|
50 |
+
*/
|
51 |
+
public static function instance() {
|
52 |
+
if ( null === self::$instance ) {
|
53 |
+
self::$instance = new self();
|
54 |
}
|
55 |
|
56 |
+
return self::$instance;
|
57 |
}
|
58 |
|
59 |
+
/**
|
60 |
+
* MainWP_Child_Pagespeed constructor.
|
61 |
+
*
|
62 |
+
* Run any time class is called.
|
63 |
+
*
|
64 |
+
* @return void
|
65 |
+
*/
|
66 |
public function __construct() {
|
67 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
68 |
if ( is_plugin_active( 'google-pagespeed-insights/google-pagespeed-insights.php' ) ) {
|
69 |
$this->is_plugin_installed = true;
|
70 |
}
|
71 |
|
72 |
+
if ( ! $this->is_plugin_installed ) {
|
73 |
+
return;
|
74 |
+
}
|
75 |
|
76 |
+
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
77 |
|
78 |
add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) );
|
79 |
}
|
80 |
|
81 |
+
/**
|
82 |
+
* Method sync_others_data()
|
83 |
+
*
|
84 |
+
* Sync the Google Pagespeed Insights plugin data.
|
85 |
+
*
|
86 |
+
* @param array $information Array containing the sync information.
|
87 |
+
* @param array $data Array containing the Google Pagespeed Insights plugin data to be synced.
|
88 |
+
*
|
89 |
+
* @return array $information Array containing the sync information.
|
90 |
+
*/
|
91 |
+
public function sync_others_data( $information, $data = array() ) {
|
92 |
+
if ( isset( $data['syncPageSpeedData'] ) && $data['syncPageSpeedData'] ) {
|
93 |
+
try {
|
94 |
+
$information['syncPageSpeedData'] = $this->get_sync_data();
|
95 |
+
} catch ( \Exception $e ) {
|
96 |
+
// ok!
|
|
|
|
|
|
|
|
|
|
|
97 |
}
|
98 |
}
|
99 |
+
return $information;
|
100 |
}
|
101 |
|
102 |
+
/**
|
103 |
+
* Method child_deactivation()
|
104 |
+
*
|
105 |
+
* Unschedule scheduled events on MainWP Child plugin deactivation.
|
106 |
+
*/
|
107 |
public function child_deactivation() {
|
108 |
+
$sched = wp_next_scheduled( 'mainwp_child_pagespeed_cron_check' );
|
109 |
+
if ( $sched ) {
|
110 |
wp_unschedule_event( $sched, 'mainwp_child_pagespeed_cron_check' );
|
111 |
}
|
112 |
}
|
113 |
|
114 |
+
/**
|
115 |
+
* Method init()
|
116 |
+
*
|
117 |
+
* Initiate action hooks.
|
118 |
+
*
|
119 |
+
* @return void
|
120 |
+
*/
|
121 |
public function init() {
|
122 |
+
if ( ! $this->is_plugin_installed ) {
|
123 |
+
return;
|
124 |
+
}
|
125 |
|
126 |
+
if ( 'hide' === get_option( 'mainwp_pagespeed_hide_plugin' ) ) {
|
127 |
add_filter( 'all_plugins', array( $this, 'hide_plugin' ) );
|
128 |
+
add_action( 'admin_menu', array( $this, 'hide_menu' ), 999 );
|
129 |
}
|
130 |
+
|
131 |
$this->init_cron();
|
132 |
}
|
133 |
|
134 |
+
/**
|
135 |
+
* Method hide_plugin()
|
136 |
+
*
|
137 |
+
* Remove the Google Pagespeed Insights plugin from the list of all plugins when the plugin is hidden.
|
138 |
+
*
|
139 |
+
* @param array $plugins Array containing all installed plugins.
|
140 |
+
*
|
141 |
+
* @return array $plugins Array containing all installed plugins without the Google Pagespeed Insights plugin.
|
142 |
+
*/
|
143 |
+
public function hide_plugin( $plugins ) {
|
144 |
+
foreach ( $plugins as $key => $value ) {
|
145 |
+
$plugin_slug = basename( $key, '.php' );
|
146 |
+
if ( 'google-pagespeed-insights' === $plugin_slug ) {
|
147 |
+
unset( $plugins[ $key ] );
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
return $plugins;
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Method hide_menu()
|
156 |
+
*
|
157 |
+
* Remove the Google Pagespeed Insights menu item when the plugin is hidden.
|
158 |
+
*/
|
159 |
+
public function hide_menu() {
|
160 |
+
|
161 |
+
/**
|
162 |
+
* WordPress submenu array.
|
163 |
+
*
|
164 |
+
* @global object
|
165 |
+
*/
|
166 |
+
global $submenu;
|
167 |
+
|
168 |
+
if ( isset( $submenu['tools.php'] ) ) {
|
169 |
+
foreach ( $submenu['tools.php'] as $key => $menu ) {
|
170 |
+
if ( 'google-pagespeed-insights' == $menu[2] ) {
|
171 |
+
unset( $submenu['tools.php'][ $key ] );
|
172 |
+
break;
|
173 |
+
}
|
174 |
+
}
|
175 |
+
}
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Method init_cron()
|
180 |
+
*
|
181 |
+
* Schedule daily Page Speed checks.
|
182 |
+
*/
|
183 |
public function init_cron() {
|
184 |
+
add_action( 'mainwp_child_pagespeed_cron_check', array( __CLASS__, 'pagespeed_cron_check' ) );
|
185 |
+
$sched = wp_next_scheduled( 'mainwp_child_pagespeed_cron_check' );
|
186 |
+
if ( false === $sched ) {
|
187 |
wp_schedule_event( time(), 'daily', 'mainwp_child_pagespeed_cron_check' );
|
188 |
}
|
189 |
}
|
190 |
|
191 |
+
/**
|
192 |
+
* Method pagespeed_cron_check()
|
193 |
+
*
|
194 |
+
* Schedule single Page Speed check event.
|
195 |
+
*/
|
196 |
public static function pagespeed_cron_check() {
|
197 |
$count = get_option( 'mainwp_child_pagespeed_count_checking' );
|
198 |
if ( $count >= 7 ) {
|
212 |
wp_schedule_single_event( time(), 'googlepagespeedinsightschecknow', $worker_args );
|
213 |
}
|
214 |
|
215 |
+
/**
|
216 |
+
* Method actions()
|
217 |
+
*
|
218 |
+
* Fire off certain Google Pagespeed Insights plugin actions.
|
219 |
+
*
|
220 |
+
* @uses MainWP_Child_Pagespeed::save_settings() Save the plugin settings.
|
221 |
+
* @uses MainWP_Child_Pagespeed::set_showhide() Hide or unhide the Google Pagespeed Insights plugin.
|
222 |
+
* @uses MainWP_Child_Pagespeed::get_sync_data() Get the Google Pagespeed Insights plugin data and store it in the sync request.
|
223 |
+
* @uses MainWP_Child_Pagespeed::check_pages() Check pages page speed.
|
224 |
+
*/
|
225 |
+
public function action() {
|
226 |
+
$information = array();
|
227 |
+
if ( ! defined( 'GPI_DIRECTORY' ) ) {
|
228 |
+
$information['error'] = 'Please install Google Pagespeed Insights plugin on child website';
|
229 |
+
MainWP_Helper::write( $information );
|
230 |
}
|
231 |
+
if ( isset( $_POST['mwp_action'] ) ) {
|
232 |
+
$mwp_action = ! empty( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
233 |
+
switch ( $mwp_action ) {
|
234 |
+
case 'save_settings':
|
235 |
+
$information = $this->save_settings();
|
236 |
+
break;
|
237 |
+
case 'set_showhide':
|
238 |
+
$information = $this->set_showhide();
|
239 |
+
break;
|
240 |
+
case 'sync_data':
|
241 |
+
$information = $this->get_sync_data();
|
242 |
+
break;
|
243 |
+
case 'check_pages':
|
244 |
+
$information = $this->check_pages();
|
245 |
break;
|
|
|
246 |
}
|
247 |
}
|
248 |
+
MainWP_Helper::write( $information );
|
249 |
}
|
250 |
|
251 |
+
/**
|
252 |
+
* Method save_settings()
|
253 |
+
*
|
254 |
+
* Save the plugin settings.
|
255 |
+
*
|
256 |
+
* @uses MainWP_Child_Pagespeed::delete_data() Delete reports or all plugin data.
|
257 |
+
*
|
258 |
+
* @used-by MainWP_Child_Pagespeed::actions() Fire off certain Google Pagespeed Insights plugin actions.
|
259 |
+
*
|
260 |
+
* @return array Action result.
|
261 |
+
*/
|
262 |
+
public function save_settings() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
$current_values = get_option( 'gpagespeedi_options' );
|
264 |
+
$checkstatus = apply_filters( 'gpi_check_status', false );
|
265 |
if ( $checkstatus ) {
|
266 |
return array( 'result' => 'RUNNING' );
|
267 |
}
|
268 |
|
269 |
+
$information = array();
|
270 |
|
271 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
272 |
+
$settings = maybe_unserialize( base64_decode( $settings ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode required for backwards compatibility.
|
273 |
|
274 |
if ( is_array( $settings ) ) {
|
275 |
|
281 |
$current_values['response_language'] = $settings['response_language'];
|
282 |
}
|
283 |
|
284 |
+
$current_values['strategy'] = isset( $_POST['strategy'] ) ? sanitize_text_field( wp_unslash( $_POST['strategy'] ) ) : '';
|
|
|
|
|
285 |
|
286 |
+
if ( isset( $settings['store_screenshots'] ) ) {
|
287 |
$current_values['store_screenshots'] = $settings['store_screenshots'];
|
288 |
}
|
289 |
+
if ( isset( $settings['use_schedule'] ) ) {
|
290 |
$current_values['use_schedule'] = $settings['use_schedule'];
|
291 |
}
|
292 |
|
316 |
|
317 |
if ( isset( $settings['check_report'] ) ) {
|
318 |
if ( is_array( $settings['check_report'] ) ) {
|
319 |
+
$current_values['check_pages'] = in_array( 'page', $settings['check_report'] ) ? true : false;
|
320 |
+
$current_values['check_posts'] = in_array( 'post', $settings['check_report'] ) ? true : false;
|
321 |
+
$current_values['check_categories'] = in_array( 'category', $settings['check_report'] ) ? true : false;
|
322 |
+
$current_values['check_custom_urls'] = in_array( 'custom_urls', $settings['check_report'] ) ? true : false;
|
323 |
} else {
|
324 |
+
$current_values['check_pages'] = false;
|
325 |
+
$current_values['check_posts'] = false;
|
326 |
+
$current_values['check_categories'] = false;
|
327 |
+
$current_values['check_custom_urls'] = false;
|
328 |
}
|
329 |
}
|
330 |
|
343 |
|
344 |
$result = $this->get_sync_data( $strategy );
|
345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
$information['data'] = $result['data'];
|
347 |
+
|
348 |
return $information;
|
349 |
}
|
350 |
|
351 |
+
/**
|
352 |
+
* Method delete_data()
|
353 |
+
*
|
354 |
+
* Delete reports or all plugin data.
|
355 |
+
*
|
356 |
+
* @used-by MainWP_Child_Pagespeed::save_settings() Save the plugin settings.
|
357 |
+
*
|
358 |
+
* @param string $what Contains information about what to delete, just reports or everything.
|
359 |
+
*/
|
360 |
+
public function delete_data( $what ) {
|
361 |
+
|
362 |
+
/**
|
363 |
+
* WordPress Database instance.
|
364 |
+
*
|
365 |
+
* @global object $wpdb
|
366 |
+
*/
|
367 |
+
global $wpdb;
|
368 |
+
|
369 |
+
$gpi_page_stats = $wpdb->prefix . 'gpi_page_stats';
|
370 |
+
$gpi_page_reports = $wpdb->prefix . 'gpi_page_reports';
|
371 |
+
$gpi_page_blacklist = $wpdb->prefix . 'gpi_page_blacklist';
|
372 |
+
// phpcs:disable -- safe queries. Required to achieve desired results, pull request solutions appreciated.
|
373 |
+
if ( 'purge_reports' === $what ) {
|
374 |
+
$wpdb->query( "TRUNCATE TABLE $gpi_page_stats" );
|
375 |
+
$wpdb->query( "TRUNCATE TABLE $gpi_page_reports" );
|
376 |
+
} elseif ( 'purge_everything' === $what ) {
|
377 |
+
$wpdb->query( "TRUNCATE TABLE $gpi_page_stats" );
|
378 |
+
$wpdb->query( "TRUNCATE TABLE $gpi_page_reports" );
|
379 |
+
$wpdb->query( "TRUNCATE TABLE $gpi_page_blacklist" );
|
380 |
+
}
|
381 |
+
// phpcs:enable
|
382 |
+
}
|
383 |
+
|
384 |
+
/**
|
385 |
+
* Method set_showhide()
|
386 |
+
*
|
387 |
+
* Hide or unhide the Google Pagespeed Insights plugin.
|
388 |
+
*
|
389 |
+
* @used-by MainWP_Child_Pagespeed::actions() Fire off certain Google Pagespeed Insights plugin actions.
|
390 |
+
*
|
391 |
+
* @return array Action result.
|
392 |
+
*/
|
393 |
+
public function set_showhide() {
|
394 |
+
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
395 |
+
MainWP_Helper::update_option( 'mainwp_pagespeed_hide_plugin', $hide );
|
396 |
+
$information['result'] = 'SUCCESS';
|
397 |
|
398 |
+
return $information;
|
399 |
+
}
|
400 |
+
|
401 |
+
/**
|
402 |
+
* Method check_pages()
|
403 |
+
*
|
404 |
+
* Initiate the check pages page speed.
|
405 |
+
*
|
406 |
+
* @uses MainWP_Child_Pagespeed::do_check_pages() If needed, force recheck proces, if not just check.
|
407 |
+
*
|
408 |
+
* @used-by MainWP_Child_Pagespeed::actions() Fire off certain Google Pagespeed Insights plugin actions.
|
409 |
+
*
|
410 |
+
* @return array Action result.
|
411 |
+
*/
|
412 |
+
public function check_pages() {
|
413 |
+
if ( isset( $_POST['force_recheck'] ) && ! empty( $_POST['force_recheck'] ) ) {
|
414 |
$recheck = true;
|
415 |
} else {
|
416 |
$recheck = false;
|
417 |
}
|
418 |
+
$information = $this->do_check_pages( $recheck );
|
419 |
+
if ( isset( $information['checked_pages'] ) && $information['checked_pages'] ) {
|
420 |
$information['result'] = 'SUCCESS';
|
421 |
}
|
422 |
return $information;
|
423 |
}
|
424 |
|
425 |
+
/**
|
426 |
+
* Method do_check_pages()
|
427 |
+
*
|
428 |
+
* Check or force re-check pages page speed.
|
429 |
+
*
|
430 |
+
* @param bool $forceRecheck If true, force recheck process, if false, just regular check.
|
431 |
+
*
|
432 |
+
* @return array Action result.
|
433 |
+
*/
|
434 |
+
public function do_check_pages( $forceRecheck = false ) {
|
435 |
$information = array();
|
436 |
if ( defined( 'GPI_DIRECTORY' ) ) {
|
437 |
$checkstatus = apply_filters( 'gpi_check_status', false );
|
438 |
if ( $checkstatus ) {
|
439 |
$information['error'] = __( 'The API is busy checking other pages, please try again later.', 'gpagespeedi' );
|
440 |
} else {
|
441 |
+
do_action( 'run_gpi', $forceRecheck );
|
|
|
442 |
$information['checked_pages'] = 1;
|
443 |
}
|
444 |
}
|
445 |
return $information;
|
446 |
}
|
447 |
|
448 |
+
/**
|
449 |
+
* Method get_sync_data()
|
450 |
+
*
|
451 |
+
* Get the Google Pagespeed Insights plugin data and store it in the sync request.
|
452 |
+
*
|
453 |
+
* @param string $strategy Contains the selected strategy (desktop, mobile or both).
|
454 |
+
*
|
455 |
+
* @uses MainWP_Child_Pagespeed::cal_pagespeed_data() Calculate page speed scores.
|
456 |
+
*
|
457 |
+
* @used-by MainWP_Child_Pagespeed::actions() Fire off certain Google Pagespeed Insights plugin actions.
|
458 |
+
*
|
459 |
+
* @return array Action result.
|
460 |
+
*/
|
461 |
public function get_sync_data( $strategy = '' ) {
|
462 |
if ( empty( $strategy ) ) {
|
463 |
$strategy = 'both';
|
464 |
}
|
465 |
|
466 |
$current_values = get_option( 'gpagespeedi_options' );
|
467 |
+
$checkstatus = apply_filters( 'gpi_check_status', false );
|
468 |
if ( $checkstatus ) {
|
469 |
return array( 'result' => 'RUNNING' );
|
470 |
}
|
474 |
$data = array( 'bad_api_key' => $bad_key );
|
475 |
|
476 |
if ( 'both' === $strategy || 'desktop' === $strategy ) {
|
477 |
+
$result = self::cal_pagespeed_data( 'desktop' );
|
478 |
+
if ( ! empty( $result ) && is_array( $result ) ) {
|
479 |
+
$data['desktop_score'] = $result['average_score'];
|
480 |
+
$data['desktop_total_pages'] = $result['total_pages'];
|
481 |
+
$data['desktop_last_modified'] = $result['last_modified'];
|
482 |
+
}
|
483 |
}
|
484 |
if ( 'both' === $strategy || 'mobile' === $strategy ) {
|
485 |
+
$result = self::cal_pagespeed_data( 'mobile' );
|
486 |
+
if ( ! empty( $result ) && is_array( $result ) ) {
|
487 |
+
$data['mobile_score'] = $result['average_score'];
|
488 |
+
$data['mobile_total_pages'] = $result['total_pages'];
|
489 |
+
$data['mobile_last_modified'] = $result['last_modified'];
|
490 |
+
}
|
491 |
}
|
492 |
|
493 |
$information['data'] = $data;
|
495 |
return $information;
|
496 |
}
|
497 |
|
498 |
+
/**
|
499 |
+
* Method cal_pagespeed_data()
|
500 |
+
*
|
501 |
+
* Calculate page speed scores.
|
502 |
+
*
|
503 |
+
* @param string $strategy Contains the selected strategy (desktop, mobile or both).
|
504 |
+
*
|
505 |
+
* @used-by MainWP_Child_Pagespeed::get_sync_data() Get the Google Pagespeed Insights plugin data and store it in the sync request.
|
506 |
+
*
|
507 |
+
* @return array Array containing data including last modified timespamp, average score and number of pages.
|
508 |
+
*/
|
509 |
+
public static function cal_pagespeed_data( $strategy ) {
|
510 |
+
|
511 |
+
/**
|
512 |
+
* WordPress Database instance.
|
513 |
+
*
|
514 |
+
* @global object $wpdb
|
515 |
+
*/
|
516 |
global $wpdb;
|
517 |
+
|
518 |
if ( ! defined( 'GPI_DIRECTORY' ) ) {
|
519 |
return false;
|
520 |
}
|
523 |
return false;
|
524 |
}
|
525 |
|
526 |
+
$score_column = $strategy . '_score';
|
|
|
|
|
527 |
|
528 |
$data_typestocheck = self::get_filter_options( 'all' );
|
529 |
|
532 |
|
533 |
$allpagedata = $wpdb->get_results(
|
534 |
$wpdb->prepare(
|
535 |
+
"SELECT ID, URL, $score_column FROM $gpi_page_stats WHERE ( $data_typestocheck[0] )", // phpcs:ignore -- safe query.
|
|
|
|
|
536 |
$data_typestocheck[1]
|
537 |
),
|
538 |
ARRAY_A
|
548 |
|
549 |
$allpagereports = $wpdb->get_results(
|
550 |
$wpdb->prepare(
|
551 |
+
"SELECT r.rule_key, r.rule_name FROM $gpi_page_stats d INNER JOIN $gpi_page_reports r ON r.page_id = d.ID AND r.strategy = '$strategy' WHERE ( $reports_typestocheck[0] )", // phpcs:ignore -- safe query.
|
|
|
|
|
|
|
|
|
|
|
552 |
$reports_typestocheck[1]
|
553 |
),
|
554 |
ARRAY_A
|
570 |
$average_score = number_format( $total_scores / $total_pages );
|
571 |
}
|
572 |
|
|
|
573 |
switch ( $strategy ) {
|
|
|
|
|
|
|
|
|
|
|
574 |
case 'mobile':
|
575 |
$nullcheck = 'mobile_score IS NOT NULL';
|
576 |
$_select = ' max(mobile_last_modified) as last_modified ';
|
577 |
break;
|
|
|
578 |
case 'desktop':
|
579 |
$nullcheck = 'desktop_score IS NOT NULL';
|
580 |
$_select = ' max(desktop_last_modified) as last_modified ';
|
581 |
break;
|
|
|
582 |
}
|
583 |
|
|
|
584 |
if ( ! is_null( $reports_typestocheck ) ) {
|
585 |
$gpi_page_stats = $wpdb->prefix . 'gpi_page_stats';
|
586 |
+
$data = $wpdb->get_results( $wpdb->prepare( "SELECT $_select FROM $gpi_page_stats WHERE ( $reports_typestocheck[0] ) AND $nullcheck", $reports_typestocheck[1] ), ARRAY_A ); // phpcs:ignore -- safe query.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
587 |
}
|
588 |
|
589 |
return array(
|
593 |
);
|
594 |
}
|
595 |
|
596 |
+
/**
|
597 |
+
* Method get_filter_options()
|
598 |
+
*
|
599 |
+
* @param string $restrict_type Contains the restricted types.
|
600 |
+
*
|
601 |
+
* @return array Array containing the list of item types to check (posts, pages, categories,...).
|
602 |
+
*/
|
603 |
+
public static function get_filter_options( $restrict_type = 'all' ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
604 |
+
|
605 |
+
$types = array();
|
606 |
+
$gpi_options = get_option( 'gpagespeedi_options' );
|
607 |
$typestocheck = array();
|
608 |
|
609 |
+
if ( $gpi_options['check_pages'] ) {
|
610 |
+
if ( 'all' == $restrict_type || 'ignored' == $restrict_type || 'pages' == $restrict_type ) {
|
611 |
$typestocheck[] = 'type = %s';
|
612 |
+
$types[1][] = 'page';
|
613 |
}
|
614 |
}
|
615 |
|
616 |
+
if ( $gpi_options['check_posts'] ) {
|
617 |
+
if ( 'all' == $restrict_type || 'ignored' == $restrict_type || 'posts' == $restrict_type ) {
|
618 |
$typestocheck[] = 'type = %s';
|
619 |
+
$types[1][] = 'post';
|
620 |
}
|
621 |
}
|
622 |
|
623 |
+
if ( $gpi_options['check_categories'] ) {
|
624 |
+
if ( 'all' == $restrict_type || 'ignored' == $restrict_type || 'categories' == $restrict_type ) {
|
625 |
$typestocheck[] = 'type = %s';
|
626 |
+
$types[1][] = 'category';
|
627 |
}
|
628 |
}
|
629 |
+
if ( $gpi_options['cpt_whitelist'] ) {
|
630 |
+
if ( 'all' == $restrict_type || 'ignored' == $restrict_type || stristr( $restrict_type, 'gpi_custom_posts' ) ) {
|
631 |
|
632 |
$cpt_whitelist_arr = false;
|
633 |
+
if ( ! empty( $gpi_options['cpt_whitelist'] ) ) {
|
634 |
+
$cpt_whitelist_arr = unserialize( $gpi_options['cpt_whitelist'] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- unserialize usage required to achieve desired results, pull request solutions appreciated.
|
635 |
}
|
636 |
+
$args = array(
|
637 |
'public' => true,
|
638 |
+
'_builtin' => false,
|
639 |
);
|
640 |
+
$custom_post_types = get_post_types( $args, 'names', 'and' );
|
641 |
+
if ( 'gpi_custom_posts' != $restrict_type && 'all' != $restrict_type && 'ignored' != $restrict_type ) {
|
642 |
+
$restrict_type = str_replace( 'gpi_custom_posts-', '', $restrict_type );
|
643 |
+
foreach ( $custom_post_types as $post_type ) {
|
644 |
+
if ( $cpt_whitelist_arr && in_array( $post_type, $cpt_whitelist_arr ) ) {
|
645 |
+
if ( $post_type == $restrict_type ) {
|
|
|
646 |
$typestocheck[] = 'type = %s';
|
647 |
+
$types[1][] = $custom_post_types[ $post_type ];
|
648 |
}
|
649 |
}
|
650 |
}
|
651 |
} else {
|
652 |
+
foreach ( $custom_post_types as $post_type ) {
|
653 |
+
if ( $cpt_whitelist_arr && in_array( $post_type, $cpt_whitelist_arr ) ) {
|
|
|
654 |
$typestocheck[] = 'type = %s';
|
655 |
+
$types[1][] = $custom_post_types[ $post_type ];
|
656 |
}
|
657 |
}
|
658 |
}
|
659 |
}
|
660 |
}
|
661 |
|
662 |
+
if ( $gpi_options['check_custom_urls'] ) {
|
|
|
663 |
|
664 |
+
/**
|
665 |
+
* WordPress Database instance.
|
666 |
+
*
|
667 |
+
* @global object $wpdb
|
668 |
+
*/
|
669 |
+
global $wpdb;
|
|
|
670 |
|
671 |
+
$custom_url_types = $wpdb->get_col( 'SELECT DISTINCT type FROM ' . $wpdb->prefix . 'gpi_custom_urls ' );
|
672 |
if ( ! empty( $custom_url_types ) ) {
|
673 |
foreach ( $custom_url_types as $custom_url_type ) {
|
674 |
+
$typestocheck[] = 'type = %s';
|
675 |
+
$types[1][] = $custom_url_type;
|
676 |
}
|
677 |
}
|
678 |
}
|
679 |
|
680 |
+
if ( ! empty( $typestocheck ) ) {
|
681 |
$types[0] = '';
|
682 |
+
foreach ( $typestocheck as $type ) {
|
683 |
+
if ( ! is_array( $type ) ) {
|
|
|
684 |
$types[0] .= $type . ' OR ';
|
685 |
} else {
|
686 |
+
foreach ( $type as $custom_post_type ) {
|
687 |
+
$types[0] .= 'type = %s OR ';
|
|
|
688 |
$types[1][] = $custom_post_type;
|
689 |
}
|
690 |
}
|
691 |
}
|
692 |
+
$types[0] = rtrim( $types[0], ' OR ' );
|
693 |
return $types;
|
694 |
}
|
695 |
return null;
|
696 |
}
|
697 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
698 |
}
|
|
class/class-mainwp-child-plugins-check.php
CHANGED
@@ -1,65 +1,128 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
4 |
*
|
5 |
-
* Credits
|
6 |
*
|
7 |
* Plugin-Name: Vendi Abandoned Plugin Check
|
8 |
* Plugin URI: https://wordpress.org/plugins/vendi-abandoned-plugin-check/
|
9 |
* Author: Vendi Advertising (Chris Haas)
|
10 |
* Author URI: https://wp-staging.com
|
11 |
* License: GPLv2
|
12 |
-
|
13 |
-
*/
|
14 |
|
15 |
-
|
16 |
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
|
|
|
|
|
|
|
|
|
|
|
19 |
private $cron_name_watcher = 'mainwp_child_cron_plugin_health_check_watcher';
|
20 |
|
|
|
|
|
|
|
|
|
|
|
21 |
private $cron_name_daily = 'mainwp_child_cron_plugin_health_check_daily';
|
22 |
|
|
|
|
|
|
|
|
|
|
|
23 |
private $cron_name_batching = 'mainwp_child_cron_plugin_health_check_batching';
|
24 |
|
|
|
|
|
|
|
|
|
|
|
25 |
private $tran_name_plugin_timestamps = 'mainwp_child_tran_name_plugin_timestamps';
|
26 |
|
|
|
|
|
|
|
|
|
|
|
27 |
private $tran_name_plugins_to_batch = 'mainwp_child_tran_name_plugins_to_batch';
|
28 |
|
|
|
|
|
|
|
|
|
|
|
29 |
private $option_name_last_daily_run = 'mainwp_child_plugin_last_daily_run';
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
}
|
35 |
|
36 |
-
return
|
37 |
}
|
38 |
|
|
|
|
|
|
|
|
|
|
|
39 |
public function __construct() {
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
add_filter( 'plugins_api_args', array( $this, 'modify_plugin_api_search_query' ), 10, 2 );
|
51 |
-
|
52 |
-
add_action( 'mainwp_child_deactivation', array( $this, 'cleanup_deactivation' ) );
|
53 |
-
}
|
54 |
}
|
55 |
|
|
|
|
|
|
|
|
|
|
|
56 |
private function cleanup_basic() {
|
57 |
wp_clear_scheduled_hook( $this->cron_name_daily );
|
58 |
wp_clear_scheduled_hook( $this->cron_name_batching );
|
59 |
delete_transient( $this->tran_name_plugins_to_batch );
|
60 |
}
|
61 |
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
public function cleanup_deactivation( $del = true ) {
|
64 |
$this->cleanup_basic();
|
65 |
wp_clear_scheduled_hook( $this->cron_name_watcher );
|
@@ -69,7 +132,13 @@ class MainWP_Child_Plugins_Check {
|
|
69 |
}
|
70 |
}
|
71 |
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
public function modify_plugin_api_search_query( $args, $action ) {
|
74 |
if ( isset( $action ) && 'query_plugins' === $action ) {
|
75 |
|
@@ -87,6 +156,11 @@ class MainWP_Child_Plugins_Check {
|
|
87 |
return $args;
|
88 |
}
|
89 |
|
|
|
|
|
|
|
|
|
|
|
90 |
public function perform_watchdog() {
|
91 |
if ( false === wp_next_scheduled( $this->cron_name_daily ) && false === wp_next_scheduled( $this->cron_name_batching ) ) {
|
92 |
$last_run = get_option( $this->option_name_last_daily_run );
|
@@ -97,7 +171,6 @@ class MainWP_Child_Plugins_Check {
|
|
97 |
$last_run = new \DateTime( '@' . $last_run );
|
98 |
}
|
99 |
|
100 |
-
//Get now
|
101 |
$now = new \DateTime();
|
102 |
|
103 |
if ( false === $last_run || (int) $now->diff( $last_run )->format( '%h' ) >= 24 ) {
|
@@ -111,23 +184,26 @@ class MainWP_Child_Plugins_Check {
|
|
111 |
}
|
112 |
}
|
113 |
|
|
|
|
|
|
|
114 |
public function schedule_watchdog() {
|
115 |
-
//For testing
|
116 |
-
//$this->cleanup_deactivation();
|
117 |
-
|
118 |
-
//Schedule a global watching cron just in case both other crons get killed
|
119 |
if ( ! wp_next_scheduled( $this->cron_name_watcher ) ) {
|
120 |
wp_schedule_event( time(), 'hourly', $this->cron_name_watcher );
|
121 |
}
|
122 |
-
|
123 |
}
|
124 |
|
|
|
|
|
|
|
|
|
|
|
125 |
public function get_plugins_outdate_info() {
|
126 |
$plugins_outdate = get_transient( $this->tran_name_plugin_timestamps );
|
127 |
if ( ! is_array( $plugins_outdate ) ) {
|
128 |
$plugins_outdate = array();
|
129 |
}
|
130 |
-
if ( ! function_exists( 'get_plugins' ) ) {
|
131 |
require_once ABSPATH . '/wp-admin/includes/plugin.php';
|
132 |
}
|
133 |
$plugins = get_plugins();
|
@@ -143,67 +219,44 @@ class MainWP_Child_Plugins_Check {
|
|
143 |
}
|
144 |
|
145 |
return $plugins_outdate;
|
146 |
-
|
147 |
}
|
148 |
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
//See if this specific plugin is in the known list
|
162 |
-
if( array_key_exists( $plugin_file, $plugin_info ) )
|
163 |
-
{
|
164 |
-
//Get now
|
165 |
-
$now = new \DateTime();
|
166 |
-
$last_updated = $plugin_info[ $plugin_file ]['last_updated'];
|
167 |
-
|
168 |
-
//Last updated is stored as timestamp, get a real date
|
169 |
-
$plugin_last_updated_date = new \DateTime( '@' . $last_updated );
|
170 |
-
|
171 |
-
//Compute days between now and plugin last updated
|
172 |
-
$diff_in_days = $now->diff( $plugin_last_updated_date )->format( '%a' );
|
173 |
-
|
174 |
-
//Customizable number of days for tolerance
|
175 |
-
$tolerance_in_days = get_option( 'mainwp_child_plugintheme_days_outdate', 365 );
|
176 |
-
|
177 |
-
//If we're outside the window for tolerance show a message
|
178 |
-
if( $diff_in_days > $tolerance_in_days )
|
179 |
-
{
|
180 |
-
$plugin_meta[] = sprintf( '<strong style="color: #f00;">This plugin has not been updated by the author in %1$d days!</strong>', $diff_in_days );
|
181 |
-
}
|
182 |
-
else
|
183 |
-
{
|
184 |
-
$plugin_meta[] = sprintf( '<span style="color: #090;">This plugin was last updated by the author in %1$d days ago.</span>', $diff_in_days );
|
185 |
}
|
186 |
}
|
187 |
-
|
188 |
-
return $plugin_meta;
|
189 |
}
|
190 |
|
|
|
|
|
|
|
|
|
|
|
191 |
public function run_check() {
|
192 |
-
if ( ! function_exists( 'get_plugins' ) ) {
|
193 |
require_once ABSPATH . '/wp-admin/includes/plugin.php';
|
194 |
}
|
195 |
|
196 |
-
//Get our previous results
|
197 |
$responses = get_transient( $this->tran_name_plugin_timestamps );
|
198 |
|
199 |
if ( false === $responses || ! is_array( $responses ) ) {
|
200 |
$responses = array();
|
201 |
}
|
202 |
|
203 |
-
//Get our previous cache of plugins for batching
|
204 |
$all_plugins = get_transient( $this->tran_name_plugins_to_batch );
|
205 |
|
206 |
-
//If there wasn't a previous cache
|
207 |
if ( false === $all_plugins || ! is_array( $all_plugins ) ) {
|
208 |
$plugins = get_plugins();
|
209 |
if ( is_array( $plugins ) ) {
|
@@ -222,29 +275,30 @@ class MainWP_Child_Plugins_Check {
|
|
222 |
}
|
223 |
|
224 |
$avoid_plugins = array( 'sitepress-multilingual-cms/sitepress.php' );
|
225 |
-
|
226 |
-
|
|
|
227 |
$tolerance_in_days = get_option( 'mainwp_child_plugintheme_days_outdate', 365 );
|
228 |
|
229 |
-
//Loop through each known plugin
|
230 |
foreach ( $plugins_to_scan as $slug => $v ) {
|
231 |
if ( in_array( $slug, $avoid_plugins ) ) {
|
232 |
continue;
|
233 |
}
|
234 |
-
//Try to get the raw information for this plugin
|
235 |
$body = $this->try_get_response_body( $slug, false );
|
236 |
|
237 |
-
//We couldn't get any information, skip this plugin
|
238 |
if ( false === $body ) {
|
239 |
continue;
|
240 |
}
|
241 |
|
242 |
-
//Deserialize the response
|
243 |
$obj = maybe_unserialize( $body );
|
244 |
|
245 |
$now = new \DateTime();
|
246 |
|
247 |
-
//Sanity check that deserialization worked and that our property exists
|
248 |
if ( false !== $obj && is_object( $obj ) && property_exists( $obj, 'last_updated' ) ) {
|
249 |
if ( version_compare( $v['Version'], $obj->version, '>' ) ) {
|
250 |
continue;
|
@@ -263,10 +317,17 @@ class MainWP_Child_Plugins_Check {
|
|
263 |
}
|
264 |
|
265 |
if ( ! defined( 'DAY_IN_SECONDS' ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
define( 'DAY_IN_SECONDS', 24 * 60 * 60 );
|
267 |
}
|
268 |
|
269 |
-
//Store the master response for usage in the plugin table
|
270 |
set_transient( $this->tran_name_plugin_timestamps, $responses, DAY_IN_SECONDS );
|
271 |
|
272 |
if ( 0 === count( $all_plugins ) ) {
|
@@ -277,27 +338,38 @@ class MainWP_Child_Plugins_Check {
|
|
277 |
}
|
278 |
}
|
279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
private function try_get_response_body( $plugin, $second_pass ) {
|
281 |
-
//Some of this code is lifted from class-wp-upgrader
|
282 |
|
283 |
-
//Get the WordPress current version to be polite in the API call
|
284 |
-
include
|
285 |
|
|
|
|
|
|
|
|
|
|
|
286 |
global $wp_version;
|
287 |
|
288 |
-
//General options to be passed to wp_remote_get
|
289 |
$options = array(
|
290 |
-
'timeout' => 60 * 60,
|
291 |
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ),
|
292 |
);
|
293 |
|
294 |
-
//The URL for the endpoint
|
295 |
-
$url
|
|
|
296 |
|
297 |
-
|
298 |
-
|
299 |
-
if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
|
300 |
-
//Requires WP 3.4.0
|
301 |
$url = set_url_scheme( $url, 'https' );
|
302 |
}
|
303 |
|
@@ -306,27 +378,23 @@ class MainWP_Child_Plugins_Check {
|
|
306 |
$plugin_dir = dirname( $plugin );
|
307 |
}
|
308 |
|
309 |
-
//Try to get the response (usually the SSL version)
|
310 |
-
//Requires WP 2.7.0
|
311 |
$raw_response = wp_remote_get( $url . $plugin_dir, $options );
|
312 |
|
313 |
-
//If we don't have an error and we received a valid response code
|
314 |
-
//Requires WP 2.7.0
|
315 |
if ( ! is_wp_error( $raw_response ) && 200 === (int) wp_remote_retrieve_response_code( $raw_response ) ) {
|
316 |
-
//Get the actual body
|
317 |
-
//Requires WP 2.7.0
|
318 |
$body = wp_remote_retrieve_body( $raw_response );
|
319 |
|
320 |
-
//Make sure that it isn't empty and also not an empty serialized object
|
321 |
if ( '' !== $body && 'N;' !== $body ) {
|
322 |
-
//If valid, return that
|
323 |
return $body;
|
324 |
}
|
325 |
}
|
326 |
|
327 |
-
//The above valid
|
328 |
-
//If we previously tried an SSL version try without SSL
|
329 |
-
//Code below same as above block
|
330 |
if ( $ssl ) {
|
331 |
$raw_response = wp_remote_get( $http_url . $plugin, $options );
|
332 |
if ( ! is_wp_error( $raw_response ) && 200 === (int) wp_remote_retrieve_response_code( $raw_response ) ) {
|
@@ -337,23 +405,22 @@ class MainWP_Child_Plugins_Check {
|
|
337 |
}
|
338 |
}
|
339 |
|
340 |
-
//The above failed
|
341 |
-
//If we're on a second pass already then there's nothing left to do but bail
|
342 |
if ( true === $second_pass ) {
|
343 |
return false;
|
344 |
}
|
345 |
|
346 |
-
//We're still on the first pass, try to get just the name of the directory of the plugin
|
347 |
$parts = explode( '/', $plugin );
|
348 |
|
349 |
-
//Sanity check that we have two parts, a directory and a file name
|
350 |
if ( 2 === count( $parts ) ) {
|
351 |
-
//Try this entire function using just the directory name
|
352 |
return $this->try_get_response_body( $parts[0], true );
|
353 |
}
|
354 |
|
355 |
-
//Everything above failed, bail
|
356 |
return false;
|
357 |
}
|
358 |
}
|
359 |
-
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Abandoned Plugin Check
|
4 |
+
*
|
5 |
+
* This file checks if pugins have been abandoned.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
*
|
9 |
+
* @Credits
|
10 |
*
|
11 |
* Plugin-Name: Vendi Abandoned Plugin Check
|
12 |
* Plugin URI: https://wordpress.org/plugins/vendi-abandoned-plugin-check/
|
13 |
* Author: Vendi Advertising (Chris Haas)
|
14 |
* Author URI: https://wp-staging.com
|
15 |
* License: GPLv2
|
16 |
+
*/
|
|
|
17 |
|
18 |
+
namespace MainWP\Child;
|
19 |
|
20 |
+
/**
|
21 |
+
* Class MainWP_Child_Plugins_Check
|
22 |
+
*
|
23 |
+
* Check if plugins have been abandoned.
|
24 |
+
*/
|
25 |
+
class MainWP_Child_Plugins_Check {
|
26 |
|
27 |
+
/**
|
28 |
+
* Cron: Plugin health check watcher.
|
29 |
+
*
|
30 |
+
* @var string
|
31 |
+
*/
|
32 |
private $cron_name_watcher = 'mainwp_child_cron_plugin_health_check_watcher';
|
33 |
|
34 |
+
/**
|
35 |
+
* Cron: Plugin health check daily.
|
36 |
+
*
|
37 |
+
* @var string
|
38 |
+
*/
|
39 |
private $cron_name_daily = 'mainwp_child_cron_plugin_health_check_daily';
|
40 |
|
41 |
+
/**
|
42 |
+
* Cron: Plugin health check batching.
|
43 |
+
*
|
44 |
+
* @var string
|
45 |
+
*/
|
46 |
private $cron_name_batching = 'mainwp_child_cron_plugin_health_check_batching';
|
47 |
|
48 |
+
/**
|
49 |
+
* Transient: Plugin timestamps.
|
50 |
+
*
|
51 |
+
* @var string
|
52 |
+
*/
|
53 |
private $tran_name_plugin_timestamps = 'mainwp_child_tran_name_plugin_timestamps';
|
54 |
|
55 |
+
/**
|
56 |
+
* Transient: Plugins to batch.
|
57 |
+
*
|
58 |
+
* @var string
|
59 |
+
*/
|
60 |
private $tran_name_plugins_to_batch = 'mainwp_child_tran_name_plugins_to_batch';
|
61 |
|
62 |
+
/**
|
63 |
+
* Transient: Plugin last daily run.
|
64 |
+
*
|
65 |
+
* @var string
|
66 |
+
*/
|
67 |
private $option_name_last_daily_run = 'mainwp_child_plugin_last_daily_run';
|
68 |
|
69 |
+
/**
|
70 |
+
* Public static variable to hold the single instance of the class.
|
71 |
+
*
|
72 |
+
* @var mixed Default null
|
73 |
+
*/
|
74 |
+
public static $instance = null;
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Method instance()
|
78 |
+
*
|
79 |
+
* Create a public static instance.
|
80 |
+
*
|
81 |
+
* @return mixed Class instance.
|
82 |
+
*/
|
83 |
+
public static function instance() {
|
84 |
+
if ( null === self::$instance ) {
|
85 |
+
self::$instance = new self();
|
86 |
}
|
87 |
|
88 |
+
return self::$instance;
|
89 |
}
|
90 |
|
91 |
+
/**
|
92 |
+
* MainWP_Child_Plugins_Check constructor.
|
93 |
+
*
|
94 |
+
* Run any time class is called.
|
95 |
+
*/
|
96 |
public function __construct() {
|
97 |
+
if ( get_option( 'mainwp_child_plugintheme_days_outdate' ) ) {
|
98 |
+
$this->schedule_watchdog();
|
99 |
+
|
100 |
+
add_action( $this->cron_name_batching, array( $this, 'run_check' ) );
|
101 |
+
add_action( $this->cron_name_daily, array( $this, 'run_check' ) );
|
102 |
+
add_action( $this->cron_name_watcher, array( $this, 'perform_watchdog' ) );
|
103 |
+
add_filter( 'plugins_api_args', array( $this, 'modify_plugin_api_search_query' ), 10, 2 );
|
104 |
+
add_action( 'mainwp_child_deactivation', array( $this, 'cleanup_deactivation' ) );
|
105 |
+
}
|
|
|
|
|
|
|
|
|
|
|
106 |
}
|
107 |
|
108 |
+
/**
|
109 |
+
* Un-schedules all events attached to the hook with the specified arguments.
|
110 |
+
* On success an integer indicating number of events un-scheduled (0 indicates no events were registered with the hook and arguments combination),
|
111 |
+
* false if un-scheduling one or more events fail.
|
112 |
+
*/
|
113 |
private function cleanup_basic() {
|
114 |
wp_clear_scheduled_hook( $this->cron_name_daily );
|
115 |
wp_clear_scheduled_hook( $this->cron_name_batching );
|
116 |
delete_transient( $this->tran_name_plugins_to_batch );
|
117 |
}
|
118 |
|
119 |
+
/**
|
120 |
+
* Un-schedules all events attached to the hook with the specified arguments.
|
121 |
+
* On success an integer indicating number of events un-scheduled (0 indicates no events were registered with the hook and arguments combination),
|
122 |
+
* false if un-scheduling one or more events fail.
|
123 |
+
*
|
124 |
+
* @param bool $del Whether or not to delete the transient data. Default: true.
|
125 |
+
*/
|
126 |
public function cleanup_deactivation( $del = true ) {
|
127 |
$this->cleanup_basic();
|
128 |
wp_clear_scheduled_hook( $this->cron_name_watcher );
|
132 |
}
|
133 |
}
|
134 |
|
135 |
+
/**
|
136 |
+
* Modify plugin API Search Query.
|
137 |
+
*
|
138 |
+
* @param object $args Query arguments.
|
139 |
+
* @param string $action Action to perform: query_plugins.
|
140 |
+
* @return \stdClass $args Modified Search Query.
|
141 |
+
*/
|
142 |
public function modify_plugin_api_search_query( $args, $action ) {
|
143 |
if ( isset( $action ) && 'query_plugins' === $action ) {
|
144 |
|
156 |
return $args;
|
157 |
}
|
158 |
|
159 |
+
/**
|
160 |
+
* Schedule watchdog crons.
|
161 |
+
*
|
162 |
+
* @throws \Exception Error message on failure.
|
163 |
+
*/
|
164 |
public function perform_watchdog() {
|
165 |
if ( false === wp_next_scheduled( $this->cron_name_daily ) && false === wp_next_scheduled( $this->cron_name_batching ) ) {
|
166 |
$last_run = get_option( $this->option_name_last_daily_run );
|
171 |
$last_run = new \DateTime( '@' . $last_run );
|
172 |
}
|
173 |
|
|
|
174 |
$now = new \DateTime();
|
175 |
|
176 |
if ( false === $last_run || (int) $now->diff( $last_run )->format( '%h' ) >= 24 ) {
|
184 |
}
|
185 |
}
|
186 |
|
187 |
+
/**
|
188 |
+
* Schedule a global watchdog cron just in case both other crons get killed.
|
189 |
+
*/
|
190 |
public function schedule_watchdog() {
|
|
|
|
|
|
|
|
|
191 |
if ( ! wp_next_scheduled( $this->cron_name_watcher ) ) {
|
192 |
wp_schedule_event( time(), 'hourly', $this->cron_name_watcher );
|
193 |
}
|
|
|
194 |
}
|
195 |
|
196 |
+
/**
|
197 |
+
* Get plugins outdated info.
|
198 |
+
*
|
199 |
+
* @return array $plugins_outdate Array of outdated plugin info.
|
200 |
+
*/
|
201 |
public function get_plugins_outdate_info() {
|
202 |
$plugins_outdate = get_transient( $this->tran_name_plugin_timestamps );
|
203 |
if ( ! is_array( $plugins_outdate ) ) {
|
204 |
$plugins_outdate = array();
|
205 |
}
|
206 |
+
if ( ! function_exists( '\get_plugins' ) ) {
|
207 |
require_once ABSPATH . '/wp-admin/includes/plugin.php';
|
208 |
}
|
209 |
$plugins = get_plugins();
|
219 |
}
|
220 |
|
221 |
return $plugins_outdate;
|
|
|
222 |
}
|
223 |
|
224 |
+
/**
|
225 |
+
* Update Days out of date option.
|
226 |
+
*/
|
227 |
+
public static function may_outdate_number_change() {
|
228 |
+
if ( isset( $_POST['numberdaysOutdatePluginTheme'] ) ) {
|
229 |
+
$days_outdate = get_option( 'mainwp_child_plugintheme_days_outdate', 365 );
|
230 |
+
if ( $days_outdate != $_POST['numberdaysOutdatePluginTheme'] ) {
|
231 |
+
$days_outdate = intval( $_POST['numberdaysOutdatePluginTheme'] );
|
232 |
+
MainWP_Helper::update_option( 'mainwp_child_plugintheme_days_outdate', $days_outdate );
|
233 |
+
self::instance()->cleanup_deactivation( false );
|
234 |
+
MainWP_Child_Themes_Check::instance()->cleanup_deactivation( false );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
}
|
236 |
}
|
|
|
|
|
237 |
}
|
238 |
|
239 |
+
/**
|
240 |
+
* Run plugin update check.
|
241 |
+
*
|
242 |
+
* @throws \Exception Error message on failure.
|
243 |
+
*/
|
244 |
public function run_check() {
|
245 |
+
if ( ! function_exists( '\get_plugins' ) ) {
|
246 |
require_once ABSPATH . '/wp-admin/includes/plugin.php';
|
247 |
}
|
248 |
|
249 |
+
// Get our previous results.
|
250 |
$responses = get_transient( $this->tran_name_plugin_timestamps );
|
251 |
|
252 |
if ( false === $responses || ! is_array( $responses ) ) {
|
253 |
$responses = array();
|
254 |
}
|
255 |
|
256 |
+
// Get our previous cache of plugins for batching.
|
257 |
$all_plugins = get_transient( $this->tran_name_plugins_to_batch );
|
258 |
|
259 |
+
// If there wasn't a previous cache.
|
260 |
if ( false === $all_plugins || ! is_array( $all_plugins ) ) {
|
261 |
$plugins = get_plugins();
|
262 |
if ( is_array( $plugins ) ) {
|
275 |
}
|
276 |
|
277 |
$avoid_plugins = array( 'sitepress-multilingual-cms/sitepress.php' );
|
278 |
+
|
279 |
+
// Grab a small number of plugins to scan.
|
280 |
+
$plugins_to_scan = array_splice( $all_plugins, 0, apply_filters( 'mainwp_child_plugin_health_check_max_plugins_to_batch', 10 ) );
|
281 |
$tolerance_in_days = get_option( 'mainwp_child_plugintheme_days_outdate', 365 );
|
282 |
|
283 |
+
// Loop through each known plugin.
|
284 |
foreach ( $plugins_to_scan as $slug => $v ) {
|
285 |
if ( in_array( $slug, $avoid_plugins ) ) {
|
286 |
continue;
|
287 |
}
|
288 |
+
// Try to get the raw information for this plugin.
|
289 |
$body = $this->try_get_response_body( $slug, false );
|
290 |
|
291 |
+
// We couldn't get any information, skip this plugin.
|
292 |
if ( false === $body ) {
|
293 |
continue;
|
294 |
}
|
295 |
|
296 |
+
// Deserialize the response.
|
297 |
$obj = maybe_unserialize( $body );
|
298 |
|
299 |
$now = new \DateTime();
|
300 |
|
301 |
+
// Sanity check that deserialization worked and that our property exists.
|
302 |
if ( false !== $obj && is_object( $obj ) && property_exists( $obj, 'last_updated' ) ) {
|
303 |
if ( version_compare( $v['Version'], $obj->version, '>' ) ) {
|
304 |
continue;
|
317 |
}
|
318 |
|
319 |
if ( ! defined( 'DAY_IN_SECONDS' ) ) {
|
320 |
+
|
321 |
+
/**
|
322 |
+
* Defines days in seconds.
|
323 |
+
*
|
324 |
+
* @const ( string ) Default: true.
|
325 |
+
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Plugins_Check.html
|
326 |
+
*/
|
327 |
define( 'DAY_IN_SECONDS', 24 * 60 * 60 );
|
328 |
}
|
329 |
|
330 |
+
// Store the master response for usage in the plugin table.
|
331 |
set_transient( $this->tran_name_plugin_timestamps, $responses, DAY_IN_SECONDS );
|
332 |
|
333 |
if ( 0 === count( $all_plugins ) ) {
|
338 |
}
|
339 |
}
|
340 |
|
341 |
+
/**
|
342 |
+
* Try to get response body.
|
343 |
+
*
|
344 |
+
* @param string $plugin Plugin slug.
|
345 |
+
* @param bool $second_pass Second pass check.
|
346 |
+
*
|
347 |
+
* @return bool|string true|false The body of the response. Empty string if no body or incorrect parameter given.
|
348 |
+
*/
|
349 |
private function try_get_response_body( $plugin, $second_pass ) {
|
|
|
350 |
|
351 |
+
// Get the WordPress current version to be polite in the API call.
|
352 |
+
include ABSPATH . WPINC . '/version.php';
|
353 |
|
354 |
+
/**
|
355 |
+
* The installed version of WordPress.
|
356 |
+
*
|
357 |
+
* @global string $wp_version The installed version of WordPress.
|
358 |
+
*/
|
359 |
global $wp_version;
|
360 |
|
361 |
+
// General options to be passed to wp_remote_get.
|
362 |
$options = array(
|
363 |
+
'timeout' => 60 * 60,
|
364 |
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ),
|
365 |
);
|
366 |
|
367 |
+
// The URL for the endpoint.
|
368 |
+
$url = 'http://api.wordpress.org/plugins/info/1.0/';
|
369 |
+
$http_url = 'http://api.wordpress.org/plugins/info/1.0/';
|
370 |
|
371 |
+
$ssl = wp_http_supports( array( 'ssl' ) );
|
372 |
+
if ( $ssl ) {
|
|
|
|
|
373 |
$url = set_url_scheme( $url, 'https' );
|
374 |
}
|
375 |
|
378 |
$plugin_dir = dirname( $plugin );
|
379 |
}
|
380 |
|
381 |
+
// Try to get the response (usually the SSL version).
|
|
|
382 |
$raw_response = wp_remote_get( $url . $plugin_dir, $options );
|
383 |
|
384 |
+
// If we don't have an error and we received a valid response code.
|
|
|
385 |
if ( ! is_wp_error( $raw_response ) && 200 === (int) wp_remote_retrieve_response_code( $raw_response ) ) {
|
386 |
+
// Get the actual body.
|
|
|
387 |
$body = wp_remote_retrieve_body( $raw_response );
|
388 |
|
389 |
+
// Make sure that it isn't empty and also not an empty serialized object.
|
390 |
if ( '' !== $body && 'N;' !== $body ) {
|
|
|
391 |
return $body;
|
392 |
}
|
393 |
}
|
394 |
|
395 |
+
// The above valid!
|
396 |
+
// If we previously tried an SSL version try without SSL.
|
397 |
+
// Code below same as above block.
|
398 |
if ( $ssl ) {
|
399 |
$raw_response = wp_remote_get( $http_url . $plugin, $options );
|
400 |
if ( ! is_wp_error( $raw_response ) && 200 === (int) wp_remote_retrieve_response_code( $raw_response ) ) {
|
405 |
}
|
406 |
}
|
407 |
|
408 |
+
// The above failed!
|
409 |
+
// If we're on a second pass already then there's nothing left to do but bail.
|
410 |
if ( true === $second_pass ) {
|
411 |
return false;
|
412 |
}
|
413 |
|
414 |
+
// We're still on the first pass, try to get just the name of the directory of the plugin.
|
415 |
$parts = explode( '/', $plugin );
|
416 |
|
417 |
+
// Sanity check that we have two parts, a directory and a file name.
|
418 |
if ( 2 === count( $parts ) ) {
|
419 |
+
// Try this entire function using just the directory name.
|
420 |
return $this->try_get_response_body( $parts[0], true );
|
421 |
}
|
422 |
|
423 |
+
// Everything above failed, bail!
|
424 |
return false;
|
425 |
}
|
426 |
}
|
|
class/class-mainwp-child-posts.php
ADDED
@@ -0,0 +1,1319 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child posts handler
|
4 |
+
*
|
5 |
+
* This file handles all post & post plus actions.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
//phpcs:disable Generic.Metrics.CyclomaticComplexity -- Required to achieve desired results, pull request solutions appreciated.
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class MainWP_Child_Posts
|
16 |
+
*
|
17 |
+
* Handle all post & post plus actions.
|
18 |
+
*/
|
19 |
+
class MainWP_Child_Posts {
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Public static variable to hold the single instance of MainWP_Child_Posts.
|
23 |
+
*
|
24 |
+
* @var mixed Default null
|
25 |
+
*/
|
26 |
+
protected static $instance = null;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Comments and clauses.
|
30 |
+
*
|
31 |
+
* @var string Comments and clauses.
|
32 |
+
*/
|
33 |
+
private $comments_and_clauses;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Posts with given suffix.
|
37 |
+
*
|
38 |
+
* @var string Posts with given suffix.
|
39 |
+
*/
|
40 |
+
private $posts_where_suffix;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Get class name.
|
44 |
+
*
|
45 |
+
* @return string __CLASS__ Class name.
|
46 |
+
*/
|
47 |
+
public static function get_class_name() {
|
48 |
+
return __CLASS__;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* MainWP_Child_Posts constructor
|
53 |
+
*
|
54 |
+
* Run any time class is called.
|
55 |
+
*
|
56 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::comments_and_clauses()
|
57 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::posts_where_suffix()
|
58 |
+
*/
|
59 |
+
public function __construct() {
|
60 |
+
$this->comments_and_clauses = '';
|
61 |
+
$this->posts_where_suffix = '';
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Create a public static instance of MainWP_Child_Posts.
|
66 |
+
*
|
67 |
+
* @return MainWP_Child_Posts|null
|
68 |
+
*/
|
69 |
+
public static function get_instance() {
|
70 |
+
if ( null === self::$instance ) {
|
71 |
+
self::$instance = new self();
|
72 |
+
}
|
73 |
+
|
74 |
+
return self::$instance;
|
75 |
+
}
|
76 |
+
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Get recent posts.
|
80 |
+
*
|
81 |
+
* @param array $pAllowedStatuses Array of allowed post statuses.
|
82 |
+
* @param int $pCount Number of posts.
|
83 |
+
* @param string $type Post type.
|
84 |
+
* @param null $extra Extra tokens.
|
85 |
+
*
|
86 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_recent_posts_int()
|
87 |
+
*
|
88 |
+
* @return array $allPost Return array of recent posts.
|
89 |
+
*/
|
90 |
+
public function get_recent_posts( $pAllowedStatuses, $pCount, $type = 'post', $extra = null ) {
|
91 |
+
$allPosts = array();
|
92 |
+
if ( null !== $pAllowedStatuses ) {
|
93 |
+
foreach ( $pAllowedStatuses as $status ) {
|
94 |
+
$this->get_recent_posts_int( $status, $pCount, $type, $allPosts, $extra );
|
95 |
+
}
|
96 |
+
} else {
|
97 |
+
$this->get_recent_posts_int( 'any', $pCount, $type, $allPosts, $extra );
|
98 |
+
}
|
99 |
+
|
100 |
+
return $allPosts;
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Initiate get recent posts.
|
105 |
+
*
|
106 |
+
* @param string $status Post status.
|
107 |
+
* @param int $pCount Number of posts.
|
108 |
+
* @param string $type Post type.
|
109 |
+
* @param array $allPosts All posts array.
|
110 |
+
* @param null $extra Extra tokens.
|
111 |
+
*
|
112 |
+
* @uses \WPSEO_Link_Column_Count()
|
113 |
+
* @uses \WPSEO_Meta()
|
114 |
+
* @uses MainWP_WordPress_SEO::instance()::parse_column_score()
|
115 |
+
* @uses MainWP_WordPress_SEO::instance()->parse_column_score_readability()
|
116 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_out_post()
|
117 |
+
*/
|
118 |
+
public function get_recent_posts_int( $status, $pCount, $type = 'post', &$allPosts, $extra = null ) {
|
119 |
+
|
120 |
+
$args = array(
|
121 |
+
'post_status' => $status,
|
122 |
+
'suppress_filters' => false,
|
123 |
+
'post_type' => $type,
|
124 |
+
);
|
125 |
+
|
126 |
+
$tokens = array();
|
127 |
+
if ( is_array( $extra ) && isset( $extra['tokens'] ) ) {
|
128 |
+
$tokens = $extra['tokens'];
|
129 |
+
if ( 1 == $extra['extract_post_type'] ) {
|
130 |
+
$args['post_type'] = 'post';
|
131 |
+
} elseif ( 2 == $extra['extract_post_type'] ) {
|
132 |
+
$args['post_type'] = 'page';
|
133 |
+
} elseif ( 3 == $extra['extract_post_type'] ) {
|
134 |
+
$args['post_type'] = array( 'post', 'page' );
|
135 |
+
}
|
136 |
+
}
|
137 |
+
$tokens = array_flip( $tokens );
|
138 |
+
|
139 |
+
if ( 0 !== $pCount ) {
|
140 |
+
$args['numberposts'] = $pCount;
|
141 |
+
}
|
142 |
+
|
143 |
+
$wp_seo_enabled = false;
|
144 |
+
if ( ! empty( $_POST['WPSEOEnabled'] ) ) {
|
145 |
+
if ( is_plugin_active( 'wordpress-seo/wp-seo.php' ) && class_exists( '\WPSEO_Link_Column_Count' ) && class_exists( '\WPSEO_Meta' ) ) {
|
146 |
+
$wp_seo_enabled = true;
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
$posts = get_posts( $args );
|
151 |
+
|
152 |
+
if ( is_array( $posts ) ) {
|
153 |
+
if ( $wp_seo_enabled ) {
|
154 |
+
$post_ids = array();
|
155 |
+
foreach ( $posts as $post ) {
|
156 |
+
$post_ids[] = $post->ID;
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Credits
|
161 |
+
*
|
162 |
+
* Plugin-Name: Yoast SEO
|
163 |
+
* Plugin URI: https://yoast.com/wordpress/plugins/seo/#utm_source=wpadmin&utm_medium=plugin&utm_campaign=wpseoplugin
|
164 |
+
* Author: Team Yoast
|
165 |
+
* Author URI: https://yoast.com/
|
166 |
+
* Licence: GPL v3
|
167 |
+
*
|
168 |
+
* The code is used for the MainWP WordPress SEO Extension
|
169 |
+
* Extension URL: https://mainwp.com/extension/wordpress-seo/
|
170 |
+
*/
|
171 |
+
$link_count = new \WPSEO_Link_Column_Count();
|
172 |
+
$link_count->set( $post_ids );
|
173 |
+
}
|
174 |
+
foreach ( $posts as $post ) {
|
175 |
+
$outPost = $this->get_out_post( $post, $extra, $tokens );
|
176 |
+
if ( $wp_seo_enabled ) {
|
177 |
+
$outPost['seo_data'] = array(
|
178 |
+
'count_seo_links' => $link_count->get( $post->ID, 'internal_link_count' ),
|
179 |
+
'count_seo_linked' => $link_count->get( $post->ID, 'incoming_link_count' ),
|
180 |
+
'seo_score' => MainWP_WordPress_SEO::instance()->parse_column_score( $post->ID ),
|
181 |
+
'readability_score' => MainWP_WordPress_SEO::instance()->parse_column_score_readability( $post->ID ),
|
182 |
+
);
|
183 |
+
}
|
184 |
+
$allPosts[] = $outPost;
|
185 |
+
}
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* Build Post.
|
191 |
+
*
|
192 |
+
* @param array $post Post array.
|
193 |
+
* @param string $extra Post date & time.
|
194 |
+
* @param array $tokens Post tokens.
|
195 |
+
* @return array $outPost Return completed post.
|
196 |
+
*/
|
197 |
+
private function get_out_post( $post, $extra, $tokens ) {
|
198 |
+
$outPost = array();
|
199 |
+
$outPost['id'] = $post->ID;
|
200 |
+
$outPost['post_type'] = $post->post_type;
|
201 |
+
$outPost['status'] = $post->post_status;
|
202 |
+
$outPost['title'] = $post->post_title;
|
203 |
+
$outPost['comment_count'] = $post->comment_count;
|
204 |
+
if ( isset( $extra['where_post_date'] ) && ! empty( $extra['where_post_date'] ) ) {
|
205 |
+
$outPost['dts'] = strtotime( $post->post_date_gmt );
|
206 |
+
} else {
|
207 |
+
$outPost['dts'] = strtotime( $post->post_modified_gmt );
|
208 |
+
}
|
209 |
+
|
210 |
+
if ( 'page' == $post->post_type ) {
|
211 |
+
$outPost['dts'] = strtotime( $post->post_modified_gmt ); // to order by modified date.
|
212 |
+
}
|
213 |
+
|
214 |
+
if ( 'future' == $post->post_status ) {
|
215 |
+
$outPost['dts'] = strtotime( $post->post_date_gmt );
|
216 |
+
}
|
217 |
+
|
218 |
+
$usr = get_user_by( 'id', $post->post_author );
|
219 |
+
$outPost['author'] = ! empty( $usr ) ? $usr->user_nicename : 'removed';
|
220 |
+
$categoryObjects = get_the_category( $post->ID );
|
221 |
+
$categories = '';
|
222 |
+
foreach ( $categoryObjects as $cat ) {
|
223 |
+
if ( '' !== $categories ) {
|
224 |
+
$categories .= ', ';
|
225 |
+
}
|
226 |
+
$categories .= $cat->name;
|
227 |
+
}
|
228 |
+
$outPost['categories'] = $categories;
|
229 |
+
|
230 |
+
$tagObjects = get_the_tags( $post->ID );
|
231 |
+
$tags = '';
|
232 |
+
if ( is_array( $tagObjects ) ) {
|
233 |
+
foreach ( $tagObjects as $tag ) {
|
234 |
+
if ( '' !== $tags ) {
|
235 |
+
$tags .= ', ';
|
236 |
+
}
|
237 |
+
$tags .= $tag->name;
|
238 |
+
}
|
239 |
+
}
|
240 |
+
$outPost['tags'] = $tags;
|
241 |
+
if ( is_array( $tokens ) ) {
|
242 |
+
if ( isset( $tokens['[post.url]'] ) ) {
|
243 |
+
$outPost['[post.url]'] = get_permalink( $post->ID );
|
244 |
+
}
|
245 |
+
if ( isset( $tokens['[post.website.url]'] ) ) {
|
246 |
+
$outPost['[post.website.url]'] = get_site_url();
|
247 |
+
}
|
248 |
+
if ( isset( $tokens['[post.website.name]'] ) ) {
|
249 |
+
$outPost['[post.website.name]'] = get_bloginfo( 'name' );
|
250 |
+
}
|
251 |
+
}
|
252 |
+
return $outPost;
|
253 |
+
}
|
254 |
+
|
255 |
+
/**
|
256 |
+
* Get all posts.
|
257 |
+
*
|
258 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_all_posts_by_type()
|
259 |
+
*/
|
260 |
+
public function get_all_posts() {
|
261 |
+
$post_type = ( isset( $_POST['post_type'] ) ? sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) : 'post' );
|
262 |
+
$this->get_all_posts_by_type( $post_type );
|
263 |
+
}
|
264 |
+
|
265 |
+
/**
|
266 |
+
* Get all pages.
|
267 |
+
*
|
268 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_all_posts_by_type()
|
269 |
+
*/
|
270 |
+
public function get_all_pages() {
|
271 |
+
$this->get_all_posts_by_type( 'page' );
|
272 |
+
}
|
273 |
+
|
274 |
+
/**
|
275 |
+
* Append the Post's SQL WHERE clause suffix.
|
276 |
+
*
|
277 |
+
* @param string $where Post's SQL WHERE clause.
|
278 |
+
*
|
279 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::posts_where_suffix()
|
280 |
+
*
|
281 |
+
* @return string $where The full SQL WHERE clause with the appended suffix.
|
282 |
+
*/
|
283 |
+
public function posts_where( $where ) {
|
284 |
+
if ( $this->posts_where_suffix ) {
|
285 |
+
$where .= ' ' . $this->posts_where_suffix;
|
286 |
+
}
|
287 |
+
|
288 |
+
return $where;
|
289 |
+
}
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Get all posts by type.
|
293 |
+
*
|
294 |
+
* @param string $type Post type.
|
295 |
+
*
|
296 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::posts_where_suffix()
|
297 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
298 |
+
*/
|
299 |
+
public function get_all_posts_by_type( $type ) {
|
300 |
+
|
301 |
+
/**
|
302 |
+
* Object, providing access to the WordPress database.
|
303 |
+
*
|
304 |
+
* @global object $wpdb WordPress Database instance.
|
305 |
+
*/
|
306 |
+
global $wpdb;
|
307 |
+
|
308 |
+
add_filter( 'posts_where', array( &$this, 'posts_where' ) );
|
309 |
+
$where_post_date = isset( $_POST['where_post_date'] ) && ! empty( $_POST['where_post_date'] ) ? true : false;
|
310 |
+
if ( isset( $_POST['postId'] ) ) {
|
311 |
+
$this->posts_where_suffix .= " AND $wpdb->posts.ID = " . sanitize_text_field( wp_unslash( $_POST['postId'] ) );
|
312 |
+
} elseif ( isset( $_POST['userId'] ) ) {
|
313 |
+
$this->posts_where_suffix .= " AND $wpdb->posts.post_author = " . sanitize_text_field( wp_unslash( $_POST['userId'] ) );
|
314 |
+
} else {
|
315 |
+
if ( isset( $_POST['keyword'] ) ) {
|
316 |
+
$search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
|
317 |
+
if ( 'title' == $search_on ) {
|
318 |
+
$this->posts_where_suffix .= " AND ( $wpdb->posts.post_title LIKE '%" . sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) . "%' )";
|
319 |
+
} elseif ( 'content' == $search_on ) {
|
320 |
+
$this->posts_where_suffix .= " AND ( $wpdb->posts.post_content LIKE '%" . sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) . "%' )";
|
321 |
+
} else {
|
322 |
+
$this->posts_where_suffix .= " AND ( $wpdb->posts.post_content LIKE '%" . sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) . "%' OR $wpdb->posts.post_title LIKE '%" . sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) . "%' )";
|
323 |
+
}
|
324 |
+
}
|
325 |
+
if ( isset( $_POST['dtsstart'] ) && '' !== $_POST['dtsstart'] ) {
|
326 |
+
if ( $where_post_date ) {
|
327 |
+
$this->posts_where_suffix .= " AND $wpdb->posts.post_date > '" . sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) . "'";
|
328 |
+
} else {
|
329 |
+
$this->posts_where_suffix .= " AND $wpdb->posts.post_modified > '" . sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) . "'";
|
330 |
+
}
|
331 |
+
}
|
332 |
+
if ( isset( $_POST['dtsstop'] ) && '' !== $_POST['dtsstop'] ) {
|
333 |
+
if ( $where_post_date ) {
|
334 |
+
$this->posts_where_suffix .= " AND $wpdb->posts.post_date < '" . sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) . "'";
|
335 |
+
} else {
|
336 |
+
$this->posts_where_suffix .= " AND $wpdb->posts.post_modified < '" . sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) . "'";
|
337 |
+
}
|
338 |
+
}
|
339 |
+
|
340 |
+
if ( isset( $_POST['exclude_page_type'] ) && wp_unslash( $_POST['exclude_page_type'] ) ) {
|
341 |
+
$this->posts_where_suffix .= " AND $wpdb->posts.post_type NOT IN ('page')";
|
342 |
+
}
|
343 |
+
}
|
344 |
+
|
345 |
+
$maxPages = 50;
|
346 |
+
if ( defined( 'MAINWP_CHILD_NR_OF_PAGES' ) ) {
|
347 |
+
$maxPages = MAINWP_CHILD_NR_OF_PAGES;
|
348 |
+
}
|
349 |
+
|
350 |
+
if ( isset( $_POST['maxRecords'] ) ) {
|
351 |
+
$maxPages = ! empty( $_POST['maxRecords'] ) ? intval( wp_unslash( $_POST['maxRecords'] ) ) : 0;
|
352 |
+
}
|
353 |
+
if ( 0 === $maxPages ) {
|
354 |
+
$maxPages = 99999;
|
355 |
+
}
|
356 |
+
|
357 |
+
$extra = array();
|
358 |
+
if ( isset( $_POST['extract_tokens'] ) ) {
|
359 |
+
$extra['tokens'] = isset( $_POST['extract_tokens'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['extract_tokens'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
360 |
+
$extra['extract_post_type'] = isset( $_POST['extract_post_type'] ) ? sanitize_text_field( wp_unslash( $_POST['extract_post_type'] ) ) : '';
|
361 |
+
}
|
362 |
+
|
363 |
+
$extra['where_post_date'] = $where_post_date;
|
364 |
+
$rslt = isset( $_POST['status'] ) ? $this->get_recent_posts( explode( ',', wp_unslash( $_POST['status'] ) ), $maxPages, $type, $extra ) : '';
|
365 |
+
$this->posts_where_suffix = '';
|
366 |
+
|
367 |
+
MainWP_Helper::write( $rslt );
|
368 |
+
}
|
369 |
+
|
370 |
+
/**
|
371 |
+
* Build New Post.
|
372 |
+
*
|
373 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::create_post()
|
374 |
+
* @uses \MainWP\Child\ainWP_Helper::error()
|
375 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
376 |
+
*/
|
377 |
+
public function new_post() {
|
378 |
+
$new_post = isset( $_POST['new_post'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['new_post'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
379 |
+
$post_custom = isset( $_POST['post_custom'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['post_custom'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
380 |
+
$post_category = isset( $_POST['post_category'] ) ? rawurldecode( base64_decode( wp_unslash( $_POST['post_category'] ) ) ) : null; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
381 |
+
$post_tags = isset( $_POST['post_tags'] ) ? rawurldecode( wp_unslash( $new_post['post_tags'] ) ) : null;
|
382 |
+
$post_featured_image = isset( $_POST['post_featured_image'] ) ? base64_decode( wp_unslash( $_POST['post_featured_image'] ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
383 |
+
$upload_dir = isset( $_POST['mainwp_upload_dir'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['mainwp_upload_dir'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
384 |
+
|
385 |
+
$others = array();
|
386 |
+
if ( isset( $_POST['featured_image_data'] ) && ! empty( $_POST['featured_image_data'] ) ) {
|
387 |
+
$others['featured_image_data'] = ! empty( $_POST['featured_image_data'] ) ? unserialize( base64_decode( wp_unslash( $_POST['featured_image_data'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
388 |
+
}
|
389 |
+
|
390 |
+
$res = $this->create_post( $new_post, $post_custom, $post_category, $post_featured_image, $upload_dir, $post_tags, $others );
|
391 |
+
|
392 |
+
if ( is_array( $res ) && isset( $res['error'] ) ) {
|
393 |
+
MainWP_Helper::error( $res['error'] );
|
394 |
+
}
|
395 |
+
|
396 |
+
$created = $res['success'];
|
397 |
+
if ( true !== $created ) {
|
398 |
+
MainWP_Helper::error( 'Undefined error' );
|
399 |
+
}
|
400 |
+
|
401 |
+
$information['added'] = true;
|
402 |
+
$information['added_id'] = $res['added_id'];
|
403 |
+
$information['link'] = $res['link'];
|
404 |
+
|
405 |
+
do_action( 'mainwp_child_after_newpost', $res );
|
406 |
+
|
407 |
+
MainWP_Helper::write( $information );
|
408 |
+
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
* Post Action.
|
412 |
+
*
|
413 |
+
* @uses \MainWP\Child\MainWP_Child_Links_Checker()
|
414 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_post_edit()
|
415 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_page_edit()
|
416 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
417 |
+
*/
|
418 |
+
public function post_action() {
|
419 |
+
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
420 |
+
$postId = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
|
421 |
+
$my_post = array();
|
422 |
+
|
423 |
+
if ( 'publish' === $action ) {
|
424 |
+
$post_current = get_post( $postId );
|
425 |
+
if ( empty( $post_current ) ) {
|
426 |
+
$information['status'] = 'FAIL';
|
427 |
+
} else {
|
428 |
+
if ( 'future' == $post_current->post_status ) {
|
429 |
+
wp_publish_post( $postId );
|
430 |
+
wp_update_post(
|
431 |
+
array(
|
432 |
+
'ID' => $postId,
|
433 |
+
'post_date' => current_time( 'mysql', false ),
|
434 |
+
'post_date_gmt' => current_time( 'mysql', true ),
|
435 |
+
)
|
436 |
+
);
|
437 |
+
} else {
|
438 |
+
wp_update_post(
|
439 |
+
array(
|
440 |
+
'ID' => $postId,
|
441 |
+
'post_status' => 'publish',
|
442 |
+
)
|
443 |
+
);
|
444 |
+
}
|
445 |
+
}
|
446 |
+
} elseif ( 'update' === $action ) {
|
447 |
+
$postData = isset( $_POST['post_data'] ) ? wp_unslash( $_POST['post_data'] ) : array();
|
448 |
+
$my_post = is_array( $postData ) ? $postData : array();
|
449 |
+
wp_update_post( $my_post );
|
450 |
+
} elseif ( 'unpublish' === $action ) {
|
451 |
+
$my_post['ID'] = $postId;
|
452 |
+
$my_post['post_status'] = 'draft';
|
453 |
+
wp_update_post( $my_post );
|
454 |
+
} elseif ( 'trash' === $action ) {
|
455 |
+
add_action( 'trash_post', array( MainWP_Child_Links_Checker::get_class_name(), 'hook_post_deleted' ) );
|
456 |
+
wp_trash_post( $postId );
|
457 |
+
} elseif ( 'delete' === $action ) {
|
458 |
+
add_action( 'delete_post', array( MainWP_Child_Links_Checker::get_class_name(), 'hook_post_deleted' ) );
|
459 |
+
wp_delete_post( $postId, true );
|
460 |
+
} elseif ( 'restore' === $action ) {
|
461 |
+
wp_untrash_post( $postId );
|
462 |
+
} elseif ( 'update_meta' === $action ) {
|
463 |
+
$values = isset( $_POST['values'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['values'] ) ) ) : array(); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
464 |
+
$meta_key = $values['meta_key'];
|
465 |
+
$meta_value = $values['meta_value'];
|
466 |
+
$check_prev = $values['check_prev'];
|
467 |
+
|
468 |
+
foreach ( $meta_key as $i => $key ) {
|
469 |
+
if ( 1 === intval( $check_prev[ $i ] ) ) {
|
470 |
+
update_post_meta( $postId, $key, get_post_meta( $postId, $key, true ) ? get_post_meta( $postId, $key, true ) : $meta_value[ $i ] );
|
471 |
+
} else {
|
472 |
+
update_post_meta( $postId, $key, $meta_value[ $i ] );
|
473 |
+
}
|
474 |
+
}
|
475 |
+
} elseif ( 'get_edit' === $action ) {
|
476 |
+
$postId = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
|
477 |
+
$post_type = isset( $_POST['post_type'] ) ? sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) : '';
|
478 |
+
if ( 'post' == $post_type ) {
|
479 |
+
$my_post = $this->get_post_edit( $postId );
|
480 |
+
} else {
|
481 |
+
$my_post = $this->get_page_edit( $postId );
|
482 |
+
}
|
483 |
+
} else {
|
484 |
+
$information['status'] = 'FAIL';
|
485 |
+
}
|
486 |
+
|
487 |
+
if ( ! isset( $information['status'] ) ) {
|
488 |
+
$information['status'] = 'SUCCESS';
|
489 |
+
}
|
490 |
+
$information['my_post'] = $my_post;
|
491 |
+
MainWP_Helper::write( $information );
|
492 |
+
}
|
493 |
+
|
494 |
+
/**
|
495 |
+
* Get post edit data.
|
496 |
+
*
|
497 |
+
* @param string $id Post ID.
|
498 |
+
*
|
499 |
+
* @return array|bool Return $post_data or FALSE on failure.
|
500 |
+
*/
|
501 |
+
public function get_post_edit( $id ) {
|
502 |
+
$post = get_post( $id );
|
503 |
+
if ( $post ) {
|
504 |
+
$categoryObjects = get_the_category( $post->ID );
|
505 |
+
$categories = '';
|
506 |
+
foreach ( $categoryObjects as $cat ) {
|
507 |
+
if ( '' !== $categories ) {
|
508 |
+
$categories .= ', ';
|
509 |
+
}
|
510 |
+
$categories .= $cat->name;
|
511 |
+
}
|
512 |
+
$post_category = $categories;
|
513 |
+
|
514 |
+
$tagObjects = get_the_tags( $post->ID );
|
515 |
+
$tags = '';
|
516 |
+
if ( is_array( $tagObjects ) ) {
|
517 |
+
foreach ( $tagObjects as $tag ) {
|
518 |
+
if ( '' !== $tags ) {
|
519 |
+
$tags .= ', ';
|
520 |
+
}
|
521 |
+
$tags .= $tag->name;
|
522 |
+
}
|
523 |
+
}
|
524 |
+
$post_tags = $tags;
|
525 |
+
|
526 |
+
$post_custom = get_post_custom( $id );
|
527 |
+
|
528 |
+
$galleries = get_post_gallery( $id, false );
|
529 |
+
$post_gallery_images = array();
|
530 |
+
|
531 |
+
if ( is_array( $galleries ) && isset( $galleries['ids'] ) ) {
|
532 |
+
$attached_images = explode( ',', $galleries['ids'] );
|
533 |
+
foreach ( $attached_images as $attachment_id ) {
|
534 |
+
$attachment = get_post( $attachment_id );
|
535 |
+
if ( $attachment ) {
|
536 |
+
$post_gallery_images[] = array(
|
537 |
+
'id' => $attachment_id,
|
538 |
+
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
|
539 |
+
'caption' => $attachment->post_excerpt,
|
540 |
+
'description' => $attachment->post_content,
|
541 |
+
'src' => $attachment->guid,
|
542 |
+
'title' => $attachment->post_title,
|
543 |
+
);
|
544 |
+
}
|
545 |
+
}
|
546 |
+
}
|
547 |
+
|
548 |
+
include_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php';
|
549 |
+
$post_featured_image = get_post_thumbnail_id( $id );
|
550 |
+
$child_upload_dir = wp_upload_dir();
|
551 |
+
$new_post = array(
|
552 |
+
'edit_id' => $id,
|
553 |
+
'is_sticky' => is_sticky( $id ) ? 1 : 0,
|
554 |
+
'post_title' => $post->post_title,
|
555 |
+
'post_content' => $post->post_content,
|
556 |
+
'post_status' => $post->post_status,
|
557 |
+
'post_date' => $post->post_date,
|
558 |
+
'post_date_gmt' => $post->post_date_gmt,
|
559 |
+
'post_tags' => $post_tags,
|
560 |
+
'post_name' => $post->post_name,
|
561 |
+
'post_excerpt' => $post->post_excerpt,
|
562 |
+
'comment_status' => $post->comment_status,
|
563 |
+
'ping_status' => $post->ping_status,
|
564 |
+
);
|
565 |
+
|
566 |
+
if ( null != $post_featured_image ) { // Featured image is set, retrieve URL.
|
567 |
+
$img = wp_get_attachment_image_src( $post_featured_image, 'full' );
|
568 |
+
$post_featured_image = $img[0];
|
569 |
+
}
|
570 |
+
|
571 |
+
require_once ABSPATH . 'wp-admin/includes/post.php';
|
572 |
+
wp_set_post_lock( $id );
|
573 |
+
|
574 |
+
$post_data = array(
|
575 |
+
'new_post' => base64_encode( serialize( $new_post ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
576 |
+
'post_custom' => base64_encode( serialize( $post_custom ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
577 |
+
'post_category' => base64_encode( $post_category ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
578 |
+
'post_featured_image' => base64_encode( $post_featured_image ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
579 |
+
'post_gallery_images' => base64_encode( serialize( $post_gallery_images ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
580 |
+
'child_upload_dir' => base64_encode( serialize( $child_upload_dir ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
581 |
+
);
|
582 |
+
return $post_data;
|
583 |
+
|
584 |
+
}
|
585 |
+
return false;
|
586 |
+
}
|
587 |
+
|
588 |
+
/**
|
589 |
+
* Get page edit data.
|
590 |
+
*
|
591 |
+
* @param string $id Page ID.
|
592 |
+
*
|
593 |
+
* @return array|bool Return $post_data or FALSE on failure.
|
594 |
+
*/
|
595 |
+
public function get_page_edit( $id ) {
|
596 |
+
$post = get_post( $id );
|
597 |
+
if ( $post ) {
|
598 |
+
$post_custom = get_post_custom( $id );
|
599 |
+
include_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php';
|
600 |
+
$post_featured_image = get_post_thumbnail_id( $id );
|
601 |
+
$child_upload_dir = wp_upload_dir();
|
602 |
+
|
603 |
+
$new_post = array(
|
604 |
+
'edit_id' => $id,
|
605 |
+
'post_title' => $post->post_title,
|
606 |
+
'post_content' => $post->post_content,
|
607 |
+
'post_status' => $post->post_status,
|
608 |
+
'post_date' => $post->post_date,
|
609 |
+
'post_date_gmt' => $post->post_date_gmt,
|
610 |
+
'post_type' => 'page',
|
611 |
+
'post_name' => $post->post_name,
|
612 |
+
'post_excerpt' => $post->post_excerpt,
|
613 |
+
'comment_status' => $post->comment_status,
|
614 |
+
'ping_status' => $post->ping_status,
|
615 |
+
);
|
616 |
+
|
617 |
+
if ( null != $post_featured_image ) {
|
618 |
+
$img = wp_get_attachment_image_src( $post_featured_image, 'full' );
|
619 |
+
$post_featured_image = $img[0];
|
620 |
+
}
|
621 |
+
|
622 |
+
$galleries = get_post_gallery( $id, false );
|
623 |
+
$post_gallery_images = array();
|
624 |
+
|
625 |
+
if ( is_array( $galleries ) && isset( $galleries['ids'] ) ) {
|
626 |
+
$attached_images = explode( ',', $galleries['ids'] );
|
627 |
+
foreach ( $attached_images as $attachment_id ) {
|
628 |
+
$attachment = get_post( $attachment_id );
|
629 |
+
if ( $attachment ) {
|
630 |
+
$post_gallery_images[] = array(
|
631 |
+
'id' => $attachment_id,
|
632 |
+
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
|
633 |
+
'caption' => $attachment->post_excerpt,
|
634 |
+
'description' => $attachment->post_content,
|
635 |
+
'src' => $attachment->guid,
|
636 |
+
'title' => $attachment->post_title,
|
637 |
+
);
|
638 |
+
}
|
639 |
+
}
|
640 |
+
}
|
641 |
+
|
642 |
+
require_once ABSPATH . 'wp-admin/includes/post.php';
|
643 |
+
wp_set_post_lock( $id );
|
644 |
+
|
645 |
+
$post_data = array(
|
646 |
+
'new_post' => base64_encode( serialize( $new_post ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
647 |
+
'post_custom' => base64_encode( serialize( $post_custom ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
648 |
+
'post_featured_image' => base64_encode( $post_featured_image ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
649 |
+
'post_gallery_images' => base64_encode( serialize( $post_gallery_images ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
650 |
+
'child_upload_dir' => base64_encode( serialize( $child_upload_dir ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
651 |
+
);
|
652 |
+
return $post_data;
|
653 |
+
}
|
654 |
+
return false;
|
655 |
+
}
|
656 |
+
|
657 |
+
/**
|
658 |
+
* Create new post.
|
659 |
+
*
|
660 |
+
* @param array $new_post Post data array.
|
661 |
+
* @param array $post_custom Post custom meta data.
|
662 |
+
* @param string $post_category Post categories.
|
663 |
+
* @param string $post_featured_image Post featured image.
|
664 |
+
* @param string $upload_dir Upload directory.
|
665 |
+
* @param string $post_tags Post tags.
|
666 |
+
* @param array $others Other data.
|
667 |
+
*
|
668 |
+
* @return array|string[] $ret Return success array, permalink & Post ID.
|
669 |
+
*
|
670 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::set_post_custom_data()
|
671 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::update_found_images()
|
672 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::create_has_shortcode_gallery()
|
673 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::create_post_plus()
|
674 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::update_post_data()
|
675 |
+
*/
|
676 |
+
private function create_post(
|
677 |
+
$new_post,
|
678 |
+
$post_custom,
|
679 |
+
$post_category,
|
680 |
+
$post_featured_image,
|
681 |
+
$upload_dir,
|
682 |
+
$post_tags,
|
683 |
+
$others = array()
|
684 |
+
) {
|
685 |
+
|
686 |
+
/**
|
687 |
+
* Hook: `mainwp_before_post_update`
|
688 |
+
*
|
689 |
+
* Runs before creating or updating a post via MainWP dashboard.
|
690 |
+
*
|
691 |
+
* @param array $new_post � Post data array.
|
692 |
+
* @param array $post_custom � Post custom meta data.
|
693 |
+
* @param string $post_category � Post categories.
|
694 |
+
* @param string $post_tags � Post tags.
|
695 |
+
*/
|
696 |
+
do_action( 'mainwp_before_post_update', $new_post, $post_custom, $post_category, $post_tags );
|
697 |
+
|
698 |
+
$edit_post_id = 0;
|
699 |
+
$is_post_plus = false;
|
700 |
+
|
701 |
+
$this->set_post_custom_data( $new_post, $post_custom, $post_tags, $edit_post_id, $is_post_plus );
|
702 |
+
|
703 |
+
require_once ABSPATH . 'wp-admin/includes/post.php';
|
704 |
+
|
705 |
+
if ( $edit_post_id ) {
|
706 |
+
$user_id = wp_check_post_lock( $edit_post_id );
|
707 |
+
if ( $user_id ) {
|
708 |
+
$user = get_userdata( $user_id );
|
709 |
+
$error = sprintf( __( 'This content is currently locked. %s is currently editing.', 'mainwp-child' ), $user->display_name );
|
710 |
+
return array( 'error' => $error );
|
711 |
+
}
|
712 |
+
}
|
713 |
+
|
714 |
+
// if editing post then will check if image existed.
|
715 |
+
$check_image_existed = $edit_post_id ? true : false;
|
716 |
+
|
717 |
+
$this->update_found_images( $new_post, $upload_dir, $check_image_existed );
|
718 |
+
$this->create_has_shortcode_gallery( $new_post );
|
719 |
+
|
720 |
+
if ( $is_post_plus ) {
|
721 |
+
$this->create_post_plus( $new_post, $post_custom );
|
722 |
+
}
|
723 |
+
|
724 |
+
// Save the post to the WP.
|
725 |
+
remove_filter( 'content_save_pre', 'wp_filter_post_kses' ); // to fix brake scripts or html.
|
726 |
+
$post_status = $new_post['post_status']; // save post_status.
|
727 |
+
$new_post['post_status'] = 'auto-draft'; // to fix reports, to log as created post.
|
728 |
+
|
729 |
+
// Update post.
|
730 |
+
if ( $edit_post_id ) {
|
731 |
+
// check if post existed.
|
732 |
+
$current_post = get_post( $edit_post_id );
|
733 |
+
if ( $current_post && ( ( ! isset( $new_post['post_type'] ) && 'post' == $current_post->post_type ) || ( isset( $new_post['post_type'] ) && $new_post['post_type'] == $current_post->post_type ) ) ) {
|
734 |
+
$new_post['ID'] = $edit_post_id;
|
735 |
+
}
|
736 |
+
$new_post['post_status'] = $post_status; // child reports: to logging as update post.
|
737 |
+
}
|
738 |
+
$wp_error = null;
|
739 |
+
$new_post_id = wp_insert_post( $new_post, $wp_error ); // insert post.
|
740 |
+
// Show errors if something went wrong.
|
741 |
+
if ( is_wp_error( $wp_error ) ) {
|
742 |
+
return $wp_error->get_error_message();
|
743 |
+
}
|
744 |
+
if ( empty( $new_post_id ) ) {
|
745 |
+
return array( 'error' => 'Empty post id' );
|
746 |
+
}
|
747 |
+
if ( ! $edit_post_id ) {
|
748 |
+
wp_update_post(
|
749 |
+
array(
|
750 |
+
'ID' => $new_post_id,
|
751 |
+
'post_status' => $post_status,
|
752 |
+
)
|
753 |
+
);
|
754 |
+
}
|
755 |
+
$this->update_post_data( $new_post_id, $post_custom, $post_category, $post_featured_image, $check_image_existed, $is_post_plus );
|
756 |
+
// unlock if edit post.
|
757 |
+
if ( $edit_post_id ) {
|
758 |
+
update_post_meta( $edit_post_id, '_edit_lock', '' );
|
759 |
+
}
|
760 |
+
$permalink = get_permalink( $new_post_id );
|
761 |
+
$ret['success'] = true;
|
762 |
+
$ret['link'] = $permalink;
|
763 |
+
$ret['added_id'] = $new_post_id;
|
764 |
+
return $ret;
|
765 |
+
}
|
766 |
+
|
767 |
+
/**
|
768 |
+
* Set custom post data.
|
769 |
+
*
|
770 |
+
* @param array $new_post Post data array.
|
771 |
+
* @param array $post_custom Post custom meta data.
|
772 |
+
* @param string $post_tags Post tags.
|
773 |
+
* @param string $edit_post_id Edit Post ID.
|
774 |
+
* @param bool $is_post_plus TRUE|FALSE, Whether or not this came from MainWP Post Plus Extension.
|
775 |
+
*
|
776 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::update_wp_rocket_custom_post()
|
777 |
+
*/
|
778 |
+
private function set_post_custom_data( &$new_post, $post_custom, $post_tags, &$edit_post_id, &$is_post_plus ) {
|
779 |
+
|
780 |
+
/**
|
781 |
+
* Current user global.
|
782 |
+
*
|
783 |
+
* @global string
|
784 |
+
*/
|
785 |
+
global $current_user;
|
786 |
+
|
787 |
+
$this->update_wp_rocket_custom_post( $post_custom );
|
788 |
+
|
789 |
+
// current user may be connected admin or alternative admin.
|
790 |
+
$current_uid = $current_user->ID;
|
791 |
+
|
792 |
+
// Set up a new post (adding additional information).
|
793 |
+
$new_post['post_author'] = isset( $new_post['post_author'] ) && ! empty( $new_post['post_author'] ) ? $new_post['post_author'] : $current_uid;
|
794 |
+
|
795 |
+
if ( isset( $new_post['custom_post_author'] ) && ! empty( $new_post['custom_post_author'] ) ) {
|
796 |
+
$_author = get_user_by( 'login', $new_post['custom_post_author'] );
|
797 |
+
if ( ! empty( $_author ) ) {
|
798 |
+
$new_post['post_author'] = $_author->ID;
|
799 |
+
}
|
800 |
+
unset( $new_post['custom_post_author'] );
|
801 |
+
}
|
802 |
+
|
803 |
+
// post plus extension process.
|
804 |
+
$is_post_plus = isset( $post_custom['_mainwp_post_plus'] ) ? true : false;
|
805 |
+
|
806 |
+
if ( $is_post_plus ) {
|
807 |
+
if ( isset( $new_post['post_date_gmt'] ) && ! empty( $new_post['post_date_gmt'] ) && '0000-00-00 00:00:00' != $new_post['post_date_gmt'] ) {
|
808 |
+
$post_date_timestamp = strtotime( $new_post['post_date_gmt'] ) + get_option( 'gmt_offset' ) * 60 * 60;
|
809 |
+
$new_post['post_date'] = date( 'Y-m-d H:i:s', $post_date_timestamp ); // phpcs:ignore -- local time.
|
810 |
+
}
|
811 |
+
}
|
812 |
+
|
813 |
+
if ( isset( $post_tags ) && '' !== $post_tags ) {
|
814 |
+
$new_post['tags_input'] = $post_tags;
|
815 |
+
}
|
816 |
+
|
817 |
+
if ( isset( $post_custom['_mainwp_edit_post_id'] ) && $post_custom['_mainwp_edit_post_id'] ) {
|
818 |
+
$edit_post_id = current( $post_custom['_mainwp_edit_post_id'] );
|
819 |
+
} elseif ( isset( $new_post['ID'] ) && $new_post['ID'] ) {
|
820 |
+
$edit_post_id = $new_post['ID'];
|
821 |
+
}
|
822 |
+
}
|
823 |
+
|
824 |
+
/**
|
825 |
+
* Update post data.
|
826 |
+
*
|
827 |
+
* @param string $new_post_id New post ID.
|
828 |
+
* @param array $post_custom Post custom meta data.
|
829 |
+
* @param string $post_category Post categories.
|
830 |
+
* @param string $post_featured_image Post featured image.
|
831 |
+
* @param bool $check_image_existed TRUE|FALSE, Whether or not featured image already exists.
|
832 |
+
* @param bool $is_post_plus TRUE|FALSE, Whether or not this came from MainWP Post Plus Extension.
|
833 |
+
*
|
834 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::set_custom_post_fields()
|
835 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::update_seo_meta()
|
836 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::create_set_categories()
|
837 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::create_featured_image()
|
838 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::post_plus_update_author()
|
839 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::post_plus_update_categories()
|
840 |
+
*/
|
841 |
+
private function update_post_data( $new_post_id, $post_custom, $post_category, $post_featured_image, $check_image_existed, $is_post_plus ) {
|
842 |
+
|
843 |
+
$seo_ext_activated = false;
|
844 |
+
if ( class_exists( '\WPSEO_Meta' ) && class_exists( '\WPSEO_Admin' ) ) {
|
845 |
+
$seo_ext_activated = true;
|
846 |
+
}
|
847 |
+
|
848 |
+
$post_to_only_existing_categories = false;
|
849 |
+
|
850 |
+
$this->set_custom_post_fields( $new_post_id, $post_custom, $seo_ext_activated, $post_to_only_existing_categories );
|
851 |
+
|
852 |
+
// yoast seo plugin activated.
|
853 |
+
if ( $seo_ext_activated ) {
|
854 |
+
$this->update_seo_meta( $new_post_id, $post_custom );
|
855 |
+
}
|
856 |
+
|
857 |
+
$this->create_set_categories( $new_post_id, $post_category, $post_to_only_existing_categories );
|
858 |
+
$this->create_featured_image( $new_post_id, $post_featured_image, $check_image_existed );
|
859 |
+
|
860 |
+
// post plus extension process.
|
861 |
+
if ( $is_post_plus ) {
|
862 |
+
$this->post_plus_update_author( $new_post_id, $post_custom );
|
863 |
+
$this->post_plus_update_categories( $new_post_id, $post_custom );
|
864 |
+
}
|
865 |
+
|
866 |
+
// to support custom post author.
|
867 |
+
$custom_post_author = apply_filters( 'mainwp_create_post_custom_author', false, $new_post_id );
|
868 |
+
if ( ! empty( $custom_post_author ) ) {
|
869 |
+
wp_update_post(
|
870 |
+
array(
|
871 |
+
'ID' => $new_post_id,
|
872 |
+
'post_author' => $custom_post_author,
|
873 |
+
)
|
874 |
+
);
|
875 |
+
}
|
876 |
+
}
|
877 |
+
|
878 |
+
/**
|
879 |
+
* Update WPRocket custom post.
|
880 |
+
*
|
881 |
+
* @param array $post_custom Post custom meta data.
|
882 |
+
*
|
883 |
+
* @uses \MainWP\Child\MainWP_Child_WP_Rocket::instance()::is_activated()
|
884 |
+
* @uses \get_rocket_option()
|
885 |
+
*/
|
886 |
+
private function update_wp_rocket_custom_post( &$post_custom ) {
|
887 |
+
// Options fields.
|
888 |
+
$wprocket_fields = array(
|
889 |
+
'lazyload',
|
890 |
+
'lazyload_iframes',
|
891 |
+
'minify_html',
|
892 |
+
'minify_css',
|
893 |
+
'minify_js',
|
894 |
+
'cdn',
|
895 |
+
'async_css',
|
896 |
+
'defer_all_js',
|
897 |
+
);
|
898 |
+
|
899 |
+
$wprocket_activated = false;
|
900 |
+
if ( MainWP_Child_WP_Rocket::instance()->is_activated() ) {
|
901 |
+
if ( function_exists( '\get_rocket_option' ) ) {
|
902 |
+
$wprocket_activated = true;
|
903 |
+
foreach ( $wprocket_fields as $field ) {
|
904 |
+
if ( ! isset( $post_custom[ '_rocket_exclude_' . $field ] ) ) {
|
905 |
+
if ( ! \get_rocket_option( $field ) ) {
|
906 |
+
$post_custom[ '_rocket_exclude_' . $field ] = array( true );
|
907 |
+
}
|
908 |
+
}
|
909 |
+
}
|
910 |
+
}
|
911 |
+
}
|
912 |
+
if ( ! $wprocket_activated ) {
|
913 |
+
foreach ( $wprocket_fields as $field ) {
|
914 |
+
if ( isset( $post_custom[ '_rocket_exclude_' . $field ] ) ) {
|
915 |
+
unset( $post_custom[ '_rocket_exclude_' . $field ] );
|
916 |
+
}
|
917 |
+
}
|
918 |
+
}
|
919 |
+
}
|
920 |
+
|
921 |
+
/**
|
922 |
+
* Search for all the images added to the new post.
|
923 |
+
*
|
924 |
+
* @param array $new_post Post data array.
|
925 |
+
* @param string $upload_dir Upload directory.
|
926 |
+
* @param bool $check_image_existed TRUE|FALSE, Whether or not featured image already exists.
|
927 |
+
*
|
928 |
+
* @uses \MainWP\Child\MainWP_Utility::upload_image()
|
929 |
+
* @uses \MainWP\Child\MainWP_Helper::log_debug()
|
930 |
+
*/
|
931 |
+
private function update_found_images( &$new_post, $upload_dir, $check_image_existed ) {
|
932 |
+
|
933 |
+
// Some images have a href tag to click to navigate to the image.. we need to replace this too.
|
934 |
+
$foundMatches = preg_match_all( '/(<a[^>]+href=\"(.*?)\"[^>]*>)?(<img[^>\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $new_post['post_content'], $matches, PREG_SET_ORDER );
|
935 |
+
if ( $foundMatches > 0 ) {
|
936 |
+
// We found images, now to download them so we can start balbal.
|
937 |
+
foreach ( $matches as $match ) {
|
938 |
+
$hrefLink = $match[2];
|
939 |
+
$imgUrl = $match[4];
|
940 |
+
|
941 |
+
if ( ! isset( $upload_dir['baseurl'] ) || ( 0 !== strripos( $imgUrl, $upload_dir['baseurl'] ) ) ) {
|
942 |
+
continue;
|
943 |
+
}
|
944 |
+
|
945 |
+
if ( preg_match( '/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $imgUrl, $imgMatches ) ) {
|
946 |
+
$search = $imgMatches[0];
|
947 |
+
$replace = '.' . $match[6];
|
948 |
+
$originalImgUrl = str_replace( $search, $replace, $imgUrl );
|
949 |
+
} else {
|
950 |
+
$originalImgUrl = $imgUrl;
|
951 |
+
}
|
952 |
+
|
953 |
+
try {
|
954 |
+
$downloadfile = MainWP_Utility::upload_image( $originalImgUrl, array(), $check_image_existed );
|
955 |
+
$localUrl = $downloadfile['url'];
|
956 |
+
$linkToReplaceWith = dirname( $localUrl );
|
957 |
+
if ( '' !== $hrefLink ) {
|
958 |
+
$server = get_option( 'mainwp_child_server' );
|
959 |
+
$serverHost = wp_parse_url( $server, PHP_URL_HOST );
|
960 |
+
if ( ! empty( $serverHost ) && strpos( $hrefLink, $serverHost ) !== false ) {
|
961 |
+
$serverHref = 'href="' . $serverHost;
|
962 |
+
$replaceServerHref = 'href="' . wp_parse_url( $localUrl, PHP_URL_SCHEME ) . '://' . wp_parse_url( $localUrl, PHP_URL_HOST );
|
963 |
+
$new_post['post_content'] = str_replace( $serverHref, $replaceServerHref, $new_post['post_content'] );
|
964 |
+
}
|
965 |
+
}
|
966 |
+
$lnkToReplace = dirname( $imgUrl );
|
967 |
+
if ( 'http:' !== $lnkToReplace && 'https:' !== $lnkToReplace ) {
|
968 |
+
$new_post['post_content'] = str_replace( $lnkToReplace, $linkToReplaceWith, $new_post['post_content'] );
|
969 |
+
}
|
970 |
+
} catch ( \Exception $e ) {
|
971 |
+
MainWP_Helper::log_debug( $e->getMessage() );
|
972 |
+
}
|
973 |
+
}
|
974 |
+
}
|
975 |
+
}
|
976 |
+
|
977 |
+
/**
|
978 |
+
* Create shortcode image gallery.
|
979 |
+
*
|
980 |
+
* @param array $new_post Post data array.
|
981 |
+
*
|
982 |
+
* @uses \MainWP\Child\MainWP_Utility::upload_image()
|
983 |
+
* @uses \Exception()
|
984 |
+
*/
|
985 |
+
private function create_has_shortcode_gallery( &$new_post ) {
|
986 |
+
|
987 |
+
if ( has_shortcode( $new_post['post_content'], 'gallery' ) ) {
|
988 |
+
if ( preg_match_all( '/\[gallery[^\]]+ids=\"(.*?)\"[^\]]*\]/ix', $new_post['post_content'], $matches, PREG_SET_ORDER ) ) {
|
989 |
+
$replaceAttachedIds = array();
|
990 |
+
if ( isset( $_POST['post_gallery_images'] ) ) {
|
991 |
+
$post_gallery_images = isset( $_POST['post_gallery_images'] ) ? unserialize( base64_decode( wp_unslash( $_POST['post_gallery_images'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
992 |
+
if ( is_array( $post_gallery_images ) ) {
|
993 |
+
foreach ( $post_gallery_images as $gallery ) {
|
994 |
+
if ( isset( $gallery['src'] ) ) {
|
995 |
+
try {
|
996 |
+
$upload = MainWP_Utility::upload_image( $gallery['src'], $gallery ); // Upload image to WP.
|
997 |
+
if ( null !== $upload ) {
|
998 |
+
$replaceAttachedIds[ $gallery['id'] ] = $upload['id'];
|
999 |
+
}
|
1000 |
+
} catch ( \Exception $e ) {
|
1001 |
+
// ok!
|
1002 |
+
}
|
1003 |
+
}
|
1004 |
+
}
|
1005 |
+
}
|
1006 |
+
}
|
1007 |
+
if ( count( $replaceAttachedIds ) > 0 ) {
|
1008 |
+
foreach ( $matches as $match ) {
|
1009 |
+
$idsToReplace = $match[1];
|
1010 |
+
$idsToReplaceWith = '';
|
1011 |
+
$originalIds = explode( ',', $idsToReplace );
|
1012 |
+
foreach ( $originalIds as $attached_id ) {
|
1013 |
+
if ( ! empty( $originalIds ) && isset( $replaceAttachedIds[ $attached_id ] ) ) {
|
1014 |
+
$idsToReplaceWith .= $replaceAttachedIds[ $attached_id ] . ',';
|
1015 |
+
}
|
1016 |
+
}
|
1017 |
+
$idsToReplaceWith = rtrim( $idsToReplaceWith, ',' );
|
1018 |
+
if ( ! empty( $idsToReplaceWith ) ) {
|
1019 |
+
$new_post['post_content'] = str_replace( '"' . $idsToReplace . '"', '"' . $idsToReplaceWith . '"', $new_post['post_content'] );
|
1020 |
+
}
|
1021 |
+
}
|
1022 |
+
}
|
1023 |
+
}
|
1024 |
+
}
|
1025 |
+
}
|
1026 |
+
|
1027 |
+
/**
|
1028 |
+
* Create post plus post.
|
1029 |
+
*
|
1030 |
+
* @param array $new_post Post data array.
|
1031 |
+
* @param array $post_custom Post custom meta data.
|
1032 |
+
*/
|
1033 |
+
private function create_post_plus( &$new_post, $post_custom ) {
|
1034 |
+
$random_publish_date = isset( $post_custom['_saved_draft_random_publish_date'] ) ? $post_custom['_saved_draft_random_publish_date'] : false;
|
1035 |
+
$random_publish_date = is_array( $random_publish_date ) ? current( $random_publish_date ) : null;
|
1036 |
+
|
1037 |
+
if ( ! empty( $random_publish_date ) ) {
|
1038 |
+
$random_date_from = isset( $post_custom['_saved_draft_publish_date_from'] ) ? $post_custom['_saved_draft_publish_date_from'] : 0;
|
1039 |
+
$random_date_from = is_array( $random_date_from ) ? current( $random_date_from ) : 0;
|
1040 |
+
|
1041 |
+
$random_date_to = isset( $post_custom['_saved_draft_publish_date_to'] ) ? $post_custom['_saved_draft_publish_date_to'] : 0;
|
1042 |
+
$random_date_to = is_array( $random_date_to ) ? current( $random_date_to ) : 0;
|
1043 |
+
|
1044 |
+
$now = time();
|
1045 |
+
|
1046 |
+
if ( empty( $random_date_from ) ) {
|
1047 |
+
$random_date_from = $now;
|
1048 |
+
}
|
1049 |
+
|
1050 |
+
if ( empty( $random_date_to ) ) {
|
1051 |
+
$random_date_to = $now;
|
1052 |
+
}
|
1053 |
+
|
1054 |
+
if ( $random_date_from === $now && $random_date_from === $random_date_to ) {
|
1055 |
+
$random_date_to = $now + 7 * 24 * 3600;
|
1056 |
+
}
|
1057 |
+
|
1058 |
+
if ( $random_date_from > $random_date_to ) {
|
1059 |
+
$tmp = $random_date_from;
|
1060 |
+
$random_date_from = $random_date_to;
|
1061 |
+
$random_date_to = $tmp;
|
1062 |
+
}
|
1063 |
+
|
1064 |
+
$random_timestamp = wp_rand( $random_date_from, $random_date_to );
|
1065 |
+
$new_post['post_date'] = date( 'Y-m-d H:i:s', $random_timestamp ); // phpcs:ignore -- local time.
|
1066 |
+
}
|
1067 |
+
}
|
1068 |
+
|
1069 |
+
/**
|
1070 |
+
* Update post plus author.
|
1071 |
+
*
|
1072 |
+
* @param string $new_post_id New post ID.
|
1073 |
+
* @param array $post_custom Post custom meta data.
|
1074 |
+
*/
|
1075 |
+
private function post_plus_update_author( $new_post_id, $post_custom ) {
|
1076 |
+
$random_privelege = isset( $post_custom['_saved_draft_random_privelege'] ) ? $post_custom['_saved_draft_random_privelege'] : null;
|
1077 |
+
$random_privelege = is_array( $random_privelege ) ? current( $random_privelege ) : null;
|
1078 |
+
$random_privelege_base = base64_decode( $random_privelege ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
1079 |
+
$random_privelege = maybe_unserialize( $random_privelege_base );
|
1080 |
+
|
1081 |
+
if ( is_array( $random_privelege ) && count( $random_privelege ) > 0 ) {
|
1082 |
+
$random_post_authors = array();
|
1083 |
+
foreach ( $random_privelege as $role ) {
|
1084 |
+
$users = get_users( array( 'role' => $role ) );
|
1085 |
+
foreach ( $users as $user ) {
|
1086 |
+
$random_post_authors[] = $user->ID;
|
1087 |
+
}
|
1088 |
+
}
|
1089 |
+
if ( count( $random_post_authors ) > 0 ) {
|
1090 |
+
shuffle( $random_post_authors );
|
1091 |
+
$key = array_rand( $random_post_authors );
|
1092 |
+
wp_update_post(
|
1093 |
+
array(
|
1094 |
+
'ID' => $new_post_id,
|
1095 |
+
'post_author' => $random_post_authors[ $key ],
|
1096 |
+
)
|
1097 |
+
);
|
1098 |
+
}
|
1099 |
+
}
|
1100 |
+
}
|
1101 |
+
|
1102 |
+
/**
|
1103 |
+
* Update post plus categories.
|
1104 |
+
*
|
1105 |
+
* @param string $new_post_id New post ID.
|
1106 |
+
* @param array $post_custom Post custom meta data.
|
1107 |
+
*/
|
1108 |
+
private function post_plus_update_categories( $new_post_id, $post_custom ) {
|
1109 |
+
$random_category = isset( $post_custom['_saved_draft_random_category'] ) ? $post_custom['_saved_draft_random_category'] : false;
|
1110 |
+
$random_category = is_array( $random_category ) ? current( $random_category ) : null;
|
1111 |
+
if ( ! empty( $random_category ) ) {
|
1112 |
+
$cats = get_categories(
|
1113 |
+
array(
|
1114 |
+
'type' => 'post',
|
1115 |
+
'hide_empty' => 0,
|
1116 |
+
)
|
1117 |
+
);
|
1118 |
+
$random_cats = array();
|
1119 |
+
if ( is_array( $cats ) ) {
|
1120 |
+
foreach ( $cats as $cat ) {
|
1121 |
+
$random_cats[] = $cat->term_id;
|
1122 |
+
}
|
1123 |
+
}
|
1124 |
+
if ( count( $random_cats ) > 0 ) {
|
1125 |
+
shuffle( $random_cats );
|
1126 |
+
$key = array_rand( $random_cats );
|
1127 |
+
wp_set_post_categories( $new_post_id, array( $random_cats[ $key ] ), false );
|
1128 |
+
}
|
1129 |
+
}
|
1130 |
+
}
|
1131 |
+
|
1132 |
+
/**
|
1133 |
+
* Create new and set categories.
|
1134 |
+
*
|
1135 |
+
* @param string $new_post_id New post ID.
|
1136 |
+
* @param string $post_category Post category.
|
1137 |
+
* @param bool $post_to_only TRUE|FALSE, Whether or not to post only to this category.
|
1138 |
+
*
|
1139 |
+
* @uses wp_create_categories() Create categories for the given post.
|
1140 |
+
* @see https://developer.wordpress.org/reference/functions/wp_create_categories/
|
1141 |
+
*
|
1142 |
+
* @uses wp_set_post_categories() Set categories for a post.
|
1143 |
+
* @see https://developer.wordpress.org/reference/functions/wp_set_post_categories/
|
1144 |
+
*/
|
1145 |
+
private function create_set_categories( $new_post_id, $post_category, $post_to_only ) {
|
1146 |
+
|
1147 |
+
// If categories exist, create them (second parameter of wp_create_categories adds the categories to the post).
|
1148 |
+
include_once ABSPATH . 'wp-admin/includes/taxonomy.php'; // Contains wp_create_categories.
|
1149 |
+
if ( isset( $post_category ) && '' !== $post_category ) {
|
1150 |
+
$categories = explode( ',', $post_category );
|
1151 |
+
if ( count( $categories ) > 0 ) {
|
1152 |
+
if ( ! $post_to_only ) {
|
1153 |
+
$post_category = wp_create_categories( $categories, $new_post_id );
|
1154 |
+
} else {
|
1155 |
+
$cat_ids = array();
|
1156 |
+
foreach ( $categories as $cat ) {
|
1157 |
+
$id = category_exists( $cat );
|
1158 |
+
if ( $id ) {
|
1159 |
+
$cat_ids[] = $id;
|
1160 |
+
}
|
1161 |
+
}
|
1162 |
+
if ( count( $cat_ids ) > 0 ) {
|
1163 |
+
wp_set_post_categories( $new_post_id, $cat_ids );
|
1164 |
+
}
|
1165 |
+
}
|
1166 |
+
}
|
1167 |
+
}
|
1168 |
+
}
|
1169 |
+
|
1170 |
+
/**
|
1171 |
+
* Set custom post fields.
|
1172 |
+
*
|
1173 |
+
* @param string $new_post_id New post ID.
|
1174 |
+
* @param array $post_custom Post custom meta data.
|
1175 |
+
* @param bool $seo_ext_activated TRUE|FALSE, Whether or not Yoast SEO is activateed or not.
|
1176 |
+
* @param bool $post_to_only TRUE|FALSE, Whether or not to post only to this category.
|
1177 |
+
*/
|
1178 |
+
private function set_custom_post_fields( $new_post_id, $post_custom, $seo_ext_activated, &$post_to_only ) {
|
1179 |
+
|
1180 |
+
// Set custom fields.
|
1181 |
+
$not_allowed = array(
|
1182 |
+
'_slug',
|
1183 |
+
'_tags',
|
1184 |
+
'_edit_lock',
|
1185 |
+
'_selected_sites',
|
1186 |
+
'_selected_groups',
|
1187 |
+
'_selected_by',
|
1188 |
+
'_categories',
|
1189 |
+
'_edit_last',
|
1190 |
+
'_sticky',
|
1191 |
+
'_mainwp_post_dripper',
|
1192 |
+
'_bulkpost_do_not_del',
|
1193 |
+
'_mainwp_spin_me',
|
1194 |
+
'_mainwp_boilerplate_sites_posts',
|
1195 |
+
'_mainwp_boilerplate',
|
1196 |
+
'_mainwp_post_plus',
|
1197 |
+
'_saved_as_draft',
|
1198 |
+
'_saved_draft_categories',
|
1199 |
+
'_saved_draft_tags',
|
1200 |
+
'_saved_draft_random_privelege',
|
1201 |
+
'_saved_draft_random_category',
|
1202 |
+
'_saved_draft_random_publish_date',
|
1203 |
+
'_saved_draft_publish_date_from',
|
1204 |
+
'_saved_draft_publish_date_to',
|
1205 |
+
'_post_to_only_existing_categories',
|
1206 |
+
'_mainwp_edit_post_site_id',
|
1207 |
+
'_mainwp_edit_post_id',
|
1208 |
+
'_edit_post_status',
|
1209 |
+
);
|
1210 |
+
|
1211 |
+
if ( is_array( $post_custom ) ) {
|
1212 |
+
foreach ( $post_custom as $meta_key => $meta_values ) {
|
1213 |
+
if ( ! in_array( $meta_key, $not_allowed ) ) {
|
1214 |
+
foreach ( $meta_values as $meta_value ) {
|
1215 |
+
if ( 0 === strpos( $meta_key, '_mainwp_spinner_' ) ) {
|
1216 |
+
continue;
|
1217 |
+
}
|
1218 |
+
|
1219 |
+
if ( ! $seo_ext_activated ) {
|
1220 |
+
// if WordPress SEO plugin is not activated do not save yoast post meta.
|
1221 |
+
if ( false === strpos( $meta_key, '_yoast_wpseo_' ) ) {
|
1222 |
+
update_post_meta( $new_post_id, $meta_key, $meta_value );
|
1223 |
+
}
|
1224 |
+
} else {
|
1225 |
+
update_post_meta( $new_post_id, $meta_key, $meta_value );
|
1226 |
+
}
|
1227 |
+
}
|
1228 |
+
} elseif ( '_sticky' === $meta_key ) {
|
1229 |
+
foreach ( $meta_values as $meta_value ) {
|
1230 |
+
if ( 'sticky' === base64_decode( $meta_value ) ) { // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
1231 |
+
stick_post( $new_post_id );
|
1232 |
+
}
|
1233 |
+
}
|
1234 |
+
} elseif ( '_post_to_only_existing_categories' === $meta_key ) {
|
1235 |
+
if ( isset( $meta_values[0] ) && $meta_values[0] ) {
|
1236 |
+
$post_to_only = true;
|
1237 |
+
}
|
1238 |
+
}
|
1239 |
+
}
|
1240 |
+
}
|
1241 |
+
}
|
1242 |
+
|
1243 |
+
/**
|
1244 |
+
* Update Yoast SEO Extension meta.
|
1245 |
+
*
|
1246 |
+
* @param string $new_post_id New post ID.
|
1247 |
+
* @param array $post_custom Post custom meta data.
|
1248 |
+
*
|
1249 |
+
* @uses \MainWP\Child\MainWP_Utility::upload_image()
|
1250 |
+
* @uses \WPSEO_Meta::$meta_prefix()
|
1251 |
+
* @uses \Exception()
|
1252 |
+
*/
|
1253 |
+
private function update_seo_meta( $new_post_id, $post_custom ) {
|
1254 |
+
|
1255 |
+
$_seo_opengraph_image = isset( $post_custom[ \WPSEO_Meta::$meta_prefix . 'opengraph-image' ] ) ? $post_custom[ \WPSEO_Meta::$meta_prefix . 'opengraph-image' ] : array();
|
1256 |
+
$_seo_opengraph_image = current( $_seo_opengraph_image );
|
1257 |
+
$_server_domain = '';
|
1258 |
+
$_server = get_option( 'mainwp_child_server' );
|
1259 |
+
if ( preg_match( '/(https?:\/\/[^\/]+\/).+/', $_server, $matchs ) ) {
|
1260 |
+
$_server_domain = isset( $matchs[1] ) ? $matchs[1] : '';
|
1261 |
+
}
|
1262 |
+
|
1263 |
+
// upload image if it on the server.
|
1264 |
+
if ( ! empty( $_seo_opengraph_image ) && false !== strpos( $_seo_opengraph_image, $_server_domain ) ) {
|
1265 |
+
try {
|
1266 |
+
$upload = MainWP_Utility::upload_image( $_seo_opengraph_image ); // Upload image to WP.
|
1267 |
+
if ( null !== $upload ) {
|
1268 |
+
update_post_meta( $new_post_id, \WPSEO_Meta::$meta_prefix . 'opengraph-image', $upload['url'] ); // Add the image to the post!
|
1269 |
+
}
|
1270 |
+
} catch ( \Exception $e ) {
|
1271 |
+
// ok!
|
1272 |
+
}
|
1273 |
+
}
|
1274 |
+
}
|
1275 |
+
|
1276 |
+
/**
|
1277 |
+
* Create featured image.
|
1278 |
+
*
|
1279 |
+
* @param string $new_post_id New post ID.
|
1280 |
+
* @param string $post_featured_image Post featured image.
|
1281 |
+
* @param bool $check_image_existed TRUE|FALSE, Whether or not featured image already exists.
|
1282 |
+
*
|
1283 |
+
* @uses \MainWP\Child\MainWP_Utility::upload_image()
|
1284 |
+
* @uses \Excepsion()
|
1285 |
+
*/
|
1286 |
+
private function create_featured_image( $new_post_id, $post_featured_image, $check_image_existed ) {
|
1287 |
+
|
1288 |
+
$featured_image_exist = false;
|
1289 |
+
// If featured image exists - set it.
|
1290 |
+
if ( null !== $post_featured_image ) {
|
1291 |
+
try {
|
1292 |
+
$upload = MainWP_Utility::upload_image( $post_featured_image, array(), $check_image_existed, $new_post_id ); // Upload image to WP.
|
1293 |
+
if ( null !== $upload ) {
|
1294 |
+
update_post_meta( $new_post_id, '_thumbnail_id', $upload['id'] ); // Add the thumbnail to the post!
|
1295 |
+
$featured_image_exist = true;
|
1296 |
+
if ( isset( $others['featured_image_data'] ) ) {
|
1297 |
+
$_image_data = $others['featured_image_data'];
|
1298 |
+
update_post_meta( $upload['id'], '_wp_attachment_image_alt', $_image_data['alt'] );
|
1299 |
+
wp_update_post(
|
1300 |
+
array(
|
1301 |
+
'ID' => $upload['id'],
|
1302 |
+
'post_excerpt' => $_image_data['caption'],
|
1303 |
+
'post_content' => $_image_data['description'],
|
1304 |
+
'post_title' => $_image_data['title'],
|
1305 |
+
)
|
1306 |
+
);
|
1307 |
+
}
|
1308 |
+
}
|
1309 |
+
} catch ( \Exception $e ) {
|
1310 |
+
// ok!
|
1311 |
+
}
|
1312 |
+
}
|
1313 |
+
|
1314 |
+
if ( ! $featured_image_exist ) {
|
1315 |
+
delete_post_meta( $new_post_id, '_thumbnail_id' );
|
1316 |
+
}
|
1317 |
+
}
|
1318 |
+
|
1319 |
+
}
|
class/class-mainwp-child-robot.php
DELETED
@@ -1,34 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class MainWP_Child_Robot {
|
4 |
-
public static $instance = null;
|
5 |
-
|
6 |
-
static function Instance() {
|
7 |
-
if ( null === MainWP_Child_Robot::$instance ) {
|
8 |
-
MainWP_Child_Robot::$instance = new MainWP_Child_Robot();
|
9 |
-
}
|
10 |
-
|
11 |
-
return MainWP_Child_Robot::$instance;
|
12 |
-
}
|
13 |
-
|
14 |
-
public function wpr_insertcomments( $postid, $comments ) {
|
15 |
-
remove_filter( 'comment_text', 'make_clickable', 9 );
|
16 |
-
foreach ( $comments as $comment ) {
|
17 |
-
$comment_post_ID = $postid;
|
18 |
-
$comment_date = $comment['dts'];
|
19 |
-
$comment_date = date( 'Y-m-d H:i:s', $comment_date );
|
20 |
-
$comment_date_gmt = $comment_date;
|
21 |
-
$rnd = rand( 1, 9999 );
|
22 |
-
$comment_author_email = "someone$rnd@domain.com";
|
23 |
-
$comment_author = $comment['author'];
|
24 |
-
$comment_author_url = '';
|
25 |
-
$comment_content = '';
|
26 |
-
$comment_content .= $comment['content'];
|
27 |
-
$comment_type = '';
|
28 |
-
$user_ID = '';
|
29 |
-
$comment_approved = 1;
|
30 |
-
$commentdata = compact( 'comment_post_ID', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID', 'comment_approved' );
|
31 |
-
$comment_id = wp_insert_comment( $commentdata );
|
32 |
-
}
|
33 |
-
}
|
34 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class/class-mainwp-child-server-information-base.php
ADDED
@@ -0,0 +1,765 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Server Information Base
|
4 |
+
*
|
5 |
+
* This is the base set of methods to collect a Child Site's Server Information.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_Server_Information_Base
|
14 |
+
*
|
15 |
+
* Base set of methods to collect a Child Site's server information.
|
16 |
+
*/
|
17 |
+
class MainWP_Child_Server_Information_Base {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Method get_class_name()
|
21 |
+
*
|
22 |
+
* Get class name.
|
23 |
+
*
|
24 |
+
* @return string __CLASS__ Class name.
|
25 |
+
*/
|
26 |
+
public static function get_class_name() {
|
27 |
+
return __CLASS__;
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Initiate check on important System Variables and compare them to required defaults.
|
32 |
+
*
|
33 |
+
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::check()
|
34 |
+
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::check_mainwp_directory()
|
35 |
+
*
|
36 |
+
* @return int $i Number of detected issues.
|
37 |
+
*/
|
38 |
+
protected static function get_warnings() {
|
39 |
+
$i = 0;
|
40 |
+
if ( ! self::check( '>=', '3.4', 'get_wordpress_version' ) ) {
|
41 |
+
$i ++;
|
42 |
+
}
|
43 |
+
if ( ! self::check( '>=', '5.2.4', 'get_php_version' ) ) {
|
44 |
+
$i ++;
|
45 |
+
}
|
46 |
+
if ( ! self::check( '>=', '5.0', 'get_my_sql_version' ) ) {
|
47 |
+
$i ++;
|
48 |
+
}
|
49 |
+
if ( ! self::check( '>=', '30', 'get_max_execution_time', '=', '0' ) ) {
|
50 |
+
$i ++;
|
51 |
+
}
|
52 |
+
if ( ! self::check( '>=', '2M', 'get_upload_max_filesize', null, null, true ) ) {
|
53 |
+
$i ++;
|
54 |
+
}
|
55 |
+
if ( ! self::check( '>=', '2M', 'get_post_max_size', null, null, true ) ) {
|
56 |
+
$i ++;
|
57 |
+
}
|
58 |
+
if ( ! self::check( '>=', '10000', 'get_output_buffer_size' ) ) {
|
59 |
+
$i ++;
|
60 |
+
}
|
61 |
+
if ( ! self::check_mainwp_directory() ) {
|
62 |
+
$i ++;
|
63 |
+
}
|
64 |
+
|
65 |
+
return $i;
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Check if MainWP Directory is writeable.
|
70 |
+
*
|
71 |
+
* @param string $message Return message - Directory not found, Directory not writable, writeable.
|
72 |
+
* @param string $path MainWP directory path.
|
73 |
+
*
|
74 |
+
* @uses MainWP_Helper::get_mainwp_dir()
|
75 |
+
* @uses Exception::getMessage()
|
76 |
+
*
|
77 |
+
* @return bool TRUE if exists & writeable, FALSE if not.
|
78 |
+
*/
|
79 |
+
protected static function check_mainwp_directory( &$message = '', &$path = '' ) {
|
80 |
+
$path = '';
|
81 |
+
try {
|
82 |
+
$dirs = MainWP_Helper::get_mainwp_dir( null, false );
|
83 |
+
$path = $dirs[0];
|
84 |
+
} catch ( \Exception $e ) {
|
85 |
+
$message = $e->getMessage();
|
86 |
+
return false;
|
87 |
+
}
|
88 |
+
|
89 |
+
if ( ! is_dir( dirname( $path ) ) ) {
|
90 |
+
$message = 'Directory not found';
|
91 |
+
return false;
|
92 |
+
}
|
93 |
+
|
94 |
+
$hasWPFileSystem = MainWP_Helper::get_wp_filesystem();
|
95 |
+
|
96 |
+
/**
|
97 |
+
* WordPress files system object.
|
98 |
+
*
|
99 |
+
* @global object
|
100 |
+
*/
|
101 |
+
global $wp_filesystem;
|
102 |
+
|
103 |
+
if ( $hasWPFileSystem && ! empty( $wp_filesystem ) ) {
|
104 |
+
if ( ! $wp_filesystem->is_writable( $path ) ) {
|
105 |
+
$message = 'Directory not writable';
|
106 |
+
return false;
|
107 |
+
}
|
108 |
+
} else {
|
109 |
+
if ( ! is_writable( $path ) ) {
|
110 |
+
$message = 'Directory not writable';
|
111 |
+
return false;
|
112 |
+
}
|
113 |
+
}
|
114 |
+
$message = 'Writable';
|
115 |
+
return true;
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Check Child Site system variables for any issues.
|
120 |
+
*
|
121 |
+
* @param string $pCompare Comparison operator.
|
122 |
+
* @param string $pVersion Version to compare to.
|
123 |
+
* @param string $pGetter The method to grab the data with.
|
124 |
+
* @param string $pExtraCompare Extra comparison operator.
|
125 |
+
* @param string $pExtraVersion Extra version to compare to.
|
126 |
+
* @param bool $sizeCompare Size to compare to.
|
127 |
+
*
|
128 |
+
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::get_class_name()
|
129 |
+
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::filesize_compare()
|
130 |
+
*
|
131 |
+
* @return bool|int When using the optional operator argument, the function will return TRUE if the
|
132 |
+
* relationship is the one specified by the operator, FALSE otherwise. Returns -1 if the first version
|
133 |
+
* is lower than the second, 0 if they are equal, and 1 if the second is lower.
|
134 |
+
*/
|
135 |
+
protected static function check( $pCompare, $pVersion, $pGetter, $pExtraCompare = null, $pExtraVersion = null, $sizeCompare = false ) {
|
136 |
+
$currentVersion = call_user_func( array( self::get_class_name(), $pGetter ) );
|
137 |
+
|
138 |
+
if ( $sizeCompare ) {
|
139 |
+
return self::filesize_compare( $currentVersion, $pVersion, $pCompare );
|
140 |
+
} else {
|
141 |
+
return ( version_compare( $currentVersion, $pVersion, $pCompare ) || ( ( null !== $pExtraCompare ) && version_compare( $currentVersion, $pExtraVersion, $pExtraCompare ) ) );
|
142 |
+
}
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Compare filesizes.
|
147 |
+
*
|
148 |
+
* @param string $value1 First value to compare.
|
149 |
+
* @param string $value2 Second value to compare.
|
150 |
+
* @param string $operator Comparison operator.
|
151 |
+
*
|
152 |
+
* @return bool|int When using the optional operator argument, the function will return TRUE if the
|
153 |
+
* relationship is the one specified by the operator, FALSE otherwise. Returns -1 if the first version
|
154 |
+
* is lower than the second, 0 if they are equal, and 1 if the second is lower.
|
155 |
+
*/
|
156 |
+
protected static function filesize_compare( $value1, $value2, $operator = null ) {
|
157 |
+
if ( false !== strpos( $value1, 'G' ) ) {
|
158 |
+
$value1 = preg_replace( '/[A-Za-z]/', '', $value1 );
|
159 |
+
$value1 = intval( $value1 ) * 1024;
|
160 |
+
} else {
|
161 |
+
$value1 = preg_replace( '/[A-Za-z]/', '', $value1 );
|
162 |
+
}
|
163 |
+
|
164 |
+
if ( false !== strpos( $value2, 'G' ) ) {
|
165 |
+
$value2 = preg_replace( '/[A-Za-z]/', '', $value2 );
|
166 |
+
$value2 = intval( $value2 ) * 1024;
|
167 |
+
} else {
|
168 |
+
$value2 = preg_replace( '/[A-Za-z]/', '', $value2 );
|
169 |
+
}
|
170 |
+
|
171 |
+
return version_compare( $value1, $value2, $operator );
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Check if PHP class curl_version() is enabled.
|
176 |
+
*
|
177 |
+
* @return bool If 'curl_version' function exists, return true, if not, return false.
|
178 |
+
*/
|
179 |
+
protected static function get_curl_support() {
|
180 |
+
return function_exists( 'curl_version' );
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* Get current cURL Timeout.
|
185 |
+
*
|
186 |
+
* @return int Current cURL timeout value.
|
187 |
+
*/
|
188 |
+
protected static function get_curl_timeout() {
|
189 |
+
return ini_get( 'default_socket_timeout' );
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Get current cURL Version.
|
194 |
+
*
|
195 |
+
* @return string Current cURL Version.
|
196 |
+
*/
|
197 |
+
protected static function get_curl_version() {
|
198 |
+
$curlversion = curl_version();
|
199 |
+
|
200 |
+
return $curlversion['version'];
|
201 |
+
}
|
202 |
+
|
203 |
+
/**
|
204 |
+
* Compare current cURL & SSL versions to required values.
|
205 |
+
*
|
206 |
+
* @param string $value Required values to compare to.
|
207 |
+
* @param string $operator Comparison operator.
|
208 |
+
*
|
209 |
+
* @return bool|int When using the optional operator argument, the function will return TRUE if the
|
210 |
+
* relationship is the one specified by the operator, FALSE otherwise. Returns -1 if the first version
|
211 |
+
* is lower than the second, 0 if they are equal, and 1 if the second is lower.
|
212 |
+
*/
|
213 |
+
protected static function curlssl_compare( $value, $operator = null ) {
|
214 |
+
if ( isset( $value['version_number'] ) && defined( 'OPENSSL_VERSION_NUMBER' ) ) {
|
215 |
+
return version_compare( OPENSSL_VERSION_NUMBER, $value['version_number'], $operator );
|
216 |
+
}
|
217 |
+
|
218 |
+
return false;
|
219 |
+
}
|
220 |
+
|
221 |
+
/**
|
222 |
+
* Get curl ssl version.
|
223 |
+
*
|
224 |
+
* @return string SSL version.
|
225 |
+
*/
|
226 |
+
protected static function get_curl_ssl_version() {
|
227 |
+
$curlversion = curl_version();
|
228 |
+
|
229 |
+
return $curlversion['ssl_version'];
|
230 |
+
}
|
231 |
+
|
232 |
+
/**
|
233 |
+
* Check for disabled PHP functions.
|
234 |
+
*/
|
235 |
+
protected static function mainwp_required_functions() {
|
236 |
+
$disabled_functions = ini_get( 'disable_functions' );
|
237 |
+
if ( '' !== $disabled_functions ) {
|
238 |
+
$arr = explode( ',', $disabled_functions );
|
239 |
+
sort( $arr );
|
240 |
+
$arr_length = count( $arr );
|
241 |
+
for ( $i = 0; $i < $arr_length; $i ++ ) {
|
242 |
+
echo esc_html( $arr[ $i ] . ', ' );
|
243 |
+
}
|
244 |
+
} else {
|
245 |
+
echo esc_html__( 'No functions disabled', 'mainwp-child' );
|
246 |
+
}
|
247 |
+
}
|
248 |
+
|
249 |
+
/**
|
250 |
+
* Get loaded PHP extensions.
|
251 |
+
*/
|
252 |
+
protected static function get_loaded_php_extensions() {
|
253 |
+
$extensions = get_loaded_extensions();
|
254 |
+
sort( $extensions );
|
255 |
+
echo esc_html( implode( ', ', $extensions ) );
|
256 |
+
}
|
257 |
+
|
258 |
+
/**
|
259 |
+
* Get file system method.
|
260 |
+
*
|
261 |
+
* @return string $fs The returned file system method.
|
262 |
+
*/
|
263 |
+
protected static function get_file_system_method() {
|
264 |
+
if ( defined( 'MAINWP_SAVE_FS_METHOD' ) ) {
|
265 |
+
return MAINWP_SAVE_FS_METHOD;
|
266 |
+
}
|
267 |
+
$fs = get_filesystem_method();
|
268 |
+
|
269 |
+
return $fs;
|
270 |
+
}
|
271 |
+
|
272 |
+
/**
|
273 |
+
* Get the current MainWP Child plugin version.
|
274 |
+
*
|
275 |
+
* @return string $currentVersion The MainWP Child plugin current version.
|
276 |
+
*/
|
277 |
+
protected static function get_current_version() {
|
278 |
+
$currentVersion = get_option( 'mainwp_child_plugin_version' );
|
279 |
+
|
280 |
+
return $currentVersion;
|
281 |
+
}
|
282 |
+
|
283 |
+
/**
|
284 |
+
* Get the current MainWP Child plugin version.
|
285 |
+
*
|
286 |
+
* @return string|bool Most recent MainWP Child version or FALSE.
|
287 |
+
*/
|
288 |
+
protected static function get_mainwp_version() {
|
289 |
+
include_once ABSPATH . '/wp-admin/includes/plugin-install.php';
|
290 |
+
$api = plugins_api(
|
291 |
+
'plugin_information',
|
292 |
+
array(
|
293 |
+
'slug' => 'mainwp-child',
|
294 |
+
'fields' => array( 'sections' => false ),
|
295 |
+
'timeout' => 60,
|
296 |
+
)
|
297 |
+
);
|
298 |
+
if ( is_object( $api ) && isset( $api->version ) ) {
|
299 |
+
return $api->version;
|
300 |
+
}
|
301 |
+
|
302 |
+
return false;
|
303 |
+
}
|
304 |
+
|
305 |
+
/**
|
306 |
+
* Check if PHP class \ZipArchive is enabled.
|
307 |
+
*
|
308 |
+
* @return bool If '\ZipArchive' class exists, return true, if not, return false.
|
309 |
+
*/
|
310 |
+
protected static function get_zip_archive_enabled() {
|
311 |
+
return class_exists( '\ZipArchive' );
|
312 |
+
}
|
313 |
+
|
314 |
+
/**
|
315 |
+
* Check if PHP function gzopen is enabled.
|
316 |
+
*
|
317 |
+
* @return bool If 'gzopen' function exists, return true, if not, return false.
|
318 |
+
*/
|
319 |
+
protected static function get_gzip_enabled() {
|
320 |
+
return function_exists( 'gzopen' );
|
321 |
+
}
|
322 |
+
|
323 |
+
/**
|
324 |
+
* Check if PHP function bzopen is enabled.
|
325 |
+
*
|
326 |
+
* @return bool If 'bzopen' function exists, return true, if not, return false.
|
327 |
+
*/
|
328 |
+
protected static function get_bzip_enabled() {
|
329 |
+
return function_exists( 'bzopen' );
|
330 |
+
}
|
331 |
+
|
332 |
+
/**
|
333 |
+
* Get current WordPress version.
|
334 |
+
*
|
335 |
+
* @return string $wp_version Current WordPress version.
|
336 |
+
*/
|
337 |
+
protected static function get_wordpress_version() {
|
338 |
+
|
339 |
+
/**
|
340 |
+
* The installed version of WordPress.
|
341 |
+
*
|
342 |
+
* @global string $wp_version The installed version of WordPress.
|
343 |
+
*/
|
344 |
+
global $wp_version;
|
345 |
+
|
346 |
+
return $wp_version;
|
347 |
+
}
|
348 |
+
|
349 |
+
/**
|
350 |
+
* Get current WordPress memory limit.
|
351 |
+
*
|
352 |
+
* @return string Current WordPress memory limit.
|
353 |
+
*/
|
354 |
+
protected static function get_wordpress_memory_limit() {
|
355 |
+
return WP_MEMORY_LIMIT;
|
356 |
+
}
|
357 |
+
|
358 |
+
/**
|
359 |
+
* Check if in multisite WordPress environment.
|
360 |
+
*
|
361 |
+
* @return bool If multisite detected, return false, if not, return true.
|
362 |
+
*/
|
363 |
+
protected static function check_if_multisite() {
|
364 |
+
$isMultisite = ! is_multisite() ? true : false;
|
365 |
+
|
366 |
+
return $isMultisite;
|
367 |
+
}
|
368 |
+
|
369 |
+
/**
|
370 |
+
* Check if PHP extension OpenSSL is enabled.
|
371 |
+
*
|
372 |
+
* @return bool If 'openssl' extension is loaded, return true, if not, return false.
|
373 |
+
*/
|
374 |
+
protected static function get_ssl_support() {
|
375 |
+
return extension_loaded( 'openssl' );
|
376 |
+
}
|
377 |
+
|
378 |
+
/**
|
379 |
+
* Get any SSL warnings.
|
380 |
+
*
|
381 |
+
* @return false|string Return error message if there are warnings, FALSE otherwise.
|
382 |
+
*/
|
383 |
+
protected static function get_ssl_warning() {
|
384 |
+
$conf = array( 'private_key_bits' => 2048 );
|
385 |
+
$str = '';
|
386 |
+
if ( function_exists( 'openssl_pkey_new' ) ) {
|
387 |
+
$res = openssl_pkey_new( $conf );
|
388 |
+
openssl_pkey_export( $res, $privkey );
|
389 |
+
|
390 |
+
$str = openssl_error_string();
|
391 |
+
}
|
392 |
+
return ( stristr( $str, 'NCONF_get_string:no value' ) ? '' : $str );
|
393 |
+
}
|
394 |
+
|
395 |
+
/**
|
396 |
+
* Get current PHP version.
|
397 |
+
*
|
398 |
+
* @return string Current PHP version.
|
399 |
+
*/
|
400 |
+
protected static function get_php_version() {
|
401 |
+
return phpversion();
|
402 |
+
}
|
403 |
+
|
404 |
+
/**
|
405 |
+
* Get max execution time.
|
406 |
+
*
|
407 |
+
* @return string Return the PHP max execution time.
|
408 |
+
*/
|
409 |
+
protected static function get_max_execution_time() {
|
410 |
+
return ini_get( 'max_execution_time' );
|
411 |
+
}
|
412 |
+
|
413 |
+
/**
|
414 |
+
* Get the max uplaod filesize.
|
415 |
+
*
|
416 |
+
* @return string Return the maximum upload filesize.
|
417 |
+
*/
|
418 |
+
protected static function get_upload_max_filesize() {
|
419 |
+
return ini_get( 'upload_max_filesize' );
|
420 |
+
}
|
421 |
+
|
422 |
+
/**
|
423 |
+
* Get the max post size.
|
424 |
+
*
|
425 |
+
* @return string Return the post maximum filesize.
|
426 |
+
*/
|
427 |
+
protected static function get_post_max_size() {
|
428 |
+
return ini_get( 'post_max_size' );
|
429 |
+
}
|
430 |
+
|
431 |
+
/**
|
432 |
+
* Get current MySQL version.
|
433 |
+
*
|
434 |
+
* @return string Return the current MySQL version.
|
435 |
+
*/
|
436 |
+
public static function get_my_sql_version() {
|
437 |
+
|
438 |
+
/**
|
439 |
+
* Object, providing access to the WordPress database.
|
440 |
+
*
|
441 |
+
* @global $wpdb WordPress Database instance.
|
442 |
+
*/
|
443 |
+
global $wpdb;
|
444 |
+
|
445 |
+
return $wpdb->get_var( "SHOW VARIABLES LIKE 'version'", 1 );
|
446 |
+
}
|
447 |
+
|
448 |
+
/**
|
449 |
+
* Get max input time.
|
450 |
+
*
|
451 |
+
* @return string Return current maximum input time.
|
452 |
+
*/
|
453 |
+
protected static function get_max_input_time() {
|
454 |
+
return ini_get( 'max_input_time' );
|
455 |
+
}
|
456 |
+
|
457 |
+
/**
|
458 |
+
* Get current PHP memory limit.
|
459 |
+
*
|
460 |
+
* @return string Return current PHP memory limit.
|
461 |
+
*/
|
462 |
+
public static function get_php_memory_limit() {
|
463 |
+
return ini_get( 'memory_limit' );
|
464 |
+
}
|
465 |
+
|
466 |
+
/**
|
467 |
+
* Get operating system.
|
468 |
+
*/
|
469 |
+
protected static function get_os() {
|
470 |
+
echo esc_html( PHP_OS );
|
471 |
+
}
|
472 |
+
|
473 |
+
/**
|
474 |
+
* Get System architecture.
|
475 |
+
*/
|
476 |
+
protected static function get_architecture() {
|
477 |
+
echo esc_html( PHP_INT_SIZE * 8 ) . ' bit';
|
478 |
+
}
|
479 |
+
|
480 |
+
/**
|
481 |
+
* Get the current Memory usage.
|
482 |
+
*/
|
483 |
+
protected static function memory_usage() {
|
484 |
+
if ( function_exists( 'memory_get_usage' ) ) {
|
485 |
+
$memory_usage = round( memory_get_usage() / 1024 / 1024, 2 ) . ' MB';
|
486 |
+
} else {
|
487 |
+
$memory_usage = __( 'N/A', 'mainwp-child' );
|
488 |
+
}
|
489 |
+
echo esc_html( $memory_usage );
|
490 |
+
}
|
491 |
+
|
492 |
+
/**
|
493 |
+
* Get the current output buffer size.
|
494 |
+
*
|
495 |
+
* @return string Return the current back track limit.
|
496 |
+
*/
|
497 |
+
protected static function get_output_buffer_size() {
|
498 |
+
return ini_get( 'pcre.backtrack_limit' );
|
499 |
+
}
|
500 |
+
|
501 |
+
/**
|
502 |
+
* Check if PHP is in Safe Mode.
|
503 |
+
*/
|
504 |
+
protected static function get_php_safe_mode() {
|
505 |
+
if ( version_compare( phpversion(), '5.3.0' ) < 0 && ini_get( 'safe_mode' ) ) {
|
506 |
+
$safe_mode = __( 'ON', 'mainwp-child' );
|
507 |
+
} else {
|
508 |
+
$safe_mode = __( 'OFF', 'mainwp-child' );
|
509 |
+
}
|
510 |
+
echo esc_html( $safe_mode );
|
511 |
+
}
|
512 |
+
|
513 |
+
/**
|
514 |
+
* Get current SQL mode.
|
515 |
+
*/
|
516 |
+
protected static function get_sql_mode() {
|
517 |
+
|
518 |
+
/**
|
519 |
+
* Object, providing access to the WordPress database.
|
520 |
+
*
|
521 |
+
* @global $wpdb WordPress Database instance.
|
522 |
+
*/
|
523 |
+
global $wpdb;
|
524 |
+
|
525 |
+
$mysqlinfo = $wpdb->get_results( "SHOW VARIABLES LIKE 'sql_mode'" );
|
526 |
+
if ( is_array( $mysqlinfo ) ) {
|
527 |
+
$sql_mode = $mysqlinfo[0]->Value;
|
528 |
+
}
|
529 |
+
if ( empty( $sql_mode ) ) {
|
530 |
+
$sql_mode = __( 'NOT SET', 'mainwp-child' );
|
531 |
+
}
|
532 |
+
echo esc_html( $sql_mode );
|
533 |
+
}
|
534 |
+
|
535 |
+
/**
|
536 |
+
* Check if PHP Allow URL fopen is enabled.
|
537 |
+
*/
|
538 |
+
protected static function get_php_allow_url_fopen() {
|
539 |
+
if ( ini_get( 'allow_url_fopen' ) ) {
|
540 |
+
$allow_url_fopen = __( 'ON', 'mainwp-child' );
|
541 |
+
} else {
|
542 |
+
$allow_url_fopen = __( 'OFF', 'mainwp-child' );
|
543 |
+
}
|
544 |
+
echo esc_html( $allow_url_fopen );
|
545 |
+
}
|
546 |
+
|
547 |
+
/**
|
548 |
+
* Check if PHP exif is enabled.
|
549 |
+
*/
|
550 |
+
protected static function get_php_exif() {
|
551 |
+
if ( is_callable( 'exif_read_data' ) ) {
|
552 |
+
$exif = __( 'YES', 'mainwp-child' ) . ' ( V' . substr( phpversion( 'exif' ), 0, 4 ) . ')';
|
553 |
+
} else {
|
554 |
+
$exif = __( 'NO', 'mainwp-child' );
|
555 |
+
}
|
556 |
+
echo esc_html( $exif );
|
557 |
+
}
|
558 |
+
|
559 |
+
/**
|
560 |
+
* Check if PHP IP TC is enabled.
|
561 |
+
*/
|
562 |
+
protected static function get_php_ip_tc() {
|
563 |
+
if ( is_callable( 'iptcparse' ) ) {
|
564 |
+
$iptc = __( 'YES', 'mainwp-child' );
|
565 |
+
} else {
|
566 |
+
$iptc = __( 'NO', 'mainwp-child' );
|
567 |
+
}
|
568 |
+
echo esc_html( $iptc );
|
569 |
+
}
|
570 |
+
|
571 |
+
/**
|
572 |
+
* Check if PHP XML is enabled.
|
573 |
+
*/
|
574 |
+
protected static function get_php_xml() {
|
575 |
+
if ( is_callable( 'xml_parser_create' ) ) {
|
576 |
+
$xml = __( 'YES', 'mainwp-child' );
|
577 |
+
} else {
|
578 |
+
$xml = __( 'NO', 'mainwp-child' );
|
579 |
+
}
|
580 |
+
echo esc_html( $xml );
|
581 |
+
}
|
582 |
+
|
583 |
+
/**
|
584 |
+
* Get current server gateway interface.
|
585 |
+
*/
|
586 |
+
protected static function get_server_getaway_interface() {
|
587 |
+
echo isset( $_SERVER['GATEWAY_INTERFACE'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['GATEWAY_INTERFACE'] ) ) ) : '';
|
588 |
+
}
|
589 |
+
|
590 |
+
/**
|
591 |
+
* Get server IP.
|
592 |
+
*/
|
593 |
+
protected static function get_server_ip() {
|
594 |
+
echo isset( $_SERVER['SERVER_ADDR'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) ) : '';
|
595 |
+
}
|
596 |
+
|
597 |
+
/**
|
598 |
+
* Get server name.
|
599 |
+
*/
|
600 |
+
protected static function get_server_name() {
|
601 |
+
echo isset( $_SERVER['SERVER_NAME'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) ) : '';
|
602 |
+
}
|
603 |
+
|
604 |
+
/**
|
605 |
+
* Get server software.
|
606 |
+
*/
|
607 |
+
protected static function get_server_software() {
|
608 |
+
echo isset( $_SERVER['SERVER_SOFTWARE'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) ) : '';
|
609 |
+
}
|
610 |
+
|
611 |
+
/**
|
612 |
+
* Get server protocol.
|
613 |
+
*/
|
614 |
+
protected static function get_server_protocol() {
|
615 |
+
echo isset( $_SERVER['SERVER_PROTOCOL'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_PROTOCOL'] ) ) ) : '';
|
616 |
+
}
|
617 |
+
|
618 |
+
/**
|
619 |
+
* Get server request time.
|
620 |
+
*/
|
621 |
+
protected static function get_server_request_time() {
|
622 |
+
echo isset( $_SERVER['REQUEST_TIME'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_TIME'] ) ) ) : '';
|
623 |
+
}
|
624 |
+
|
625 |
+
/**
|
626 |
+
* Get server HTTP accept.
|
627 |
+
*/
|
628 |
+
protected static function get_server_http_accept() {
|
629 |
+
echo isset( $_SERVER['HTTP_ACCEPT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_ACCEPT'] ) ) ) : '';
|
630 |
+
}
|
631 |
+
|
632 |
+
/**
|
633 |
+
* Get server accepted charset.
|
634 |
+
*/
|
635 |
+
protected static function get_server_accept_charset() {
|
636 |
+
echo ! empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) ) : esc_html_e( 'N/A', 'mainwp-child' );
|
637 |
+
}
|
638 |
+
|
639 |
+
/**
|
640 |
+
* Get server HTTP host.
|
641 |
+
*/
|
642 |
+
protected static function get_http_host() {
|
643 |
+
echo ! empty( $_SERVER['HTTP_HOST'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : '';
|
644 |
+
}
|
645 |
+
|
646 |
+
/**
|
647 |
+
* Get server complete URL.
|
648 |
+
*/
|
649 |
+
protected static function get_complete_url() {
|
650 |
+
echo ! empty( $_SERVER['HTTP_REFERER'] ) ? esc_html( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '';
|
651 |
+
}
|
652 |
+
|
653 |
+
/**
|
654 |
+
* Get server user agent.
|
655 |
+
*/
|
656 |
+
protected static function get_user_agent() {
|
657 |
+
echo ! empty( $_SERVER['HTTP_USER_AGENT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) ) : '';
|
658 |
+
}
|
659 |
+
|
660 |
+
/**
|
661 |
+
* Check if HTTPS is on.
|
662 |
+
*/
|
663 |
+
protected static function get_https() {
|
664 |
+
echo ! empty( $_SERVER['HTTPS'] ) ? esc_html( __( 'ON', 'mainwp-child' ) . ' - ' . sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) ) ) : esc_html__( 'OFF', 'mainwp-child' );
|
665 |
+
}
|
666 |
+
|
667 |
+
/**
|
668 |
+
* Server self-connection test.
|
669 |
+
*/
|
670 |
+
protected static function server_self_connect() {
|
671 |
+
$url = site_url( 'wp-cron.php' );
|
672 |
+
$query_args = array( 'mainwp_child_run' => 'test' );
|
673 |
+
$url = add_query_arg( $query_args, $url );
|
674 |
+
$args = array(
|
675 |
+
'blocking' => true,
|
676 |
+
'sslverify' => apply_filters( 'https_local_ssl_verify', true ),
|
677 |
+
'timeout' => 15,
|
678 |
+
);
|
679 |
+
$response = wp_remote_post( $url, $args );
|
680 |
+
$test_result = '';
|
681 |
+
if ( is_wp_error( $response ) ) {
|
682 |
+
$test_result .= sprintf( __( 'The HTTP response test get an error "%s"', 'mainwp-child' ), $response->get_error_message() );
|
683 |
+
}
|
684 |
+
$response_code = wp_remote_retrieve_response_code( $response );
|
685 |
+
if ( $response_code < 200 && $response_code > 204 ) {
|
686 |
+
$test_result .= sprintf( __( 'The HTTP response test get a false http status (%s)', 'mainwp-child' ), wp_remote_retrieve_response_code( $response ) );
|
687 |
+
} else {
|
688 |
+
$response_body = wp_remote_retrieve_body( $response );
|
689 |
+
if ( false === strstr( $response_body, 'MainWP Test' ) ) {
|
690 |
+
$test_result .= sprintf( __( 'Not expected HTTP response body: %s', 'mainwp-child' ), esc_attr( wp_strip_all_tags( $response_body ) ) );
|
691 |
+
}
|
692 |
+
}
|
693 |
+
if ( empty( $test_result ) ) {
|
694 |
+
_e( 'Response Test O.K.', 'mainwp-child' );
|
695 |
+
} else {
|
696 |
+
echo $test_result;
|
697 |
+
}
|
698 |
+
}
|
699 |
+
|
700 |
+
|
701 |
+
/**
|
702 |
+
* Get server remote address.
|
703 |
+
*/
|
704 |
+
protected static function get_remote_address() {
|
705 |
+
echo isset( $_SERVER['REMOTE_ADDR'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) : '';
|
706 |
+
}
|
707 |
+
|
708 |
+
/**
|
709 |
+
* Get server remote host.
|
710 |
+
*/
|
711 |
+
protected static function get_remote_host() {
|
712 |
+
echo ! empty( $_SERVER['REMOTE_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_HOST'] ) ) : esc_html( 'N/A' );
|
713 |
+
}
|
714 |
+
|
715 |
+
/**
|
716 |
+
* Get server remote port.
|
717 |
+
*/
|
718 |
+
protected static function get_remote_port() {
|
719 |
+
echo ! empty( $_SERVER['REMOTE_PORT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_PORT'] ) ) ) : '';
|
720 |
+
}
|
721 |
+
|
722 |
+
/**
|
723 |
+
* Get server script filename.
|
724 |
+
*/
|
725 |
+
protected static function get_script_file_name() {
|
726 |
+
echo ! empty( $_SERVER['SCRIPT_FILENAME'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_FILENAME'] ) ) ) : '';
|
727 |
+
}
|
728 |
+
|
729 |
+
/**
|
730 |
+
* Get server port.
|
731 |
+
*/
|
732 |
+
protected static function get_server_port() {
|
733 |
+
echo ! empty( $_SERVER['SERVER_PORT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_PORT'] ) ) ) : '';
|
734 |
+
}
|
735 |
+
|
736 |
+
/**
|
737 |
+
* Get current page URL.
|
738 |
+
*/
|
739 |
+
protected static function get_current_page_uri() {
|
740 |
+
echo ! empty( $_SERVER['REQUEST_URI'] ) ? esc_html( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
|
741 |
+
}
|
742 |
+
|
743 |
+
/**
|
744 |
+
* Get WordPress root directory.
|
745 |
+
*/
|
746 |
+
protected static function get_wp_root() {
|
747 |
+
echo esc_html( ABSPATH );
|
748 |
+
}
|
749 |
+
|
750 |
+
/**
|
751 |
+
* Time comparison.
|
752 |
+
*
|
753 |
+
* @param string $a Time 1.
|
754 |
+
* @param string $b Time 2.
|
755 |
+
*
|
756 |
+
* @return int Return 0 if $a is equal to $b, -1 if $a > $b or 1 if $a < $b.
|
757 |
+
*/
|
758 |
+
protected static function time_compare( $a, $b ) {
|
759 |
+
if ( $a === $b ) {
|
760 |
+
return 0;
|
761 |
+
}
|
762 |
+
|
763 |
+
return ( strtotime( $a['time'] ) > strtotime( $b['time'] ) ) ? - 1 : 1;
|
764 |
+
}
|
765 |
+
}
|
class/class-mainwp-child-server-information.php
CHANGED
@@ -1,40 +1,94 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
const WARNING = 1;
|
5 |
-
const ERROR
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
public static function init() {
|
8 |
-
add_action(
|
9 |
-
'
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
12 |
}
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
if ( isset( $_POST['what'] ) ) {
|
16 |
$dismissWarnings = get_option( 'mainwp_child_dismiss_warnings' );
|
17 |
if ( ! is_array( $dismissWarnings ) ) {
|
18 |
$dismissWarnings = array();
|
19 |
}
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
}
|
28 |
MainWP_Helper::update_option( 'mainwp_child_dismiss_warnings', $dismissWarnings );
|
29 |
}
|
30 |
}
|
31 |
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
return;
|
35 |
}
|
36 |
|
37 |
-
$warnings
|
38 |
|
39 |
$dismissWarnings = get_option( 'mainwp_child_dismiss_warnings' );
|
40 |
if ( ! is_array( $dismissWarnings ) ) {
|
@@ -66,17 +120,15 @@ class MainWP_Child_Server_Information {
|
|
66 |
var data = {
|
67 |
action: 'mainwp-child_dismiss_warnings',
|
68 |
what: pAction,
|
69 |
-
|
70 |
};
|
71 |
|
72 |
jQuery.ajax( {
|
73 |
type: "POST",
|
74 |
url: ajaxurl,
|
75 |
data: data,
|
76 |
-
success: function ( resp ) {
|
77 |
-
},
|
78 |
-
error: function () {
|
79 |
-
},
|
80 |
dataType: 'json'
|
81 |
} );
|
82 |
|
@@ -101,7 +153,7 @@ class MainWP_Child_Server_Information {
|
|
101 |
border-radius: 3px;
|
102 |
margin: 1em 0 !important;
|
103 |
|
104 |
-
background-image: url('<?php echo esc_url( plugins_url( 'images/mainwp-icon-orange.png', dirname( __FILE__ ) ) ); ?>') !important;
|
105 |
background-position: 1.5em 50% !important;
|
106 |
background-repeat: no-repeat !important;
|
107 |
background-size: 30px !important;
|
@@ -122,9 +174,8 @@ class MainWP_Child_Server_Information {
|
|
122 |
<tbody id="the-sites-list" class="list:sites">
|
123 |
<?php
|
124 |
$warning = '';
|
125 |
-
|
126 |
if ( $warnings > 0 ) {
|
127 |
-
$warning .= '<tr><td colspan="2">This site may not connect to your dashboard or may have other issues. Check your <a href="options-general.php?page=mainwp_child_tab">MainWP server information page</a
|
128 |
}
|
129 |
echo $warning;
|
130 |
?>
|
@@ -134,7 +185,12 @@ class MainWP_Child_Server_Information {
|
|
134 |
<?php
|
135 |
}
|
136 |
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
138 |
?>
|
139 |
<script language="javascript">
|
140 |
|
@@ -144,22 +200,19 @@ class MainWP_Child_Server_Information {
|
|
144 |
*
|
145 |
* By Eli Grey, http://eligrey.com
|
146 |
* License: X11/MIT
|
147 |
-
*
|
148 |
*/
|
149 |
|
150 |
/*global self */
|
151 |
-
/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true,
|
152 |
-
plusplus: true */
|
153 |
|
154 |
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
|
155 |
|
156 |
var childSaveAs = childSaveAs
|
157 |
-
|| (navigator.msSaveBlob && navigator.msSaveBlob.bind(navigator))
|
158 |
-
|| (function(view) {
|
159 |
"use strict";
|
160 |
-
var
|
161 |
-
doc = view.document
|
162 |
-
// only get URL when necessary in case BlobBuilder.js hasn't overridden it yet
|
163 |
, get_URL = function() {
|
164 |
return view.URL || view.webkitURL || view;
|
165 |
}
|
@@ -188,13 +241,13 @@ class MainWP_Child_Server_Information {
|
|
188 |
var i = deletion_queue.length;
|
189 |
while (i--) {
|
190 |
var file = deletion_queue[i];
|
191 |
-
if (typeof file === "string") {
|
192 |
URL.revokeObjectURL(file);
|
193 |
-
} else {
|
194 |
file.remove();
|
195 |
}
|
196 |
}
|
197 |
-
deletion_queue.length = 0;
|
198 |
}
|
199 |
, dispatch = function(filesaver, event_types, event) {
|
200 |
event_types = [].concat(event_types);
|
@@ -210,8 +263,7 @@ class MainWP_Child_Server_Information {
|
|
210 |
}
|
211 |
}
|
212 |
}
|
213 |
-
, FileSaver = function(blob, name) {
|
214 |
-
// First try a.download, then web filesystem, then object URLs
|
215 |
var
|
216 |
filesaver = this
|
217 |
, type = blob.type
|
@@ -224,13 +276,11 @@ class MainWP_Child_Server_Information {
|
|
224 |
return object_url;
|
225 |
}
|
226 |
, dispatch_all = function() {
|
227 |
-
dispatch(filesaver, "writestart progress write writeend".split(" "));
|
228 |
}
|
229 |
-
// on any filesys errors revert to saving with object URLs
|
230 |
, fs_error = function() {
|
231 |
-
|
232 |
-
|
233 |
-
object_url = get_object_url(blob);
|
234 |
}
|
235 |
if (target_view) {
|
236 |
target_view.location.href = object_url;
|
@@ -249,34 +299,28 @@ class MainWP_Child_Server_Information {
|
|
249 |
, slice
|
250 |
;
|
251 |
filesaver.readyState = filesaver.INIT;
|
252 |
-
if (!name) {
|
253 |
name = "download";
|
254 |
}
|
255 |
-
if (can_use_save_link) {
|
256 |
-
object_url = get_object_url(blob);
|
257 |
save_link.href = object_url;
|
258 |
save_link.download = name;
|
259 |
-
if (click(save_link)) {
|
260 |
filesaver.readyState = filesaver.DONE;
|
261 |
dispatch_all();
|
262 |
return;
|
263 |
}
|
264 |
}
|
265 |
-
|
266 |
-
// viewed in a tab, so I force save with application/octet-stream
|
267 |
-
// http://code.google.com/p/chromium/issues/detail?id=91158
|
268 |
-
if (view.chrome && type && type !== force_saveable_type) {
|
269 |
slice = blob.slice || blob.webkitSlice;
|
270 |
-
blob = slice.call(blob, 0, blob.size, force_saveable_type);
|
271 |
blob_changed = true;
|
272 |
}
|
273 |
-
// Since I can't be sure that the guessed media type will trigger a download
|
274 |
-
// in WebKit, I append .download to the filename.
|
275 |
-
// https://bugs.webkit.org/show_bug.cgi?id=65440
|
276 |
if (webkit_req_fs && name !== "download") {
|
277 |
name += ".download";
|
278 |
}
|
279 |
-
if (type === force_saveable_type || webkit_req_fs) {
|
280 |
target_view = view;
|
281 |
} else {
|
282 |
target_view = view.open();
|
@@ -316,7 +360,6 @@ class MainWP_Child_Server_Information {
|
|
316 |
}), fs_error);
|
317 |
};
|
318 |
dir.getFile(name, {create: false}, abortable(function(file) {
|
319 |
-
// delete file if it already exists
|
320 |
file.remove();
|
321 |
save();
|
322 |
}), abortable(function(ex) {
|
@@ -361,8 +404,7 @@ class MainWP_Child_Server_Information {
|
|
361 |
var o = i.toString();
|
362 |
if (!s) { s = '0'; }
|
363 |
while (o.length < parseInt(l)) {
|
364 |
-
|
365 |
-
if(w == 'undefined'){
|
366 |
o = s + o;
|
367 |
}else{
|
368 |
o = o + s;
|
@@ -370,66 +412,77 @@ class MainWP_Child_Server_Information {
|
|
370 |
}
|
371 |
return o;
|
372 |
};
|
373 |
-
jQuery( document ).on( 'click', '.mwp-child-get-system-report-btn', function(){
|
374 |
var report = "";
|
375 |
-
jQuery('.mwp_server_info_box thead, .mwp_server_info_box tbody').each(function(){
|
376 |
var td_len = [35, 55, 45, 12, 12];
|
377 |
var th_count = 0;
|
378 |
var i;
|
379 |
-
if ( jQuery( this ).is('thead') ) {
|
380 |
i = 0;
|
381 |
report = report + "\n### ";
|
382 |
-
th_count = jQuery( this ).find('th:not(".mwp-not-generate-row")').length;
|
383 |
-
jQuery( this ).find('th:not(".mwp-not-generate-row")').each(function(){
|
384 |
var len = td_len[i];
|
385 |
-
if (i == 0 || i == th_count -1)
|
386 |
len = len - 4;
|
387 |
-
|
388 |
i++;
|
389 |
-
});
|
390 |
report = report + " ###\n\n";
|
391 |
} else {
|
392 |
-
jQuery('tr', jQuery( this )).each(function(){
|
393 |
-
if (jQuery( this ).hasClass('mwp-not-generate-row'))
|
394 |
return;
|
395 |
i = 0;
|
396 |
-
jQuery( this ).find('td:not(".mwp-not-generate-row")').each(function(){
|
397 |
-
if (jQuery( this ).hasClass('mwp-hide-generate-row')) {
|
398 |
-
report = report + mwp_child_strCut(' ', td_len[i], ' ' );
|
399 |
i++;
|
400 |
return;
|
401 |
}
|
402 |
-
report = report + mwp_child_strCut(jQuery.trim( jQuery( this ).text()), td_len[i], ' ' );
|
403 |
i++;
|
404 |
-
});
|
405 |
report = report + "\n";
|
406 |
-
});
|
407 |
-
|
408 |
}
|
409 |
} );
|
410 |
-
|
411 |
try {
|
412 |
-
jQuery("#mwp-server-information").slideDown();
|
413 |
-
jQuery("#mwp-server-information textarea").val( report ).focus().select();
|
414 |
-
jQuery(this).fadeOut();
|
415 |
-
jQuery('.mwp_child_close_srv_info').show();
|
416 |
return false;
|
417 |
} catch(e){ }
|
418 |
-
});
|
419 |
|
420 |
-
jQuery( document ).on( 'click', 'a#mwp_child_close_srv_info', function(){
|
421 |
-
jQuery('#mwp-server-information').hide();
|
422 |
-
jQuery('.mwp_child_close_srv_info').hide();
|
423 |
-
jQuery('a.mwp-child-get-system-report-btn').show();
|
424 |
return false;
|
425 |
-
});
|
426 |
-
jQuery( document ).on( 'click', '#mwp_child_download_srv_info', function
|
427 |
-
var server_info = jQuery('#mwp-server-information textarea').val();
|
428 |
-
var blob = new Blob([server_info], {type: "text/plain;charset=utf-8"});
|
429 |
-
childSaveAs(blob, "server_child_information.txt");
|
430 |
-
});
|
431 |
-
|
432 |
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
433 |
<style type="text/css">
|
434 |
#mwp-server-information {
|
435 |
display: none;
|
@@ -461,74 +514,131 @@ class MainWP_Child_Server_Information {
|
|
461 |
</style>
|
462 |
<div class="wrap">
|
463 |
<div class="updated below-h2">
|
464 |
-
<p><?php
|
465 |
-
<span class="mwp_child_close_srv_info"
|
466 |
-
|
467 |
-
|
468 |
<p class="submit">
|
469 |
-
<a class="button-primary mwp-child-get-system-report-btn" href="#"><?php
|
470 |
</p>
|
471 |
-
|
472 |
<div id="mwp-server-information"><textarea readonly="readonly" wrap="off"></textarea></div>
|
473 |
</div>
|
474 |
<br/>
|
475 |
<div class="mwp_server_info_box">
|
476 |
-
<h2><?php esc_html_e( 'Server Information' ); ?></h2
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
?>
|
483 |
</div>
|
484 |
</div>
|
485 |
<?php
|
486 |
}
|
487 |
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
$i ++;
|
505 |
-
}
|
506 |
-
if ( ! self::check( '>=', '2M', 'getPostMaxSize', null, null, true ) ) {
|
507 |
-
$i ++;
|
508 |
-
}
|
509 |
-
if ( ! self::check( '>=', '10000', 'getOutputBufferSize' ) ) {
|
510 |
-
$i ++;
|
511 |
-
}
|
512 |
-
// if (!self::check('=', true, 'getSSLSupport')) $i++;
|
513 |
-
|
514 |
-
if ( ! self::checkDirectoryMainWPDirectory( false ) ) {
|
515 |
-
$i ++;
|
516 |
}
|
517 |
-
|
518 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
519 |
}
|
520 |
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
528 |
}
|
529 |
|
530 |
-
|
531 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
532 |
if ( 'direct' === $fsmethod ) {
|
533 |
echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>';
|
534 |
} else {
|
@@ -536,382 +646,349 @@ class MainWP_Child_Server_Information {
|
|
536 |
}
|
537 |
}
|
538 |
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
545 |
}
|
|
|
546 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
547 |
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
548 |
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
$server = get_option( 'mainwp_child_server' );
|
577 |
-
?>
|
578 |
-
<tr>
|
579 |
-
<td></td>
|
580 |
-
<td><?php _e( 'Currently connected to dashboard URL', 'mainwp-child' ); ?></td>
|
581 |
-
<td><?php echo esc_html( $server ); ?></td>
|
582 |
-
<td></td>
|
583 |
-
<td></td>
|
584 |
-
</tr>
|
585 |
-
<tr>
|
586 |
-
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'WORDPRESS', 'mainwp-child' ); ?></td>
|
587 |
-
</tr><?php
|
588 |
-
self::renderRow( 'WordPress Version', '>=', '3.4', 'getWordpressVersion' );
|
589 |
-
self::renderRow( 'WordPress Memory Limit', '>=', '64M', 'getWordpressMemoryLimit' );
|
590 |
-
self::renderRow( 'MultiSite Disabled', '=', true, 'checkIfMultisite' );
|
591 |
-
?>
|
592 |
-
<tr>
|
593 |
-
<td></td>
|
594 |
-
<td><?php esc_html_e( 'FileSystem Method', 'mainwp-child' ); ?></td>
|
595 |
-
<td><?php echo esc_html( '= direct' ); ?></td>
|
596 |
-
<td><?php echo esc_html( self::getFileSystemMethod() ); ?></td>
|
597 |
-
<td><?php echo esc_html( self::getFileSystemMethodCheck() ); ?></td>
|
598 |
-
</tr>
|
599 |
-
<tr>
|
600 |
-
<td style="background: #333; color: #fff;"
|
601 |
-
colspan="5"><?php esc_html_e( 'PHP SETTINGS', 'mainwp-child' ); ?></td>
|
602 |
-
</tr><?php
|
603 |
-
self::renderRow( 'PHP Version', '>=', '5.6', 'getPHPVersion' );
|
604 |
-
?>
|
605 |
-
<tr>
|
606 |
-
<td></td>
|
607 |
-
<td><?php esc_html_e( 'PHP Safe Mode Disabled', 'mainwp-child' ); ?></td>
|
608 |
-
<td colspan="3"><?php self::getPHPSafeMode(); ?></td>
|
609 |
-
</tr>
|
610 |
-
<?php
|
611 |
-
self::renderRowSec( 'PHP Max Execution Time', '>=', '30', 'getMaxExecutionTime', 'seconds', '=', '0' );
|
612 |
-
self::renderRowSec( 'PHP Max Input Time', '>=', '30', 'getMaxInputTime', 'seconds', '=', '0' );
|
613 |
-
self::renderRow( 'PHP Memory Limit', '>=', '128M', 'getPHPMemoryLimit', '(256M+ best for big backups)', null, null, true );
|
614 |
-
self::renderRow( 'PCRE Backtracking Limit', '>=', '10000', 'getOutputBufferSize' );
|
615 |
-
self::renderRow( 'PHP Upload Max Filesize', '>=', '2M', 'getUploadMaxFilesize', '(2MB+ best for upload of big plugins)', null, null, true );
|
616 |
-
self::renderRow( 'PHP Post Max Size', '>=', '2M', 'getPostMaxSize', '(2MB+ best for upload of big plugins)', null, null, true );
|
617 |
-
self::renderRow( 'SSL Extension Enabled', '=', true, 'getSSLSupport' );
|
618 |
-
self::renderRowSec( 'SSL Warnings', '=', '', 'getSSLWarning', 'empty', '' );
|
619 |
-
self::renderRowSec( 'cURL Extension Enabled', '=', true, 'getCurlSupport', '', '', null, '', null, self::ERROR );
|
620 |
-
self::renderRowSec( 'cURL Timeout', '>=', '300', 'getCurlTimeout', 'seconds', '=', '0' );
|
621 |
-
if ( function_exists( 'curl_version' ) ) {
|
622 |
-
self::renderRowSec( 'cURL Version', '>=', '7.18.1', 'getCurlVersion', '', '', null );
|
623 |
-
self::renderRowSec( 'cURL SSL Version', '>=', array(
|
624 |
-
'version_number' => 0x009080cf,
|
625 |
-
'version' => 'OpenSSL/0.9.8l',
|
626 |
-
), 'getCurlSSLVersion', '', '', null, '', 'curlssl' );
|
627 |
}
|
628 |
?>
|
629 |
-
<tr>
|
630 |
-
<td style="background: #333; color: #fff;"
|
631 |
-
colspan="5"><?php esc_html_e( 'MySQL SETTINGS', 'mainwp-child' ); ?></td>
|
632 |
-
</tr><?php
|
633 |
-
self::renderRow( 'MySQL Version', '>=', '5.0', 'getMySQLVersion' );
|
634 |
-
?>
|
635 |
-
<tr>
|
636 |
-
<td style="background: #333; color: #fff;"
|
637 |
-
colspan="5"><?php esc_html_e( 'BACKUP ARCHIVE INFORMATION', 'mainwp-child' ); ?></td>
|
638 |
-
</tr><?php
|
639 |
-
self::renderRow( 'ZipArchive enabled in PHP', '=', true, 'getZipArchiveEnabled' );
|
640 |
-
self::renderRow( 'Tar GZip supported', '=', true, 'getGZipEnabled' );
|
641 |
-
self::renderRow( 'Tar BZip2 supported', '=', true, 'getBZipEnabled' );
|
642 |
-
?>
|
643 |
-
|
644 |
-
<tr>
|
645 |
-
<td style="background: #333; color: #fff;"
|
646 |
-
colspan="5"><?php esc_html_e( 'SERVER INFORMATION', 'mainwp-child' ); ?></td>
|
647 |
-
</tr>
|
648 |
-
<tr>
|
649 |
-
<td></td>
|
650 |
-
<td><?php esc_html_e( 'WordPress Root Directory', 'mainwp-child' ); ?></td>
|
651 |
-
<td colspan="3"><?php self::getWPRoot(); ?></td>
|
652 |
-
</tr>
|
653 |
-
<tr>
|
654 |
-
<td></td>
|
655 |
-
<td><?php esc_html_e( 'Server Name', 'mainwp-child' ); ?></td>
|
656 |
-
<td colspan="3"><?php self::getServerName(); ?></td>
|
657 |
-
</tr>
|
658 |
-
<tr>
|
659 |
-
<td></td>
|
660 |
-
<td><?php esc_html_e( 'Server Software', 'mainwp-child' ); ?></td>
|
661 |
-
<td colspan="3"><?php self::getServerSoftware(); ?></td>
|
662 |
-
</tr>
|
663 |
-
<tr>
|
664 |
-
<td></td>
|
665 |
-
<td><?php esc_html_e( 'Operating System', 'mainwp-child' ); ?></td>
|
666 |
-
<td colspan="3"><?php self::getOS(); ?></td>
|
667 |
-
</tr>
|
668 |
-
<tr>
|
669 |
-
<td></td>
|
670 |
-
<td><?php esc_html_e( 'Architecture', 'mainwp-child' ); ?></td>
|
671 |
-
<td colspan="3"><?php self::getArchitecture(); ?></td>
|
672 |
-
</tr>
|
673 |
-
<tr>
|
674 |
-
<td></td>
|
675 |
-
<td><?php esc_html_e( 'Server IP', 'mainwp-child' ); ?></td>
|
676 |
-
<td colspan="3"><?php self::getServerIP(); ?></td>
|
677 |
-
</tr>
|
678 |
-
<tr>
|
679 |
-
<td></td>
|
680 |
-
<td><?php esc_html_e( 'Server Protocol', 'mainwp-child' ); ?></td>
|
681 |
-
<td colspan="3"><?php self::getServerProtocol(); ?></td>
|
682 |
-
</tr>
|
683 |
-
<tr>
|
684 |
-
<td></td>
|
685 |
-
<td><?php esc_html_e( 'HTTP Host', 'mainwp-child' ); ?></td>
|
686 |
-
<td colspan="3"><?php self::getHTTPHost(); ?></td>
|
687 |
-
</tr>
|
688 |
-
<tr>
|
689 |
-
<td></td>
|
690 |
-
<td><?php esc_html_e( 'HTTPS', 'mainwp-child' ); ?></td>
|
691 |
-
<td colspan="3"><?php self::getHTTPS(); ?></td>
|
692 |
-
</tr>
|
693 |
-
<tr>
|
694 |
-
<td></td>
|
695 |
-
<td><?php esc_html_e( 'Server self connect', 'mainwp-child' ); ?></td>
|
696 |
-
<td colspan="3"><?php self::serverSelfConnect(); ?></td>
|
697 |
-
</tr>
|
698 |
-
<tr>
|
699 |
-
<td></td>
|
700 |
-
<td><?php esc_html_e( 'User Agent', 'mainwp-child' ); ?></td>
|
701 |
-
<td colspan="3"><?php self::getUserAgent(); ?></td>
|
702 |
-
</tr>
|
703 |
-
<tr>
|
704 |
-
<td></td>
|
705 |
-
<td><?php esc_html_e( 'Server Port', 'mainwp-child' ); ?></td>
|
706 |
-
<td colspan="3"><?php self::getServerPort(); ?></td>
|
707 |
-
</tr>
|
708 |
-
<tr>
|
709 |
-
<td></td>
|
710 |
-
<td><?php esc_html_e( 'Gateway Interface', 'mainwp-child' ); ?></td>
|
711 |
-
<td colspan="3"><?php self::getServerGetawayInterface(); ?></td>
|
712 |
-
</tr>
|
713 |
-
<tr>
|
714 |
-
<td></td>
|
715 |
-
<td><?php esc_html_e( 'Memory Usage', 'mainwp-child' ); ?></td>
|
716 |
-
<td colspan="3"><?php self::memoryUsage(); ?></td>
|
717 |
-
</tr>
|
718 |
-
<tr>
|
719 |
-
<td></td>
|
720 |
-
<td><?php esc_html_e( 'Complete URL', 'mainwp-child' ); ?></td>
|
721 |
-
<td colspan="3"><?php self::getCompleteURL(); ?></td>
|
722 |
-
</tr>
|
723 |
-
<tr>
|
724 |
-
<td></td>
|
725 |
-
<td><?php esc_html_e( 'Request Time', 'mainwp-child' ); ?></td>
|
726 |
-
<td colspan="3"><?php self::getServerRequestTime(); ?></td>
|
727 |
-
</tr>
|
728 |
-
<tr>
|
729 |
-
<td></td>
|
730 |
-
<td><?php esc_html_e( 'Accept Content', 'mainwp-child' ); ?></td>
|
731 |
-
<td colspan="3"><?php self::getServerHTTPAccept(); ?></td>
|
732 |
-
</tr>
|
733 |
-
<tr>
|
734 |
-
<td></td>
|
735 |
-
<td><?php esc_html_e( 'Accept-Charset Content', 'mainwp-child' ); ?></td>
|
736 |
-
<td colspan="3"><?php self::getServerAcceptCharset(); ?></td>
|
737 |
-
</tr>
|
738 |
-
<tr>
|
739 |
-
<td></td>
|
740 |
-
<td><?php esc_html_e( 'Currently Executing Script Pathname', 'mainwp-child' ); ?></td>
|
741 |
-
<td colspan="3"><?php self::getScriptFileName(); ?></td>
|
742 |
-
</tr>
|
743 |
-
<tr>
|
744 |
-
<td></td>
|
745 |
-
<td><?php esc_html_e( 'Current Page URI', 'mainwp-child' ); ?></td>
|
746 |
-
<td colspan="3"><?php self::getCurrentPageURI(); ?></td>
|
747 |
-
</tr>
|
748 |
-
<tr>
|
749 |
-
<td></td>
|
750 |
-
<td><?php esc_html_e( 'Remote Address', 'mainwp-child' ); ?></td>
|
751 |
-
<td colspan="3"><?php self::getRemoteAddress(); ?></td>
|
752 |
-
</tr>
|
753 |
-
<tr>
|
754 |
-
<td></td>
|
755 |
-
<td><?php esc_html_e( 'Remote Host', 'mainwp-child' ); ?></td>
|
756 |
-
<td colspan="3"><?php self::getRemoteHost(); ?></td>
|
757 |
-
</tr>
|
758 |
-
<tr>
|
759 |
-
<td></td>
|
760 |
-
<td><?php esc_html_e( 'Remote Port', 'mainwp-child' ); ?></td>
|
761 |
-
<td colspan="3"><?php self::getRemotePort(); ?></td>
|
762 |
-
</tr>
|
763 |
-
<tr>
|
764 |
-
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'PHP INFORMATION', 'mainwp-child' ); ?></td>
|
765 |
-
</tr>
|
766 |
-
<tr>
|
767 |
-
<td></td>
|
768 |
-
<td><?php esc_html_e( 'PHP Allow URL fopen', 'mainwp-child' ); ?></td>
|
769 |
-
<td colspan="3"><?php self::getPHPAllowUrlFopen(); ?></td>
|
770 |
-
</tr>
|
771 |
-
<tr>
|
772 |
-
<td></td>
|
773 |
-
<td><?php esc_html_e( 'PHP Exif Support', 'mainwp-child' ); ?></td>
|
774 |
-
<td colspan="3"><?php self::getPHPExif(); ?></td>
|
775 |
-
</tr>
|
776 |
-
<tr>
|
777 |
-
<td></td>
|
778 |
-
<td><?php esc_html_e( 'PHP IPTC Support', 'mainwp-child' ); ?></td>
|
779 |
-
<td colspan="3"><?php self::getPHPIPTC(); ?></td>
|
780 |
-
</tr>
|
781 |
-
<tr>
|
782 |
-
<td></td>
|
783 |
-
<td><?php esc_html_e( 'PHP XML Support', 'mainwp-child' ); ?></td>
|
784 |
-
<td colspan="3"><?php self::getPHPXML(); ?></td>
|
785 |
-
</tr>
|
786 |
-
<tr>
|
787 |
-
<td></td>
|
788 |
-
<td><?php esc_html_e( 'PHP Disabled Functions', 'mainwp-child' ); ?></td>
|
789 |
-
<td colspan="3"><?php self::mainwpRequiredFunctions(); ?></td>
|
790 |
-
</tr>
|
791 |
-
<tr>
|
792 |
-
<td></td>
|
793 |
-
<td><?php esc_html_e( 'PHP Loaded Extensions', 'mainwp-child' ); ?></td>
|
794 |
-
<td colspan="3" style="width: 73% !important;"><?php self::getLoadedPHPExtensions(); ?></td>
|
795 |
-
</tr>
|
796 |
-
<tr>
|
797 |
-
<td style="background: #333; color: #fff;"
|
798 |
-
colspan="5"><?php esc_html_e( 'MySQL INFORMATION', 'mainwp-child' ); ?></td>
|
799 |
-
</tr>
|
800 |
<tr>
|
801 |
<td></td>
|
802 |
-
<td><?php
|
803 |
-
<td
|
804 |
-
|
805 |
-
<tr>
|
806 |
<td></td>
|
807 |
-
<td><?php esc_html_e( 'MySQL Client Encoding', 'mainwp-child' ); ?></td>
|
808 |
-
<td colspan="3"><?php echo esc_html( defined( 'DB_CHARSET' ) ? DB_CHARSET : '' ); ?></td>
|
809 |
-
</tr>
|
810 |
-
<tr>
|
811 |
-
<td style="background: #333; color: #fff;" colspan="5"><?php _e( 'WORDPRESS PLUGINS', 'mainwp-child' ); ?></td>
|
812 |
</tr>
|
813 |
<?php
|
814 |
-
|
815 |
-
|
816 |
-
if ( $slug == 'mainwp-child/mainwp-child.php' || $slug == 'mainwp-child-reports/mainwp-child-reports.php' ) {
|
817 |
-
if ( $isBranding ) {
|
818 |
-
if ( $slug == 'mainwp-child/mainwp-child.php' ) {
|
819 |
-
$plugin['Name'] = esc_html( stripslashes( $branding_title ) );
|
820 |
-
} else if ($slug == 'mainwp-child-reports/mainwp-child-reports.php') {
|
821 |
-
$plugin['Name'] = esc_html( stripslashes( $branding_title ) ) . ' reports';
|
822 |
-
}
|
823 |
-
}
|
824 |
-
}
|
825 |
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
840 |
<?php
|
841 |
}
|
842 |
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
910 |
}
|
911 |
|
912 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
913 |
$current = get_option( 'mainwp_child_plugin_version' );
|
914 |
-
$latest = self::
|
915 |
if ( $current === $latest ) {
|
916 |
echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>';
|
917 |
} else {
|
@@ -919,20 +996,30 @@ class MainWP_Child_Server_Information {
|
|
919 |
}
|
920 |
}
|
921 |
|
922 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
923 |
$cron_array = _get_cron_array();
|
924 |
$schedules = wp_get_schedules();
|
925 |
?>
|
926 |
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0">
|
927 |
<thead>
|
928 |
-
|
929 |
-
|
930 |
-
<span><?php esc_html_e( '
|
931 |
-
|
932 |
-
|
933 |
-
<th scope="col" class="manage-column column-posts" style="">
|
934 |
-
<span><?php esc_html_e( 'Hook', 'mainwp-child' ); ?></span></th>
|
935 |
-
</tr>
|
936 |
</thead>
|
937 |
<tbody id="the-sites-list" class="list:sites">
|
938 |
<?php
|
@@ -941,7 +1028,7 @@ class MainWP_Child_Server_Information {
|
|
941 |
foreach ( $cron_info as $key => $schedule ) {
|
942 |
?>
|
943 |
<tr>
|
944 |
-
<td><?php echo esc_html( MainWP_Helper::
|
945 |
<td><?php echo esc_html( ( isset( $schedule['schedule'] ) && isset( $schedules[ $schedule['schedule'] ] ) && isset( $schedules[ $schedule['schedule'] ]['display'] ) ) ? $schedules[ $schedule['schedule'] ]['display'] : '' ); ?> </td>
|
946 |
<td><?php echo esc_html( $hook ); ?></td>
|
947 |
</tr>
|
@@ -955,497 +1042,180 @@ class MainWP_Child_Server_Information {
|
|
955 |
<?php
|
956 |
}
|
957 |
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
}
|
971 |
-
|
972 |
-
if ( ! is_dir( dirname( $path ) ) ) {
|
973 |
-
if ( $write ) {
|
974 |
-
return self::renderDirectoryRow( $branding_title, $path, 'Writable', 'Directory not found', false );
|
975 |
-
} else {
|
976 |
-
return false;
|
977 |
-
}
|
978 |
}
|
|
|
979 |
|
980 |
-
$
|
981 |
-
|
982 |
|
983 |
-
|
984 |
-
if ( ! $wp_filesystem->is_writable( $path ) ) {
|
985 |
-
if ( $write ) {
|
986 |
-
return self::renderDirectoryRow( $branding_title, $path, 'Writable', 'Directory not writable', false );
|
987 |
-
} else {
|
988 |
-
return false;
|
989 |
-
}
|
990 |
-
}
|
991 |
-
} else {
|
992 |
-
if ( ! is_writable( $path ) ) {
|
993 |
-
if ( $write ) {
|
994 |
-
return self::renderDirectoryRow( $branding_title, $path, 'Writable', 'Directory not writable', false );
|
995 |
-
} else {
|
996 |
-
return false;
|
997 |
-
}
|
998 |
-
}
|
999 |
-
}
|
1000 |
|
1001 |
-
|
1002 |
-
return self::renderDirectoryRow( $branding_title, $path, 'Writable', 'Writable', true );
|
1003 |
-
} else {
|
1004 |
-
return true;
|
1005 |
-
}
|
1006 |
}
|
1007 |
|
1008 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1009 |
?>
|
1010 |
<tr class="mwp-not-generate-row">
|
1011 |
<td></td>
|
1012 |
-
<td><?php echo esc_html( stripslashes( $
|
1013 |
-
|
1014 |
-
<td><?php echo esc_html( $
|
1015 |
-
<td><?php echo
|
1016 |
-
<td><?php echo ( $pPassed ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>' ); ?></td>
|
1017 |
</tr>
|
1018 |
<?php
|
1019 |
-
return true;
|
1020 |
}
|
1021 |
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1025 |
?>
|
1026 |
<tr>
|
1027 |
<td></td>
|
1028 |
-
<td><?php echo esc_html( esc_html( $
|
1029 |
-
<td><?php echo esc_html( esc_html( $
|
1030 |
<td><?php echo esc_html( true === $currentVersion ? 'true' : $currentVersion ); ?></td>
|
1031 |
-
<td><?php echo ( self::check( $
|
1032 |
</tr>
|
1033 |
<?php
|
1034 |
}
|
1035 |
|
1036 |
-
|
1037 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1038 |
?>
|
1039 |
<tr>
|
1040 |
<td></td>
|
1041 |
-
<td><?php echo $
|
1042 |
-
<td><?php echo $
|
1043 |
-
<td><?php echo(
|
1044 |
-
<?php if (
|
1045 |
-
<td><?php echo( self::filesize_compare( $currentVersion, $
|
1046 |
-
<?php }
|
1047 |
-
<td><?php echo( self::curlssl_compare( $
|
1048 |
-
<?php }
|
1049 |
<td><?php echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>'; ?></td>
|
1050 |
<?php } else { ?>
|
1051 |
-
<td><?php echo (version_compare($currentVersion, $
|
1052 |
<?php } ?>
|
1053 |
</tr>
|
1054 |
<?php
|
1055 |
}
|
1056 |
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1060 |
return '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>';
|
1061 |
}
|
1062 |
return '<span class="mainwp-fail"><i class="fa fa-exclamation-circle"></i> Fail</span>';
|
1063 |
}
|
1064 |
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
$currentVersion = call_user_func( array( 'MainWP_Child_Server_Information', $pGetter ) );
|
1085 |
-
|
1086 |
-
if ($sizeCompare) {
|
1087 |
-
return self::filesize_compare( $currentVersion, $pVersion, $pCompare );
|
1088 |
-
} else {
|
1089 |
-
return ( version_compare( $currentVersion, $pVersion, $pCompare ) || ( ( null !== $pExtraCompare ) && version_compare( $currentVersion, $pExtraVersion, $pExtraCompare ) ) );
|
1090 |
-
}
|
1091 |
-
}
|
1092 |
-
|
1093 |
-
protected static function getZipArchiveEnabled() {
|
1094 |
-
return class_exists( 'ZipArchive' );
|
1095 |
-
}
|
1096 |
-
|
1097 |
-
protected static function getGZipEnabled() {
|
1098 |
-
return function_exists( 'gzopen' );
|
1099 |
-
}
|
1100 |
-
|
1101 |
-
protected static function getBZipEnabled() {
|
1102 |
-
return function_exists( 'bzopen' );
|
1103 |
-
}
|
1104 |
-
|
1105 |
-
protected static function getWordpressVersion() {
|
1106 |
-
global $wp_version;
|
1107 |
-
|
1108 |
-
return $wp_version;
|
1109 |
-
}
|
1110 |
-
|
1111 |
-
protected static function getWordpressMemoryLimit() {
|
1112 |
-
return WP_MEMORY_LIMIT;
|
1113 |
-
}
|
1114 |
-
|
1115 |
-
public static function checkIfMultisite() {
|
1116 |
-
$isMultisite = ! is_multisite() ? true : false;
|
1117 |
-
|
1118 |
-
return $isMultisite;
|
1119 |
-
}
|
1120 |
-
|
1121 |
-
protected static function getSSLSupport() {
|
1122 |
-
return extension_loaded( 'openssl' );
|
1123 |
-
}
|
1124 |
-
|
1125 |
-
protected static function getSSLWarning() {
|
1126 |
-
$conf = array( 'private_key_bits' => 2048 );
|
1127 |
-
$str = '';
|
1128 |
-
if ( function_exists( 'openssl_pkey_new' ) ) {
|
1129 |
-
$res = @openssl_pkey_new( $conf );
|
1130 |
-
@openssl_pkey_export( $res, $privkey );
|
1131 |
-
|
1132 |
-
$str = openssl_error_string();
|
1133 |
-
}
|
1134 |
-
return ( stristr( $str, 'NCONF_get_string:no value' ) ? '' : $str );
|
1135 |
-
}
|
1136 |
-
|
1137 |
-
public static function getPHPVersion() {
|
1138 |
-
return phpversion();
|
1139 |
-
}
|
1140 |
-
|
1141 |
-
protected static function getMaxExecutionTime() {
|
1142 |
-
return ini_get( 'max_execution_time' );
|
1143 |
-
}
|
1144 |
-
|
1145 |
-
protected static function getUploadMaxFilesize() {
|
1146 |
-
return ini_get( 'upload_max_filesize' );
|
1147 |
-
}
|
1148 |
-
|
1149 |
-
protected static function getPostMaxSize() {
|
1150 |
-
return ini_get( 'post_max_size' );
|
1151 |
-
}
|
1152 |
-
|
1153 |
-
public static function getMySQLVersion() {
|
1154 |
-
/** @var $wpdb wpdb */
|
1155 |
-
global $wpdb;
|
1156 |
-
|
1157 |
-
return $wpdb->get_var( "SHOW VARIABLES LIKE 'version'", 1 );
|
1158 |
-
}
|
1159 |
-
|
1160 |
-
protected static function getMaxInputTime() {
|
1161 |
-
return ini_get( 'max_input_time' );
|
1162 |
-
}
|
1163 |
-
|
1164 |
-
public static function getPHPMemoryLimit() {
|
1165 |
-
return ini_get( 'memory_limit' );
|
1166 |
-
}
|
1167 |
-
|
1168 |
-
protected static function getOS() {
|
1169 |
-
echo esc_html( PHP_OS );
|
1170 |
-
}
|
1171 |
-
|
1172 |
-
protected static function getArchitecture() {
|
1173 |
-
echo esc_html( PHP_INT_SIZE * 8 ) ?> bit <?php
|
1174 |
-
}
|
1175 |
-
|
1176 |
-
protected static function memoryUsage() {
|
1177 |
-
if ( function_exists( 'memory_get_usage' ) ) {
|
1178 |
-
$memory_usage = round( memory_get_usage() / 1024 / 1024, 2 ) . __( ' MB' );
|
1179 |
-
} else {
|
1180 |
-
$memory_usage = __( 'N/A' );
|
1181 |
-
}
|
1182 |
-
echo esc_html( $memory_usage );
|
1183 |
-
}
|
1184 |
-
|
1185 |
-
protected static function getOutputBufferSize() {
|
1186 |
-
return ini_get( 'pcre.backtrack_limit' );
|
1187 |
-
}
|
1188 |
-
|
1189 |
-
protected static function getPHPSafeMode() {
|
1190 |
-
if ( version_compare(phpversion(), '5.3.0') < 0 && ini_get( 'safe_mode' ) ) {
|
1191 |
-
$safe_mode = __( 'ON' );
|
1192 |
-
} else {
|
1193 |
-
$safe_mode = __( 'OFF' );
|
1194 |
-
}
|
1195 |
-
echo esc_html( $safe_mode );
|
1196 |
-
}
|
1197 |
-
|
1198 |
-
protected static function getSQLMode() {
|
1199 |
-
global $wpdb;
|
1200 |
-
$mysqlinfo = $wpdb->get_results( "SHOW VARIABLES LIKE 'sql_mode'" );
|
1201 |
-
if ( is_array( $mysqlinfo ) ) {
|
1202 |
-
$sql_mode = $mysqlinfo[0]->Value;
|
1203 |
-
}
|
1204 |
-
if ( empty( $sql_mode ) ) {
|
1205 |
-
$sql_mode = __( 'NOT SET' );
|
1206 |
-
}
|
1207 |
-
echo esc_html( $sql_mode );
|
1208 |
-
}
|
1209 |
-
|
1210 |
-
protected static function getPHPAllowUrlFopen() {
|
1211 |
-
if ( ini_get( 'allow_url_fopen' ) ) {
|
1212 |
-
$allow_url_fopen = __( 'ON' );
|
1213 |
-
} else {
|
1214 |
-
$allow_url_fopen = __( 'OFF' );
|
1215 |
-
}
|
1216 |
-
echo esc_html( $allow_url_fopen );
|
1217 |
-
}
|
1218 |
-
|
1219 |
-
protected static function getPHPExif() {
|
1220 |
-
if ( is_callable( 'exif_read_data' ) ) {
|
1221 |
-
$exif = __( 'YES' ) . ' ( V' . substr( phpversion( 'exif' ), 0, 4 ) . ')';
|
1222 |
-
} else {
|
1223 |
-
$exif = __( 'NO' );
|
1224 |
-
}
|
1225 |
-
echo esc_html( $exif );
|
1226 |
-
}
|
1227 |
-
|
1228 |
-
protected static function getPHPIPTC() {
|
1229 |
-
if ( is_callable( 'iptcparse' ) ) {
|
1230 |
-
$iptc = __( 'YES' );
|
1231 |
-
} else {
|
1232 |
-
$iptc = __( 'NO' );
|
1233 |
-
}
|
1234 |
-
echo esc_html( $iptc );
|
1235 |
-
}
|
1236 |
-
|
1237 |
-
protected static function getPHPXML() {
|
1238 |
-
if ( is_callable( 'xml_parser_create' ) ) {
|
1239 |
-
$xml = __( 'YES' );
|
1240 |
-
} else {
|
1241 |
-
$xml = __( 'NO' );
|
1242 |
-
}
|
1243 |
-
echo esc_html( $xml );
|
1244 |
-
}
|
1245 |
-
|
1246 |
-
// new
|
1247 |
-
|
1248 |
-
protected static function getCurrentlyExecutingScript() {
|
1249 |
-
echo esc_html( $_SERVER['PHP_SELF'] );
|
1250 |
-
}
|
1251 |
-
|
1252 |
-
protected static function getServerGetawayInterface() {
|
1253 |
-
$gate = isset($_SERVER['GATEWAY_INTERFACE']) ? $_SERVER['GATEWAY_INTERFACE'] : '';
|
1254 |
-
echo esc_html( $gate );
|
1255 |
-
}
|
1256 |
-
|
1257 |
-
public static function getServerIP() {
|
1258 |
-
echo esc_html( $_SERVER['SERVER_ADDR'] );
|
1259 |
-
}
|
1260 |
-
|
1261 |
-
protected static function getServerName() {
|
1262 |
-
echo esc_html( $_SERVER['SERVER_NAME'] );
|
1263 |
-
}
|
1264 |
-
|
1265 |
-
protected static function getServerSoftware() {
|
1266 |
-
echo esc_html( $_SERVER['SERVER_SOFTWARE'] );
|
1267 |
-
}
|
1268 |
-
|
1269 |
-
protected static function getServerProtocol() {
|
1270 |
-
echo esc_html( $_SERVER['SERVER_PROTOCOL'] );
|
1271 |
-
}
|
1272 |
-
|
1273 |
-
protected static function getServerRequestMethod() {
|
1274 |
-
echo esc_html( $_SERVER['REQUEST_METHOD'] );
|
1275 |
-
}
|
1276 |
-
|
1277 |
-
protected static function getServerRequestTime() {
|
1278 |
-
echo esc_html( $_SERVER['REQUEST_TIME'] );
|
1279 |
-
}
|
1280 |
-
|
1281 |
-
protected static function getServerQueryString() {
|
1282 |
-
echo esc_html( $_SERVER['QUERY_STRING'] );
|
1283 |
-
}
|
1284 |
-
|
1285 |
-
protected static function getServerHTTPAccept() {
|
1286 |
-
echo esc_html( $_SERVER['HTTP_ACCEPT'] );
|
1287 |
-
}
|
1288 |
-
|
1289 |
-
protected static function getServerAcceptCharset() {
|
1290 |
-
if ( ! isset( $_SERVER['HTTP_ACCEPT_CHARSET'] ) || ( '' === $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
|
1291 |
-
esc_html_e( 'N/A', 'mainwp-child' );
|
1292 |
-
} else {
|
1293 |
-
echo esc_html( $_SERVER['HTTP_ACCEPT_CHARSET'] );
|
1294 |
-
}
|
1295 |
-
}
|
1296 |
-
|
1297 |
-
protected static function getHTTPHost() {
|
1298 |
-
echo esc_html( $_SERVER['HTTP_HOST'] );
|
1299 |
-
}
|
1300 |
-
|
1301 |
-
protected static function getCompleteURL() {
|
1302 |
-
echo isset( $_SERVER['HTTP_REFERER'] ) ? esc_html( $_SERVER['HTTP_REFERER'] ) : '';
|
1303 |
-
}
|
1304 |
-
|
1305 |
-
protected static function getUserAgent() {
|
1306 |
-
echo esc_html( $_SERVER['HTTP_USER_AGENT'] );
|
1307 |
-
}
|
1308 |
-
|
1309 |
-
protected static function getHTTPS() {
|
1310 |
-
if ( isset( $_SERVER['HTTPS'] ) && '' !== $_SERVER['HTTPS'] ) {
|
1311 |
-
echo esc_html( __( 'ON', 'mainwp-child' ) . ' - ' . $_SERVER['HTTPS'] );
|
1312 |
-
} else {
|
1313 |
-
esc_html_e( 'OFF', 'mainwp-child' );
|
1314 |
-
}
|
1315 |
-
}
|
1316 |
-
|
1317 |
-
protected static function serverSelfConnect() {
|
1318 |
-
$url = site_url( 'wp-cron.php' );
|
1319 |
-
$query_args = array('mainwp_child_run' => 'test');
|
1320 |
-
$url = add_query_arg( $query_args, $url );
|
1321 |
-
$args = array( 'blocking' => TRUE,
|
1322 |
-
'sslverify' => apply_filters( 'https_local_ssl_verify', true ),
|
1323 |
-
'timeout' => 15
|
1324 |
-
);
|
1325 |
-
$response = wp_remote_post( $url, $args );
|
1326 |
-
$test_result = '';
|
1327 |
-
if ( is_wp_error( $response ) ) {
|
1328 |
-
$test_result .= sprintf( __( 'The HTTP response test get an error "%s"','mainwp-child' ), $response->get_error_message() );
|
1329 |
-
}
|
1330 |
-
$response_code = wp_remote_retrieve_response_code( $response );
|
1331 |
-
if ( $response_code < 200 && $response_code > 204 ) {
|
1332 |
-
$test_result .= sprintf( __( 'The HTTP response test get a false http status (%s)','mainwp-child' ), wp_remote_retrieve_response_code( $response ) );
|
1333 |
-
} else {
|
1334 |
-
$response_body = wp_remote_retrieve_body( $response );
|
1335 |
-
if ( FALSE === strstr( $response_body, 'MainWP Test' ) ) {
|
1336 |
-
$test_result .= sprintf( __( 'Not expected HTTP response body: %s','mainwp-child' ), esc_attr( strip_tags( $response_body ) ) );
|
1337 |
-
}
|
1338 |
-
}
|
1339 |
-
if ( empty( $test_result ) ) {
|
1340 |
-
_e( 'Response Test O.K.', 'mainwp-child' );
|
1341 |
-
} else
|
1342 |
-
echo $test_result;
|
1343 |
-
}
|
1344 |
-
|
1345 |
-
|
1346 |
-
protected static function getRemoteAddress() {
|
1347 |
-
echo esc_html( $_SERVER['REMOTE_ADDR'] );
|
1348 |
-
}
|
1349 |
-
|
1350 |
-
protected static function getRemoteHost() {
|
1351 |
-
if ( ! isset( $_SERVER['REMOTE_HOST'] ) || ( '' === $_SERVER['REMOTE_HOST'] ) ) {
|
1352 |
-
esc_html_e( 'N/A', 'mainwp-child' );
|
1353 |
-
} else {
|
1354 |
-
echo esc_html( $_SERVER['REMOTE_HOST'] );
|
1355 |
-
}
|
1356 |
-
}
|
1357 |
-
|
1358 |
-
protected static function getRemotePort() {
|
1359 |
-
echo esc_html( $_SERVER['REMOTE_PORT'] );
|
1360 |
-
}
|
1361 |
-
|
1362 |
-
protected static function getScriptFileName() {
|
1363 |
-
echo esc_html( $_SERVER['SCRIPT_FILENAME'] );
|
1364 |
-
}
|
1365 |
-
|
1366 |
-
protected static function getServerAdmin() {
|
1367 |
-
echo esc_html( $_SERVER['SERVER_ADMIN'] );
|
1368 |
-
}
|
1369 |
-
|
1370 |
-
protected static function getServerPort() {
|
1371 |
-
echo esc_html( $_SERVER['SERVER_PORT'] );
|
1372 |
-
}
|
1373 |
-
|
1374 |
-
protected static function getServerSignature() {
|
1375 |
-
echo esc_html( $_SERVER['SERVER_SIGNATURE'] );
|
1376 |
-
}
|
1377 |
-
|
1378 |
-
protected static function getServerPathTranslated() {
|
1379 |
-
if ( ! isset( $_SERVER['PATH_TRANSLATED'] ) || ( '' === $_SERVER['PATH_TRANSLATED'] ) ) {
|
1380 |
-
esc_html_e( 'N/A', 'mainwp-child' );
|
1381 |
-
} else {
|
1382 |
-
echo esc_html( $_SERVER['PATH_TRANSLATED'] );
|
1383 |
-
}
|
1384 |
-
}
|
1385 |
-
|
1386 |
-
protected static function getScriptName() {
|
1387 |
-
echo esc_html( $_SERVER['SCRIPT_NAME'] );
|
1388 |
-
}
|
1389 |
-
|
1390 |
-
protected static function getCurrentPageURI() {
|
1391 |
-
echo esc_html( $_SERVER['REQUEST_URI'] );
|
1392 |
-
}
|
1393 |
-
|
1394 |
-
protected static function getWPRoot() {
|
1395 |
-
echo esc_html( ABSPATH );
|
1396 |
-
}
|
1397 |
-
|
1398 |
-
function formatSizeUnits( $bytes ) {
|
1399 |
-
if ( $bytes >= 1073741824 ) {
|
1400 |
-
$bytes = number_format( $bytes / 1073741824, 2 ) . ' GB';
|
1401 |
-
} elseif ( $bytes >= 1048576 ) {
|
1402 |
-
$bytes = number_format( $bytes / 1048576, 2 ) . ' MB';
|
1403 |
-
} elseif ( $bytes >= 1024 ) {
|
1404 |
-
$bytes = number_format( $bytes / 1024, 2 ) . ' KB';
|
1405 |
-
} elseif ( $bytes > 1 ) {
|
1406 |
-
$bytes = $bytes . ' bytes';
|
1407 |
-
} elseif ( 1 === $bytes ) {
|
1408 |
-
$bytes = $bytes . ' byte';
|
1409 |
-
} else {
|
1410 |
-
$bytes = '0 bytes';
|
1411 |
-
}
|
1412 |
-
|
1413 |
-
return $bytes;
|
1414 |
-
|
1415 |
-
}
|
1416 |
-
|
1417 |
-
|
1418 |
-
/*
|
1419 |
-
*Plugin-Name: Error Log Dashboard Widget
|
1420 |
-
*Plugin URI: http://wordpress.org/extend/plugins/error-log-dashboard-widget/
|
1421 |
-
*Description: Robust zero-configuration and low-memory way to keep an eye on error log.
|
1422 |
-
*Author: Andrey "Rarst" Savchenko
|
1423 |
-
*Author URI: http://www.rarst.net/
|
1424 |
-
*Version: 1.0.2
|
1425 |
-
*License: GPLv2 or later
|
1426 |
-
|
1427 |
-
*Includes last_lines() function by phant0m, licensed under cc-wiki and GPLv2+
|
1428 |
-
*/
|
1429 |
-
|
1430 |
-
public static function renderErrorLogPage() {
|
1431 |
?>
|
1432 |
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0">
|
1433 |
<thead title="Click to Toggle" style="cursor: pointer;">
|
1434 |
-
|
1435 |
-
|
1436 |
-
<
|
1437 |
-
|
1438 |
-
<span><?php esc_html_e( 'Error', 'mainwp-child' ); ?></span></th>
|
1439 |
-
</tr>
|
1440 |
</thead>
|
1441 |
<tbody class="list:sites" id="mainwp-error-log-table">
|
1442 |
-
|
1443 |
</tbody>
|
1444 |
</table>
|
1445 |
<?php
|
1446 |
}
|
1447 |
|
1448 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1449 |
$log_errors = ini_get( 'log_errors' );
|
1450 |
if ( ! $log_errors ) {
|
1451 |
echo '<tr><td colspan="2">' . esc_html__( 'Error logging disabled.', 'mainwp-child' ) . '</td></tr>';
|
@@ -1457,9 +1227,8 @@ class MainWP_Child_Server_Information {
|
|
1457 |
$lines = array();
|
1458 |
|
1459 |
foreach ( $logs as $log ) {
|
1460 |
-
|
1461 |
if ( is_readable( $log ) ) {
|
1462 |
-
$lines = array_merge( $lines, self::
|
1463 |
}
|
1464 |
}
|
1465 |
|
@@ -1467,12 +1236,12 @@ class MainWP_Child_Server_Information {
|
|
1467 |
$lines = array_filter( $lines );
|
1468 |
|
1469 |
if ( empty( $lines ) ) {
|
1470 |
-
|
1471 |
-
|
1472 |
-
|
1473 |
-
|
1474 |
-
|
1475 |
-
echo '<tr><td colspan="2">' . $msg
|
1476 |
return;
|
1477 |
}
|
1478 |
|
@@ -1504,31 +1273,32 @@ class MainWP_Child_Server_Information {
|
|
1504 |
echo wp_kses_post( "<tr><td>{$time}</td><td>{$error}</td></tr>" );
|
1505 |
}
|
1506 |
}
|
1507 |
-
|
1508 |
-
}
|
1509 |
-
|
1510 |
-
static function time_compare( $a, $b ) {
|
1511 |
-
if ( $a === $b ) {
|
1512 |
-
return 0;
|
1513 |
-
}
|
1514 |
-
|
1515 |
-
return ( strtotime( $a['time'] ) > strtotime( $b['time'] ) ) ? - 1 : 1;
|
1516 |
}
|
1517 |
|
1518 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1519 |
$lines = array();
|
1520 |
|
1521 |
-
// we will always have a fragment of a non-complete line
|
1522 |
// keep this in here till we have our next entire line.
|
1523 |
$leftover = '';
|
1524 |
|
|
|
1525 |
$fh = fopen( $path, 'r' );
|
1526 |
-
// go to the end of the file
|
1527 |
fseek( $fh, 0, SEEK_END );
|
1528 |
|
|
|
1529 |
do {
|
1530 |
-
// need to know whether we can actually go back
|
1531 |
-
// $block_size bytes
|
1532 |
$can_read = $block_size;
|
1533 |
|
1534 |
if ( ftell( $fh ) <= $block_size ) {
|
@@ -1539,23 +1309,20 @@ class MainWP_Child_Server_Information {
|
|
1539 |
break;
|
1540 |
}
|
1541 |
|
1542 |
-
// go back as many bytes as we can
|
1543 |
-
// read them to $data and then move the file pointer
|
1544 |
// back to where we were.
|
1545 |
fseek( $fh, - $can_read, SEEK_CUR );
|
1546 |
-
$data
|
1547 |
$data .= $leftover;
|
1548 |
fseek( $fh, - $can_read, SEEK_CUR );
|
1549 |
|
1550 |
-
// split lines by \n. Then reverse them,
|
1551 |
-
// now the last line is most likely not a complete
|
1552 |
-
// line which is why we do not directly add it, but
|
1553 |
-
// append it to the data read the next time.
|
1554 |
$split_data = array_reverse( explode( "\n", $data ) );
|
1555 |
$new_lines = array_slice( $split_data, 0, - 1 );
|
1556 |
$lines = array_merge( $lines, $new_lines );
|
1557 |
$leftover = $split_data[ count( $split_data ) - 1 ];
|
1558 |
-
} while (
|
1559 |
|
1560 |
if ( 0 === ftell( $fh ) ) {
|
1561 |
$lines[] = $leftover;
|
@@ -1563,123 +1330,87 @@ class MainWP_Child_Server_Information {
|
|
1563 |
|
1564 |
fclose( $fh );
|
1565 |
|
|
|
|
|
1566 |
// Usually, we will read too many lines, correct that here.
|
1567 |
return array_slice( $lines, 0, $line_count );
|
1568 |
}
|
1569 |
|
1570 |
-
|
1571 |
-
|
1572 |
-
|
1573 |
-
|
1574 |
-
|
1575 |
-
|
1576 |
-
|
1577 |
-
|
1578 |
-
@show_source( ABSPATH . 'wp-config.php' );
|
1579 |
-
} else {
|
1580 |
-
$files = @get_included_files();
|
1581 |
-
$configFound = false;
|
1582 |
-
if ( is_array( $files ) ) {
|
1583 |
-
foreach ( $files as $file ) {
|
1584 |
-
if ( stristr( $file, 'wp-config.php' ) ) {
|
1585 |
-
$configFound = true;
|
1586 |
-
@show_source( $file );
|
1587 |
-
break;
|
1588 |
-
}
|
1589 |
-
}
|
1590 |
-
}
|
1591 |
-
|
1592 |
-
if ( !$configFound ) {
|
1593 |
-
_e( 'wp-config.php not found', 'mainwp' );
|
1594 |
-
}
|
1595 |
-
}
|
1596 |
-
?>
|
1597 |
-
</div>
|
1598 |
-
</div>
|
1599 |
-
<?php
|
1600 |
-
}
|
1601 |
-
|
1602 |
-
public static function renderhtaccess() {
|
1603 |
-
?>
|
1604 |
-
<div class="postbox" id="mainwp-code-display">
|
1605 |
-
<h3 class="hndle" style="padding: 8px 12px; font-size: 14px;"><span><?php _e( '.htaccess', 'mainwp-child' ); ?></span></h3>
|
1606 |
|
1607 |
-
|
1608 |
-
|
1609 |
-
|
1610 |
-
|
1611 |
-
|
1612 |
-
|
1613 |
-
|
1614 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1615 |
|
1616 |
-
|
1617 |
-
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
|
1618 |
-
if ($branding_title == '')
|
1619 |
-
$branding_title = 'MainWP';
|
1620 |
-
|
1621 |
-
global $current_user;
|
1622 |
-
$uniqueId = get_option('mainwp_child_uniqueId');
|
1623 |
-
$details = array(
|
1624 |
-
'siteurl' => array(
|
1625 |
-
'title' => __('Site URL', 'mainwp-child'),
|
1626 |
-
'value' => get_bloginfo( 'url' ),
|
1627 |
-
'desc' => get_bloginfo( 'url' )
|
1628 |
-
),
|
1629 |
-
'adminuser' => array(
|
1630 |
-
'title' => __('Administrator name', 'mainwp-child'),
|
1631 |
-
'value' => $current_user->user_login,
|
1632 |
-
'desc' => __('This is your Administrator username, however, you can use any existing Administrator username.', 'mainwp-child')
|
1633 |
-
),
|
1634 |
-
'friendly_name' => array(
|
1635 |
-
'title' => __('Friendly site name', 'mainwp-child'),
|
1636 |
-
'value' => get_bloginfo( 'name' ),
|
1637 |
-
'desc' => __('For the friendly site name, you can use any name, this is just a suggestion.', 'mainwp-child')
|
1638 |
-
),
|
1639 |
-
'uniqueid' => array(
|
1640 |
-
'title' => __('Child unique security id', 'mainwp-child'),
|
1641 |
-
'value' => !empty($uniqueId) ? $uniqueId : __('Leave the field blank', 'mainwp-child'),
|
1642 |
-
'desc' => sprintf(__('Child unique security id is not required, however, since you have enabled it, you need to add it to your %s dashboard.', 'mainwp-child') , stripslashes( $branding_title ) )
|
1643 |
-
),
|
1644 |
-
'verify_ssl' => array(
|
1645 |
-
'title' => __('Verify certificate', 'mainwp-child'),
|
1646 |
-
'value' => __('Yes', 'mainwp-child'),
|
1647 |
-
'desc' => __('If there is an issue with SSL certificate on this site, try to set this option to No.', 'mainwp-child')
|
1648 |
-
),
|
1649 |
-
'ssl_version' => array(
|
1650 |
-
'title' => __('SSL version', 'mainwp-child'),
|
1651 |
-
'value' => __('Auto Detect', 'mainwp-child'),
|
1652 |
-
'desc' => __('Auto Detect', 'mainwp-child'),
|
1653 |
-
),
|
1654 |
-
|
1655 |
-
);
|
1656 |
?>
|
1657 |
<div class="postbox" id="connection_detail">
|
1658 |
<h3 class="mainwp_box_title"><span><?php _e( 'Connection details', 'mainwp-child' ); ?></span></h3>
|
1659 |
<div class="inside">
|
1660 |
-
|
1661 |
-
|
1662 |
-
|
1663 |
-
|
1664 |
-
|
1665 |
-
|
1666 |
-
|
1667 |
-
|
1668 |
-
|
1669 |
-
|
1670 |
-
|
1671 |
-
|
1672 |
-
|
1673 |
-
|
1674 |
-
|
1675 |
-
|
1676 |
-
|
1677 |
-
|
1678 |
-
</tbody>
|
1679 |
-
</table>
|
1680 |
</div>
|
1681 |
</div>
|
1682 |
<?php
|
1683 |
}
|
1684 |
|
1685 |
-
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Server Information
|
4 |
+
*
|
5 |
+
* MainWP Child server information handler.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_Server_Information
|
14 |
+
*
|
15 |
+
* MainWP Child server information handler.
|
16 |
+
*/
|
17 |
+
class MainWP_Child_Server_Information extends MainWP_Child_Server_Information_Base {
|
18 |
const WARNING = 1;
|
19 |
+
const ERROR = 2;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Method get_class_name()
|
23 |
+
*
|
24 |
+
* Get class name.
|
25 |
+
*
|
26 |
+
* @return string __CLASS__ Class name.
|
27 |
+
*/
|
28 |
+
public static function get_class_name() {
|
29 |
+
return __CLASS__;
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Add hooks after WordPress has finished loading but before any headers are sent.
|
34 |
+
*
|
35 |
+
* @uses MainWP_Child_Server_Information::dismiss_warnings() Dismiss warnings.
|
36 |
+
*/
|
37 |
public static function init() {
|
38 |
+
add_action(
|
39 |
+
'wp_ajax_mainwp-child_dismiss_warnings',
|
40 |
+
array(
|
41 |
+
self::get_class_name(),
|
42 |
+
'dismiss_warnings',
|
43 |
+
)
|
44 |
+
);
|
45 |
}
|
46 |
|
47 |
+
/**
|
48 |
+
* Dismiss warnings.
|
49 |
+
*
|
50 |
+
* @uses MainWP_Helper::update_option() Update option by option name.
|
51 |
+
* @uses MainWP_Child_Server_Information_Base::get_warnings() Initiate check on important System Variables and compare them to required defaults.
|
52 |
+
* @uses get_option() Retrieves an option value based on an option name.
|
53 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
54 |
+
*
|
55 |
+
* @used-by MainWP_Child_Server_Information::init() Add hooks after WordPress has finished loading but before any headers are sent.
|
56 |
+
*/
|
57 |
+
public static function dismiss_warnings() {
|
58 |
if ( isset( $_POST['what'] ) ) {
|
59 |
$dismissWarnings = get_option( 'mainwp_child_dismiss_warnings' );
|
60 |
if ( ! is_array( $dismissWarnings ) ) {
|
61 |
$dismissWarnings = array();
|
62 |
}
|
63 |
+
if ( 'warning' == $_POST['what'] ) {
|
64 |
+
if ( isset( $_POST['warnings'] ) ) {
|
65 |
+
$warnings = intval( $_POST['warnings'] );
|
66 |
+
} else {
|
67 |
+
$warnings = self::get_warnings();
|
68 |
+
}
|
69 |
+
$dismissWarnings['warnings'] = $warnings;
|
70 |
}
|
71 |
MainWP_Helper::update_option( 'mainwp_child_dismiss_warnings', $dismissWarnings );
|
72 |
}
|
73 |
}
|
74 |
|
75 |
+
/**
|
76 |
+
* Render warnings.
|
77 |
+
*
|
78 |
+
* @uses MainWP_Helper::update_option() Update option by option name.
|
79 |
+
* @uses MainWP_Child_Server_Information_Base::get_warnings() Initiate check on important System Variables and compare them to required defaults.
|
80 |
+
* @uses get_option() Retrieves an option value based on an option name.
|
81 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
82 |
+
*
|
83 |
+
* @used-by MainWP_Child_Server_Information::init() Add hooks after WordPress has finished loading but before any headers are sent.
|
84 |
+
*/
|
85 |
+
public static function render_warnings() {
|
86 |
+
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '';
|
87 |
+
if ( isset( $_SERVER['REQUEST_URI'] ) && ( stristr( $request_uri, 'mainwp_child_tab' ) || stristr( $request_uri, 'mainwp-reports-page' ) || stristr( $request_uri, 'mainwp-reports-settings' ) ) ) {
|
88 |
return;
|
89 |
}
|
90 |
|
91 |
+
$warnings = self::get_warnings();
|
92 |
|
93 |
$dismissWarnings = get_option( 'mainwp_child_dismiss_warnings' );
|
94 |
if ( ! is_array( $dismissWarnings ) ) {
|
120 |
var data = {
|
121 |
action: 'mainwp-child_dismiss_warnings',
|
122 |
what: pAction,
|
123 |
+
warnings: <?php echo intval( $warnings ); ?>
|
124 |
};
|
125 |
|
126 |
jQuery.ajax( {
|
127 |
type: "POST",
|
128 |
url: ajaxurl,
|
129 |
data: data,
|
130 |
+
success: function ( resp ) {},
|
131 |
+
error: function () {},
|
|
|
|
|
132 |
dataType: 'json'
|
133 |
} );
|
134 |
|
153 |
border-radius: 3px;
|
154 |
margin: 1em 0 !important;
|
155 |
|
156 |
+
background-image: url( '<?php echo esc_url( plugins_url( 'images/mainwp-icon-orange.png', dirname( __FILE__ ) ) ); ?>' ) !important;
|
157 |
background-position: 1.5em 50% !important;
|
158 |
background-repeat: no-repeat !important;
|
159 |
background-size: 30px !important;
|
174 |
<tbody id="the-sites-list" class="list:sites">
|
175 |
<?php
|
176 |
$warning = '';
|
|
|
177 |
if ( $warnings > 0 ) {
|
178 |
+
$warning .= '<tr><td colspan="2">This site may not connect to your dashboard or may have other issues. Check your <a href="options-general.php?page=mainwp_child_tab">MainWP server information page</a>.</td><td style="text-align: right;"><a href="#" id="mainwp-child-connect-warning-dismiss">Dismiss</a></td></tr>';
|
179 |
}
|
180 |
echo $warning;
|
181 |
?>
|
185 |
<?php
|
186 |
}
|
187 |
|
188 |
+
/**
|
189 |
+
* Render JavaScrip code for the Server Information page.
|
190 |
+
*
|
191 |
+
* @used-by MainWP_Child_Server_Information::render_page() Render the Server Information page.
|
192 |
+
*/
|
193 |
+
private static function render_page_js() {
|
194 |
?>
|
195 |
<script language="javascript">
|
196 |
|
200 |
*
|
201 |
* By Eli Grey, http://eligrey.com
|
202 |
* License: X11/MIT
|
203 |
+
* See LICENSE.md
|
204 |
*/
|
205 |
|
206 |
/*global self */
|
207 |
+
/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true, plusplus: true */
|
|
|
208 |
|
209 |
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
|
210 |
|
211 |
var childSaveAs = childSaveAs
|
212 |
+
|| ( navigator.msSaveBlob && navigator.msSaveBlob.bind( navigator ) )
|
213 |
+
|| ( function( view ) {
|
214 |
"use strict";
|
215 |
+
var doc = view.document
|
|
|
|
|
216 |
, get_URL = function() {
|
217 |
return view.URL || view.webkitURL || view;
|
218 |
}
|
241 |
var i = deletion_queue.length;
|
242 |
while (i--) {
|
243 |
var file = deletion_queue[i];
|
244 |
+
if (typeof file === "string") {
|
245 |
URL.revokeObjectURL(file);
|
246 |
+
} else {
|
247 |
file.remove();
|
248 |
}
|
249 |
}
|
250 |
+
deletion_queue.length = 0;
|
251 |
}
|
252 |
, dispatch = function(filesaver, event_types, event) {
|
253 |
event_types = [].concat(event_types);
|
263 |
}
|
264 |
}
|
265 |
}
|
266 |
+
, FileSaver = function( blob, name ) {
|
|
|
267 |
var
|
268 |
filesaver = this
|
269 |
, type = blob.type
|
276 |
return object_url;
|
277 |
}
|
278 |
, dispatch_all = function() {
|
279 |
+
dispatch( filesaver, "writestart progress write writeend".split( " " ) );
|
280 |
}
|
|
|
281 |
, fs_error = function() {
|
282 |
+
if ( blob_changed || !object_url ) {
|
283 |
+
object_url = get_object_url( blob );
|
|
|
284 |
}
|
285 |
if (target_view) {
|
286 |
target_view.location.href = object_url;
|
299 |
, slice
|
300 |
;
|
301 |
filesaver.readyState = filesaver.INIT;
|
302 |
+
if ( !name ) {
|
303 |
name = "download";
|
304 |
}
|
305 |
+
if ( can_use_save_link ) {
|
306 |
+
object_url = get_object_url( blob );
|
307 |
save_link.href = object_url;
|
308 |
save_link.download = name;
|
309 |
+
if ( click( save_link ) ) {
|
310 |
filesaver.readyState = filesaver.DONE;
|
311 |
dispatch_all();
|
312 |
return;
|
313 |
}
|
314 |
}
|
315 |
+
if ( view.chrome && type && type !== force_saveable_type ) {
|
|
|
|
|
|
|
316 |
slice = blob.slice || blob.webkitSlice;
|
317 |
+
blob = slice.call( blob, 0, blob.size, force_saveable_type );
|
318 |
blob_changed = true;
|
319 |
}
|
|
|
|
|
|
|
320 |
if (webkit_req_fs && name !== "download") {
|
321 |
name += ".download";
|
322 |
}
|
323 |
+
if ( type === force_saveable_type || webkit_req_fs ) {
|
324 |
target_view = view;
|
325 |
} else {
|
326 |
target_view = view.open();
|
360 |
}), fs_error);
|
361 |
};
|
362 |
dir.getFile(name, {create: false}, abortable(function(file) {
|
|
|
363 |
file.remove();
|
364 |
save();
|
365 |
}), abortable(function(ex) {
|
404 |
var o = i.toString();
|
405 |
if (!s) { s = '0'; }
|
406 |
while (o.length < parseInt(l)) {
|
407 |
+
if( w == 'undefined' ){
|
|
|
408 |
o = s + o;
|
409 |
}else{
|
410 |
o = o + s;
|
412 |
}
|
413 |
return o;
|
414 |
};
|
415 |
+
jQuery( document ).on( 'click', 'a.mwp-child-get-system-report-btn', function() {
|
416 |
var report = "";
|
417 |
+
jQuery( '.mwp_server_info_box thead, .mwp_server_info_box tbody' ).each( function() {
|
418 |
var td_len = [35, 55, 45, 12, 12];
|
419 |
var th_count = 0;
|
420 |
var i;
|
421 |
+
if ( jQuery( this ).is( 'thead' ) ) {
|
422 |
i = 0;
|
423 |
report = report + "\n### ";
|
424 |
+
th_count = jQuery( this ).find( 'th:not(".mwp-not-generate-row")' ).length;
|
425 |
+
jQuery( this ).find( 'th:not(".mwp-not-generate-row")' ).each( function() {
|
426 |
var len = td_len[i];
|
427 |
+
if ( i == 0 || i == th_count -1 )
|
428 |
len = len - 4;
|
429 |
+
report = report + mwp_child_strCut( jQuery.trim( jQuery( this ).text() ), len, ' ' );
|
430 |
i++;
|
431 |
+
} );
|
432 |
report = report + " ###\n\n";
|
433 |
} else {
|
434 |
+
jQuery( 'tr', jQuery( this ) ).each( function() {
|
435 |
+
if ( jQuery( this ).hasClass( 'mwp-not-generate-row' ) )
|
436 |
return;
|
437 |
i = 0;
|
438 |
+
jQuery( this ).find( 'td:not(".mwp-not-generate-row")' ).each( function() {
|
439 |
+
if (jQuery( this ).hasClass( 'mwp-hide-generate-row' ) ) {
|
440 |
+
report = report + mwp_child_strCut( ' ', td_len[i], ' ' );
|
441 |
i++;
|
442 |
return;
|
443 |
}
|
444 |
+
report = report + mwp_child_strCut( jQuery.trim( jQuery( this ).text() ), td_len[i], ' ' );
|
445 |
i++;
|
446 |
+
} );
|
447 |
report = report + "\n";
|
448 |
+
} );
|
|
|
449 |
}
|
450 |
} );
|
|
|
451 |
try {
|
452 |
+
jQuery( "#mwp-server-information" ).slideDown();
|
453 |
+
jQuery( "#mwp-server-information textarea" ).val( report ).focus().select();
|
454 |
+
jQuery( this ).fadeOut();
|
455 |
+
jQuery( '.mwp_child_close_srv_info' ).show();
|
456 |
return false;
|
457 |
} catch(e){ }
|
458 |
+
} );
|
459 |
|
460 |
+
jQuery( document ).on( 'click', 'a#mwp_child_close_srv_info', function() {
|
461 |
+
jQuery( '#mwp-server-information' ).hide();
|
462 |
+
jQuery( '.mwp_child_close_srv_info' ).hide();
|
463 |
+
jQuery( 'a.mwp-child-get-system-report-btn' ).show();
|
464 |
return false;
|
465 |
+
} );
|
466 |
+
jQuery( document ).on( 'click', '#mwp_child_download_srv_info', function() {
|
467 |
+
var server_info = jQuery( '#mwp-server-information textarea' ).val();
|
468 |
+
var blob = new Blob( [server_info], {type: "text/plain;charset=utf-8"} );
|
469 |
+
childSaveAs( blob, "server_child_information.txt" );
|
470 |
+
} );
|
|
|
471 |
</script>
|
472 |
+
<?php
|
473 |
+
}
|
474 |
+
|
475 |
+
/**
|
476 |
+
* Render the Server Information page.
|
477 |
+
*
|
478 |
+
* @uses MainWP_Child_Server_Information::render_page_js() Render JavaScrip code for the Server Information page.
|
479 |
+
* @uses MainWP_Child_Server_Information::render_server_infor() Render server information.
|
480 |
+
* @uses MainWP_Child_Server_Information::render_cron() Render cron schedules.
|
481 |
+
* @uses MainWP_Child_Server_Information::render_error_page() Render error log.
|
482 |
+
*/
|
483 |
+
public static function render_page() {
|
484 |
+
self::render_page_js();
|
485 |
+
?>
|
486 |
<style type="text/css">
|
487 |
#mwp-server-information {
|
488 |
display: none;
|
514 |
</style>
|
515 |
<div class="wrap">
|
516 |
<div class="updated below-h2">
|
517 |
+
<p><?php esc_html_e( 'Please include this information when requesting support:', 'mainwp-child' ); ?></p>
|
518 |
+
<span class="mwp_child_close_srv_info">
|
519 |
+
<a href="#" id="mwp_child_download_srv_info"><?php esc_html_e( 'Download', 'mainwp-child' ); ?></a> | <a href="#" id="mwp_child_close_srv_info"><i class="fa fa-eye-slash"></i> <?php _e( 'Hide', 'mainwp-child' ); ?></a>
|
520 |
+
</span>
|
521 |
<p class="submit">
|
522 |
+
<a class="button-primary mwp-child-get-system-report-btn" href="#"><?php esc_html_e( 'Get system report', 'mainwp-child' ); ?></a>
|
523 |
</p>
|
|
|
524 |
<div id="mwp-server-information"><textarea readonly="readonly" wrap="off"></textarea></div>
|
525 |
</div>
|
526 |
<br/>
|
527 |
<div class="mwp_server_info_box">
|
528 |
+
<h2><?php esc_html_e( 'Server Information', 'mainwp-child' ); ?></h2>
|
529 |
+
<?php self::render_server_infor(); ?>
|
530 |
+
<h2><?php esc_html_e( 'Cron Schedules', 'mainwp-child' ); ?></h2>
|
531 |
+
<?php self::render_cron(); ?>
|
532 |
+
<h2><?php esc_html_e( 'Error Log', 'mainwp-child' ); ?></h2>
|
533 |
+
<?php self::render_error_page(); ?>
|
|
|
534 |
</div>
|
535 |
</div>
|
536 |
<?php
|
537 |
}
|
538 |
|
539 |
+
/**
|
540 |
+
* Render server information content.
|
541 |
+
*
|
542 |
+
* @uses MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
543 |
+
* @uses MainWP_Child_Server_Information::render_php_settings_rows() Render PHP settings information rows.
|
544 |
+
* @uses MainWP_Child_Server_Information::render_mysql_infor_rows() Render MySQL settings information rows.
|
545 |
+
* @uses MainWP_Child_Server_Information::render_server_infor_rows() Render server settings information rows.
|
546 |
+
* @uses MainWP_Child_Server_Information::render_php_infor_rows() Render PHP information rows.
|
547 |
+
* @uses MainWP_Child_Server_Information::render_plugins_infor_rows() Render plugins information rows.
|
548 |
+
*
|
549 |
+
* @used-by MainWP_Child_Server_Information::render_page() Render the Server Information page.
|
550 |
+
*/
|
551 |
+
private static function render_server_infor() {
|
552 |
+
$branding_title = MainWP_Child_Branding::instance()->get_branding_title();
|
553 |
+
if ( '' == $branding_title ) {
|
554 |
+
$branding_title = 'MainWP Child';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
555 |
}
|
556 |
+
?>
|
557 |
+
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0">
|
558 |
+
<thead>
|
559 |
+
<tr>
|
560 |
+
<th scope="col" class="manage-column column-posts mwp-not-generate-row" style="width: 1px;"></th>
|
561 |
+
<th scope="col" class="manage-column column-posts"><span><?php esc_html_e( 'Server configuration', 'mainwp-child' ); ?></span></th>
|
562 |
+
<th scope="col" class="manage-column column-posts"><?php esc_html_e( 'Required value', 'mainwp-child' ); ?></th>
|
563 |
+
<th scope="col" class="manage-column column-posts"><?php esc_html_e( 'Value', 'mainwp-child' ); ?></th>
|
564 |
+
<th scope="col" class="manage-column column-posts"><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
565 |
+
</tr>
|
566 |
+
</thead>
|
567 |
+
<tbody id="the-sites-list" class="list:sites">
|
568 |
+
<?php self::render_system_infor_rows( $branding_title ); ?>
|
569 |
+
<?php self::render_php_settings_rows(); ?>
|
570 |
+
<?php self::render_mysql_infor_rows(); ?>
|
571 |
+
<?php self::render_server_infor_rows(); ?>
|
572 |
+
<?php self::render_php_infor_rows(); ?>
|
573 |
+
<?php self::render_plugins_infor_rows( $branding_title ); ?>
|
574 |
+
</tbody>
|
575 |
+
</table>
|
576 |
+
<br/>
|
577 |
+
<?php
|
578 |
}
|
579 |
|
580 |
+
/**
|
581 |
+
* Render system information rows.
|
582 |
+
*
|
583 |
+
* @param string $branding_title Custom branding plgin title.
|
584 |
+
*
|
585 |
+
* @uses MainWP_Child_Server_Information_Base::get_mainwp_version() Get the MainWP Child plugin version number.
|
586 |
+
* @uses MainWP_Child_Server_Information_Base::get_current_version() Get the current MainWP Child plugin version.
|
587 |
+
* @uses MainWP_Child_Server_Information_Base::get_file_system_method() Get file system method.
|
588 |
+
* @uses MainWP_Child_Server_Information::render_file_system_method_check() Render the file system method check.
|
589 |
+
* @uses MainWP_Child_Server_Information::render_mainwp_version_check() Render the MainWP version check row.
|
590 |
+
* @uses MainWP_Child_Server_Information::render_row() Render the server information row.
|
591 |
+
* @uses get_option() Retrieves an option value based on an option name.
|
592 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
593 |
+
*
|
594 |
+
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
595 |
+
*/
|
596 |
+
private static function render_system_infor_rows( $branding_title ) {
|
597 |
+
?>
|
598 |
+
<tr>
|
599 |
+
<td style="background: #333; color: #fff;" colspan="5"><?php echo esc_html( strtoupper( stripslashes( $branding_title ) ) ); ?></td>
|
600 |
+
</tr>
|
601 |
+
<tr>
|
602 |
+
<td></td>
|
603 |
+
<td><?php echo esc_html( stripslashes( $branding_title ) ) . ' ' . __( 'Version', 'mainwp-chil' ); ?></td>
|
604 |
+
<td><?php echo esc_html( self::get_mainwp_version() ); ?></td>
|
605 |
+
<td><?php echo esc_html( self::get_current_version() ); ?></td>
|
606 |
+
<td><?php echo esc_html( self::render_mainwp_version_check() ); ?></td>
|
607 |
+
</tr>
|
608 |
+
<?php self::render_mainwp_directory(); ?>
|
609 |
+
<?php $server = get_option( 'mainwp_child_server' ); ?>
|
610 |
+
<tr>
|
611 |
+
<td></td>
|
612 |
+
<td><?php esc_html_e( 'Currently connected to dashboard URL', 'mainwp-child' ); ?></td>
|
613 |
+
<td><?php echo esc_html( $server ); ?></td>
|
614 |
+
<td></td>
|
615 |
+
<td></td>
|
616 |
+
</tr>
|
617 |
+
<tr>
|
618 |
+
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'WordPress', 'mainwp-child' ); ?></td>
|
619 |
+
</tr>
|
620 |
+
<?php self::render_row( 'WordPress Version', '>=', '3.4', 'get_wordpress_version' ); ?>
|
621 |
+
<?php self::render_row( 'WordPress Memory Limit', '>=', '64M', 'get_wordpress_memory_limit' ); ?>
|
622 |
+
<?php self::render_row( 'MultiSite Disabled', '=', true, 'check_if_multisite' ); ?>
|
623 |
+
<tr>
|
624 |
+
<td></td>
|
625 |
+
<td><?php esc_html_e( 'FileSystem Method', 'mainwp-child' ); ?></td>
|
626 |
+
<td><?php echo esc_html( '= direct' ); ?></td>
|
627 |
+
<td><?php echo esc_html( self::get_file_system_method() ); ?></td>
|
628 |
+
<td><?php echo esc_html( self::render_file_system_method_check() ); ?></td>
|
629 |
+
</tr>
|
630 |
+
<?php
|
631 |
}
|
632 |
|
633 |
+
/**
|
634 |
+
* Render the file system method check.
|
635 |
+
*
|
636 |
+
* @uses MainWP_Child_Server_Information_Base::get_file_system_method() Get file system method.
|
637 |
+
*
|
638 |
+
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
639 |
+
*/
|
640 |
+
protected static function render_file_system_method_check() {
|
641 |
+
$fsmethod = self::get_file_system_method();
|
642 |
if ( 'direct' === $fsmethod ) {
|
643 |
echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>';
|
644 |
} else {
|
646 |
}
|
647 |
}
|
648 |
|
649 |
+
/**
|
650 |
+
* Render PHP settings information rows.
|
651 |
+
*
|
652 |
+
* @uses MainWP_Child_Server_Information::render_row() Render the server information row.
|
653 |
+
* @uses MainWP_Child_Server_Information::render_row_sec() Render the server information secondary row.
|
654 |
+
* @uses MainWP_Child_Server_Information_Base::get_php_safe_mode() Check if PHP is in Safe Mode.
|
655 |
+
*
|
656 |
+
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
657 |
+
*/
|
658 |
+
private static function render_php_settings_rows() {
|
659 |
+
?>
|
660 |
+
<tr>
|
661 |
+
<td style="background: #333; color: #fff;"
|
662 |
+
colspan="5"><?php esc_html_e( 'PHP SETTINGS', 'mainwp-child' ); ?></td>
|
663 |
+
</tr>
|
664 |
+
<?php self::render_row( 'PHP Version', '>=', '5.6', 'get_php_version' ); ?>
|
665 |
+
<tr>
|
666 |
+
<td></td>
|
667 |
+
<td><?php esc_html_e( 'PHP Safe Mode Disabled', 'mainwp-child' ); ?></td>
|
668 |
+
<td colspan="3"><?php self::get_php_safe_mode(); ?></td>
|
669 |
+
</tr>
|
670 |
+
<?php
|
671 |
+
self::render_row_sec( 'PHP Max Execution Time', '>=', '30', 'get_max_execution_time', 'seconds', '=', '0' );
|
672 |
+
self::render_row_sec( 'PHP Max Input Time', '>=', '30', 'get_max_input_time', 'seconds', '=', '0' );
|
673 |
+
self::render_row( 'PHP Memory Limit', '>=', '128M', 'get_php_memory_limit', '(256M+ best for big backups)', null, null, true );
|
674 |
+
self::render_row( 'PCRE Backtracking Limit', '>=', '10000', 'get_output_buffer_size' );
|
675 |
+
self::render_row( 'PHP Upload Max Filesize', '>=', '2M', 'get_upload_max_filesize', '(2MB+ best for upload of big plugins)', null, null, true );
|
676 |
+
self::render_row( 'PHP Post Max Size', '>=', '2M', 'get_post_max_size', '(2MB+ best for upload of big plugins)', null, null, true );
|
677 |
+
self::render_row( 'SSL Extension Enabled', '=', true, 'get_ssl_support' );
|
678 |
+
self::render_row_sec( 'SSL Warnings', '=', '', 'get_ssl_warning', 'empty', '' );
|
679 |
+
self::render_row_sec( 'cURL Extension Enabled', '=', true, 'get_curl_support', '', '', null, '', null, self::ERROR );
|
680 |
+
self::render_row_sec( 'cURL Timeout', '>=', '300', 'get_curl_timeout', 'seconds', '=', '0' );
|
681 |
+
if ( function_exists( 'curl_version' ) ) {
|
682 |
+
self::render_row_sec( 'cURL Version', '>=', '7.18.1', 'get_curl_version', '', '', null );
|
683 |
+
self::render_row_sec(
|
684 |
+
'cURL SSL Version',
|
685 |
+
'>=',
|
686 |
+
array(
|
687 |
+
'version_number' => 0x009080cf,
|
688 |
+
'version' => 'OpenSSL/0.9.8l',
|
689 |
+
),
|
690 |
+
'get_curl_ssl_version',
|
691 |
+
'',
|
692 |
+
'',
|
693 |
+
null,
|
694 |
+
'',
|
695 |
+
'curlssl'
|
696 |
+
);
|
697 |
}
|
698 |
+
}
|
699 |
|
700 |
+
/**
|
701 |
+
* Render MySQL settings information rows.
|
702 |
+
*
|
703 |
+
* @uses MainWP_Child_Server_Information::render_row() Render the server information row.
|
704 |
+
*
|
705 |
+
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
706 |
+
*/
|
707 |
+
private static function render_mysql_infor_rows() {
|
708 |
?>
|
709 |
+
<tr>
|
710 |
+
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'MySQL SETTINGS', 'mainwp-child' ); ?></td>
|
711 |
+
</tr>
|
712 |
+
<?php self::render_row( 'MySQL Version', '>=', '5.0', 'get_my_sql_version' ); ?>
|
713 |
+
<tr>
|
714 |
+
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'BACKUP ARCHIVE INFORMATION', 'mainwp-child' ); ?></td>
|
715 |
+
</tr>
|
716 |
+
<?php self::render_row( 'ZipArchive enabled in PHP', '=', true, 'get_zip_archive_enabled' ); ?>
|
717 |
+
<?php self::render_row( 'Tar GZip supported', '=', true, 'get_gzip_enabled' ); ?>
|
718 |
+
<?php self::render_row( 'Tar BZip2 supported', '=', true, 'get_bzip_enabled' ); ?>
|
719 |
+
<?php
|
720 |
+
}
|
721 |
|
722 |
+
/**
|
723 |
+
* Render plugins information rows.
|
724 |
+
*
|
725 |
+
* @param string $branding_title Custom branding plugin title.
|
726 |
+
*
|
727 |
+
* @uses get_plugins() Check the plugins directory and retrieve all plugin files with plugin data.
|
728 |
+
* @see https://developer.wordpress.org/reference/functions/get_plugins/
|
729 |
+
*
|
730 |
+
* @uses is_plugin_active() Determines whether a plugin is active.
|
731 |
+
* @see https://developer.wordpress.org/reference/functions/get_plugins/
|
732 |
+
*
|
733 |
+
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
734 |
+
*/
|
735 |
+
private static function render_plugins_infor_rows( $branding_title ) {
|
736 |
+
?>
|
737 |
+
<tr>
|
738 |
+
<td style="background: #333; color: #fff;" colspan="5"><?php _e( 'WordPress PLUGINS', 'mainwp-child' ); ?></td>
|
739 |
+
</tr>
|
740 |
+
<?php
|
741 |
+
$all_plugins = get_plugins();
|
742 |
+
foreach ( $all_plugins as $slug => $plugin ) {
|
743 |
+
if ( ! empty( $branding_title ) && ( 'mainwp-child/mainwp-child.php' == $slug || 'mainwp-child-reports/mainwp-child-reports.php' == $slug ) ) {
|
744 |
+
if ( 'mainwp-child/mainwp-child.php' == $slug ) {
|
745 |
+
$plugin['Name'] = esc_html( stripslashes( $branding_title ) );
|
746 |
+
} elseif ( 'mainwp-child-reports/mainwp-child-reports.php' == $slug ) {
|
747 |
+
$plugin['Name'] = esc_html( stripslashes( $branding_title ) ) . ' reports';
|
748 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
749 |
}
|
750 |
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
751 |
<tr>
|
752 |
<td></td>
|
753 |
+
<td><?php echo esc_html( $plugin['Name'] ); ?></td>
|
754 |
+
<td><?php echo esc_html( $plugin['Version'] ); ?></td>
|
755 |
+
<td><?php echo is_plugin_active( $slug ) ? __( 'Active', 'mainwp-child' ) : __( 'Inactive', 'mainwp-child' ); ?></td>
|
|
|
756 |
<td></td>
|
|
|
|
|
|
|
|
|
|
|
757 |
</tr>
|
758 |
<?php
|
759 |
+
}
|
760 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
761 |
|
762 |
+
/**
|
763 |
+
* Render PHP information rows.
|
764 |
+
*
|
765 |
+
* @uses MainWP_Child_Server_Information_Base::get_php_allow_url_fopen() Check if PHP Allow URL fopen is enabled.
|
766 |
+
* @uses MainWP_Child_Server_Information_Base::get_php_exif() Check if PHP exif is enabled.
|
767 |
+
* @uses MainWP_Child_Server_Information_Base::get_php_ip_tc() Check if PHP IP TC is enabled.
|
768 |
+
* @uses MainWP_Child_Server_Information_Base::get_php_xml() Check if PHP XML is enabled.
|
769 |
+
* @uses MainWP_Child_Server_Information_Base::mainwp_required_functions() Check for disabled PHP functions.
|
770 |
+
* @uses MainWP_Child_Server_Information_Base::get_loaded_php_extensions() Get loaded PHP extensions.
|
771 |
+
* @uses MainWP_Child_Server_Information_Base::get_sql_mode() Get current SQL mode.
|
772 |
+
*
|
773 |
+
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
774 |
+
*/
|
775 |
+
private static function render_php_infor_rows() {
|
776 |
+
?>
|
777 |
+
<tr>
|
778 |
+
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'PHP INFORMATION', 'mainwp-child' ); ?></td>
|
779 |
+
</tr>
|
780 |
+
<tr>
|
781 |
+
<td></td>
|
782 |
+
<td><?php esc_html_e( 'PHP Allow URL fopen', 'mainwp-child' ); ?></td>
|
783 |
+
<td colspan="3"><?php self::get_php_allow_url_fopen(); ?></td>
|
784 |
+
</tr>
|
785 |
+
<tr>
|
786 |
+
<td></td>
|
787 |
+
<td><?php esc_html_e( 'PHP Exif Support', 'mainwp-child' ); ?></td>
|
788 |
+
<td colspan="3"><?php self::get_php_exif(); ?></td>
|
789 |
+
</tr>
|
790 |
+
<tr>
|
791 |
+
<td></td>
|
792 |
+
<td><?php esc_html_e( 'PHP IPTC Support', 'mainwp-child' ); ?></td>
|
793 |
+
<td colspan="3"><?php self::get_php_ip_tc(); ?></td>
|
794 |
+
</tr>
|
795 |
+
<tr>
|
796 |
+
<td></td>
|
797 |
+
<td><?php esc_html_e( 'PHP XML Support', 'mainwp-child' ); ?></td>
|
798 |
+
<td colspan="3"><?php self::get_php_xml(); ?></td>
|
799 |
+
</tr>
|
800 |
+
<tr>
|
801 |
+
<td></td>
|
802 |
+
<td><?php esc_html_e( 'PHP Disabled Functions', 'mainwp-child' ); ?></td>
|
803 |
+
<td colspan="3"><?php self::mainwp_required_functions(); ?></td>
|
804 |
+
</tr>
|
805 |
+
<tr>
|
806 |
+
<td></td>
|
807 |
+
<td><?php esc_html_e( 'PHP Loaded Extensions', 'mainwp-child' ); ?></td>
|
808 |
+
<td colspan="3" style="width: 73% !important;"><?php self::get_loaded_php_extensions(); ?></td>
|
809 |
+
</tr>
|
810 |
+
<tr>
|
811 |
+
<td style="background: #333; color: #fff;"
|
812 |
+
colspan="5"><?php esc_html_e( 'MySQL INFORMATION', 'mainwp-child' ); ?></td>
|
813 |
+
</tr>
|
814 |
+
<tr>
|
815 |
+
<td></td>
|
816 |
+
<td><?php esc_html_e( 'MySQL Mode', 'mainwp-child' ); ?></td>
|
817 |
+
<td colspan="3"><?php self::get_sql_mode(); ?></td>
|
818 |
+
</tr>
|
819 |
+
<tr>
|
820 |
+
<td></td>
|
821 |
+
<td><?php esc_html_e( 'MySQL Client Encoding', 'mainwp-child' ); ?></td>
|
822 |
+
<td colspan="3"><?php echo esc_html( defined( 'DB_CHARSET' ) ? DB_CHARSET : '' ); ?></td>
|
823 |
+
</tr>
|
824 |
<?php
|
825 |
}
|
826 |
|
827 |
+
/**
|
828 |
+
* Render server settings information rows.
|
829 |
+
*
|
830 |
+
* @uses MainWP_Child_Server_Information_Base::get_wp_root() Get WordPress root directory.
|
831 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_name()Get server name.
|
832 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_software() Get server software.
|
833 |
+
* @uses MainWP_Child_Server_Information_Base::get_os() Get operating system.
|
834 |
+
* @uses MainWP_Child_Server_Information_Base::get_architecture() Get System architecture.
|
835 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_ip() Get server IP.
|
836 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_protocol() Get server protocol.
|
837 |
+
* @uses MainWP_Child_Server_Information_Base::get_http_host() Get server HTTP host.
|
838 |
+
* @uses MainWP_Child_Server_Information_Base::get_https() Check if HTTPS is on.
|
839 |
+
* @uses MainWP_Child_Server_Information_Base::server_self_connect() Server self-connection test.
|
840 |
+
* @uses MainWP_Child_Server_Information_Base::get_user_agent() Get server user agent.
|
841 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_port() Get server port.
|
842 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_getaway_interface() Get current server gateway interface.
|
843 |
+
* @uses MainWP_Child_Server_Information_Base::memory_usage() Get the current Memory usage.
|
844 |
+
* @uses MainWP_Child_Server_Information_Base::get_complete_url() Get server complete URL.
|
845 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_request_time() Get server request time.
|
846 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_http_accept() Get server HTTP accept.
|
847 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_accept_charset() Get server accepted charset.
|
848 |
+
* @uses MainWP_Child_Server_Information_Base::get_script_file_name() Get server script filename.
|
849 |
+
* @uses MainWP_Child_Server_Information_Base::get_current_page_uri() Get current page URL.
|
850 |
+
* @uses MainWP_Child_Server_Information_Base::get_remote_address() Get server remote address.
|
851 |
+
* @uses MainWP_Child_Server_Information_Base::get_remote_host() Get server remote host.
|
852 |
+
* @uses MainWP_Child_Server_Information_Base::get_remote_port() Get server remote port.
|
853 |
+
*
|
854 |
+
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
855 |
+
*/
|
856 |
+
private static function render_server_infor_rows() {
|
857 |
+
?>
|
858 |
+
<tr>
|
859 |
+
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'SERVER INFORMATION', 'mainwp-child' ); ?></td>
|
860 |
+
</tr>
|
861 |
+
<tr>
|
862 |
+
<td></td>
|
863 |
+
<td><?php esc_html_e( 'WordPress Root Directory', 'mainwp-child' ); ?></td>
|
864 |
+
<td colspan="3"><?php self::get_wp_root(); ?></td>
|
865 |
+
</tr>
|
866 |
+
<tr>
|
867 |
+
<td></td>
|
868 |
+
<td><?php esc_html_e( 'Server Name', 'mainwp-child' ); ?></td>
|
869 |
+
<td colspan="3"><?php self::get_server_name(); ?></td>
|
870 |
+
</tr>
|
871 |
+
<tr>
|
872 |
+
<td></td>
|
873 |
+
<td><?php esc_html_e( 'Server Software', 'mainwp-child' ); ?></td>
|
874 |
+
<td colspan="3"><?php self::get_server_software(); ?></td>
|
875 |
+
</tr>
|
876 |
+
<tr>
|
877 |
+
<td></td>
|
878 |
+
<td><?php esc_html_e( 'Operating System', 'mainwp-child' ); ?></td>
|
879 |
+
<td colspan="3"><?php self::get_os(); ?></td>
|
880 |
+
</tr>
|
881 |
+
<tr>
|
882 |
+
<td></td>
|
883 |
+
<td><?php esc_html_e( 'Architecture', 'mainwp-child' ); ?></td>
|
884 |
+
<td colspan="3"><?php self::get_architecture(); ?></td>
|
885 |
+
</tr>
|
886 |
+
<tr>
|
887 |
+
<td></td>
|
888 |
+
<td><?php esc_html_e( 'Server IP', 'mainwp-child' ); ?></td>
|
889 |
+
<td colspan="3"><?php self::get_server_ip(); ?></td>
|
890 |
+
</tr>
|
891 |
+
<tr>
|
892 |
+
<td></td>
|
893 |
+
<td><?php esc_html_e( 'Server Protocol', 'mainwp-child' ); ?></td>
|
894 |
+
<td colspan="3"><?php self::get_server_protocol(); ?></td>
|
895 |
+
</tr>
|
896 |
+
<tr>
|
897 |
+
<td></td>
|
898 |
+
<td><?php esc_html_e( 'HTTP Host', 'mainwp-child' ); ?></td>
|
899 |
+
<td colspan="3"><?php self::get_http_host(); ?></td>
|
900 |
+
</tr>
|
901 |
+
<tr>
|
902 |
+
<td></td>
|
903 |
+
<td><?php esc_html_e( 'HTTPS', 'mainwp-child' ); ?></td>
|
904 |
+
<td colspan="3"><?php self::get_https(); ?></td>
|
905 |
+
</tr>
|
906 |
+
<tr>
|
907 |
+
<td></td>
|
908 |
+
<td><?php esc_html_e( 'Server self connect', 'mainwp-child' ); ?></td>
|
909 |
+
<td colspan="3"><?php self::server_self_connect(); ?></td>
|
910 |
+
</tr>
|
911 |
+
<tr>
|
912 |
+
<td></td>
|
913 |
+
<td><?php esc_html_e( 'User Agent', 'mainwp-child' ); ?></td>
|
914 |
+
<td colspan="3"><?php self::get_user_agent(); ?></td>
|
915 |
+
</tr>
|
916 |
+
<tr>
|
917 |
+
<td></td>
|
918 |
+
<td><?php esc_html_e( 'Server Port', 'mainwp-child' ); ?></td>
|
919 |
+
<td colspan="3"><?php self::get_server_port(); ?></td>
|
920 |
+
</tr>
|
921 |
+
<tr>
|
922 |
+
<td></td>
|
923 |
+
<td><?php esc_html_e( 'Gateway Interface', 'mainwp-child' ); ?></td>
|
924 |
+
<td colspan="3"><?php self::get_server_getaway_interface(); ?></td>
|
925 |
+
</tr>
|
926 |
+
<tr>
|
927 |
+
<td></td>
|
928 |
+
<td><?php esc_html_e( 'Memory Usage', 'mainwp-child' ); ?></td>
|
929 |
+
<td colspan="3"><?php self::memory_usage(); ?></td>
|
930 |
+
</tr>
|
931 |
+
<tr>
|
932 |
+
<td></td>
|
933 |
+
<td><?php esc_html_e( 'Complete URL', 'mainwp-child' ); ?></td>
|
934 |
+
<td colspan="3"><?php self::get_complete_url(); ?></td>
|
935 |
+
</tr>
|
936 |
+
<tr>
|
937 |
+
<td></td>
|
938 |
+
<td><?php esc_html_e( 'Request Time', 'mainwp-child' ); ?></td>
|
939 |
+
<td colspan="3"><?php self::get_server_request_time(); ?></td>
|
940 |
+
</tr>
|
941 |
+
<tr>
|
942 |
+
<td></td>
|
943 |
+
<td><?php esc_html_e( 'Accept Content', 'mainwp-child' ); ?></td>
|
944 |
+
<td colspan="3"><?php self::get_server_http_accept(); ?></td>
|
945 |
+
</tr>
|
946 |
+
<tr>
|
947 |
+
<td></td>
|
948 |
+
<td><?php esc_html_e( 'Accept-Charset Content', 'mainwp-child' ); ?></td>
|
949 |
+
<td colspan="3"><?php self::get_server_accept_charset(); ?></td>
|
950 |
+
</tr>
|
951 |
+
<tr>
|
952 |
+
<td></td>
|
953 |
+
<td><?php esc_html_e( 'Currently Executing Script Pathname', 'mainwp-child' ); ?></td>
|
954 |
+
<td colspan="3"><?php self::get_script_file_name(); ?></td>
|
955 |
+
</tr>
|
956 |
+
<tr>
|
957 |
+
<td></td>
|
958 |
+
<td><?php esc_html_e( 'Current Page URI', 'mainwp-child' ); ?></td>
|
959 |
+
<td colspan="3"><?php self::get_current_page_uri(); ?></td>
|
960 |
+
</tr>
|
961 |
+
<tr>
|
962 |
+
<td></td>
|
963 |
+
<td><?php esc_html_e( 'Remote Address', 'mainwp-child' ); ?></td>
|
964 |
+
<td colspan="3"><?php self::get_remote_address(); ?></td>
|
965 |
+
</tr>
|
966 |
+
<tr>
|
967 |
+
<td></td>
|
968 |
+
<td><?php esc_html_e( 'Remote Host', 'mainwp-child' ); ?></td>
|
969 |
+
<td colspan="3"><?php self::get_remote_host(); ?></td>
|
970 |
+
</tr>
|
971 |
+
<tr>
|
972 |
+
<td></td>
|
973 |
+
<td><?php esc_html_e( 'Remote Port', 'mainwp-child' ); ?></td>
|
974 |
+
<td colspan="3"><?php self::get_remote_port(); ?></td>
|
975 |
+
</tr>
|
976 |
+
<?php
|
977 |
}
|
978 |
|
979 |
+
/**
|
980 |
+
* Render the MainWP version check.
|
981 |
+
*
|
982 |
+
* @uses MainWP_Child_Server_Information_Base::get_mainwp_version() Get the current MainWP Child plugin version.
|
983 |
+
*
|
984 |
+
* @uses get_option() Retrieves an option value based on an option name.
|
985 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
986 |
+
*
|
987 |
+
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
988 |
+
*/
|
989 |
+
protected static function render_mainwp_version_check() {
|
990 |
$current = get_option( 'mainwp_child_plugin_version' );
|
991 |
+
$latest = self::get_mainwp_version();
|
992 |
if ( $current === $latest ) {
|
993 |
echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>';
|
994 |
} else {
|
996 |
}
|
997 |
}
|
998 |
|
999 |
+
/**
|
1000 |
+
* Render cron schedules.
|
1001 |
+
*
|
1002 |
+
* @uses _get_cron_array() Retrieve cron info array option.
|
1003 |
+
* @see https://developer.wordpress.org/reference/functions/_get_cron_array/
|
1004 |
+
*
|
1005 |
+
* @uses wp_get_schedules() Retrieve supported event recurrence schedules.
|
1006 |
+
* @see https://developer.wordpress.org/reference/functions/wp_get_schedules/
|
1007 |
+
*
|
1008 |
+
* @uses MainWP_Helper::format_timestamp() Format timestamp as per the WordPress general settings.
|
1009 |
+
*
|
1010 |
+
* @used-by MainWP_Child_Server_Information::render_page() Render the Server Information page.
|
1011 |
+
*/
|
1012 |
+
private static function render_cron() {
|
1013 |
$cron_array = _get_cron_array();
|
1014 |
$schedules = wp_get_schedules();
|
1015 |
?>
|
1016 |
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0">
|
1017 |
<thead>
|
1018 |
+
<tr>
|
1019 |
+
<th scope="col" class="manage-column column-posts"><span><?php esc_html_e( 'Next due', 'mainwp-child' ); ?></span></th>
|
1020 |
+
<th scope="col" class="manage-column column-posts"><span><?php esc_html_e( 'Schedule', 'mainwp-child' ); ?></span></th>
|
1021 |
+
<th scope="col" class="manage-column column-posts"><span><?php esc_html_e( 'Hook', 'mainwp-child' ); ?></span></th>
|
1022 |
+
</tr>
|
|
|
|
|
|
|
1023 |
</thead>
|
1024 |
<tbody id="the-sites-list" class="list:sites">
|
1025 |
<?php
|
1028 |
foreach ( $cron_info as $key => $schedule ) {
|
1029 |
?>
|
1030 |
<tr>
|
1031 |
+
<td><?php echo esc_html( MainWP_Helper::format_timestamp( MainWP_Helper::get_timestamp( $time ) ) ); ?></td>
|
1032 |
<td><?php echo esc_html( ( isset( $schedule['schedule'] ) && isset( $schedules[ $schedule['schedule'] ] ) && isset( $schedules[ $schedule['schedule'] ]['display'] ) ) ? $schedules[ $schedule['schedule'] ]['display'] : '' ); ?> </td>
|
1033 |
<td><?php echo esc_html( $hook ); ?></td>
|
1034 |
</tr>
|
1042 |
<?php
|
1043 |
}
|
1044 |
|
1045 |
+
/**
|
1046 |
+
* Render the MainWP directory check.
|
1047 |
+
*
|
1048 |
+
* @uses MainWP_Child_Server_Information_Base::check_mainwp_directory() Check if MainWP Directory is writeable.
|
1049 |
+
* @uses MainWP_Child_Server_Information::render_directory_row() Render the directroy check row.
|
1050 |
+
*
|
1051 |
+
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
1052 |
+
*/
|
1053 |
+
protected static function render_mainwp_directory() {
|
1054 |
+
$branding_title = MainWP_Child_Branding::instance()->get_branding_title();
|
1055 |
+
if ( '' == $branding_title ) {
|
1056 |
+
$branding_title = 'MainWP';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1057 |
}
|
1058 |
+
$branding_title .= ' Upload Directory';
|
1059 |
|
1060 |
+
$path = '';
|
1061 |
+
$message = 'Writable';
|
1062 |
|
1063 |
+
self::check_mainwp_directory( $message, $path );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1064 |
|
1065 |
+
self::render_directory_row( $branding_title, $path, 'Writable', $message, true );
|
|
|
|
|
|
|
|
|
1066 |
}
|
1067 |
|
1068 |
+
/**
|
1069 |
+
* Render the directroy check row.
|
1070 |
+
*
|
1071 |
+
* @param string $name Check name.
|
1072 |
+
* @param string $directory Directory to check.
|
1073 |
+
* @param string $check Check condition.
|
1074 |
+
* @param string $result Check result.
|
1075 |
+
* @param string $passed Show correct label depending on passed status.
|
1076 |
+
*
|
1077 |
+
* @used-by MainWP_Child_Server_Information::render_mainwp_directory() Render the MainWP directory check.
|
1078 |
+
*/
|
1079 |
+
protected static function render_directory_row( $name, $directory, $check, $result, $passed ) {
|
1080 |
?>
|
1081 |
<tr class="mwp-not-generate-row">
|
1082 |
<td></td>
|
1083 |
+
<td><?php echo esc_html( stripslashes( $name ) ); ?><br/><?php echo esc_html( ( MainWP_Child_Branding::instance()->is_branding() ) ? '' : $directory ); ?></td>
|
1084 |
+
<td><?php echo esc_html( $check ); ?></td>
|
1085 |
+
<td><?php echo esc_html( $result ); ?></td>
|
1086 |
+
<td><?php echo ( $passed ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>' ); ?></td>
|
|
|
1087 |
</tr>
|
1088 |
<?php
|
|
|
1089 |
}
|
1090 |
|
1091 |
+
/**
|
1092 |
+
* Render the server information check row.
|
1093 |
+
*
|
1094 |
+
* @param string $config Check name.
|
1095 |
+
* @param string $compare Comparison operator.
|
1096 |
+
* @param string $version Version for comparison.
|
1097 |
+
* @param string $getter Function to call to handle comparison.
|
1098 |
+
* @param string $extra_text Extra text to display in the row.
|
1099 |
+
* @param string $extra_compare Additional comparison operator.
|
1100 |
+
* @param string $extra_version Additional version to compare.
|
1101 |
+
* @param bool $size_compare Determies if size should be compared.
|
1102 |
+
*
|
1103 |
+
* @uses MainWP_Child_Server_Information_Base::check() Check Child Site system variables for any issues.
|
1104 |
+
*
|
1105 |
+
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
1106 |
+
* @used-by MainWP_Child_Server_Information::render_php_settings_rows() Render PHP settings information rows.
|
1107 |
+
* @used-by MainWP_Child_Server_Information::render_mysql_infor_rows() Render MySQL settings information rows.
|
1108 |
+
*/
|
1109 |
+
protected static function render_row( $config, $compare, $version, $getter, $extra_text = '', $extra_compare = null, $extra_version = null, $size_compare = false ) {
|
1110 |
+
$currentVersion = call_user_func( array( self::get_class_name(), $getter ) );
|
1111 |
?>
|
1112 |
<tr>
|
1113 |
<td></td>
|
1114 |
+
<td><?php echo esc_html( esc_html( $config ) ); ?></td>
|
1115 |
+
<td><?php echo esc_html( esc_html( $compare ) ); ?><?php echo esc_html( ( true === $version ? 'true' : $version ) . ' ' . $extra_text ); ?></td>
|
1116 |
<td><?php echo esc_html( true === $currentVersion ? 'true' : $currentVersion ); ?></td>
|
1117 |
+
<td><?php echo ( self::check( $compare, $version, $getter, $extra_compare, $extra_version, $size_compare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>' ); ?></td>
|
1118 |
</tr>
|
1119 |
<?php
|
1120 |
}
|
1121 |
|
1122 |
+
/**
|
1123 |
+
* Render the server information check secondary row.
|
1124 |
+
*
|
1125 |
+
* @param string $config Check name.
|
1126 |
+
* @param string $compare Comparison operator.
|
1127 |
+
* @param string $version Version for comparison.
|
1128 |
+
* @param string $getter Function to call to handle comparison.
|
1129 |
+
* @param string $extra_text Extra text to display in the row.
|
1130 |
+
* @param string $extra_compare Additional comparison operator.
|
1131 |
+
* @param string $extra_version Additional version to compare.
|
1132 |
+
* @param string $toolTip Tooltip to show.
|
1133 |
+
* @param string $whatType What type.
|
1134 |
+
* @param string $errorType Error type.
|
1135 |
+
*
|
1136 |
+
* @used-by MainWP_Child_Server_Information::render_php_settings_rows() Render PHP settings information rows.
|
1137 |
+
*/
|
1138 |
+
protected static function render_row_sec( $config, $compare, $version, $getter, $extra_text = '', $extra_compare = null, $extra_version = null, $toolTip = null, $whatType = null, $errorType = self::WARNING ) {
|
1139 |
+
$currentVersion = call_user_func( array( self::get_class_name(), $getter ) );
|
1140 |
?>
|
1141 |
<tr>
|
1142 |
<td></td>
|
1143 |
+
<td><?php echo $config; ?></td>
|
1144 |
+
<td><?php echo $compare; ?><?php echo ( true === $version ? 'true' : ( is_array( $version ) && isset( $version['version'] ) ? $version['version'] : $version ) ) . ' ' . $extra_text; ?></td>
|
1145 |
+
<td><?php echo( true === $currentVersion ? 'true' : $currentVersion ); ?></td>
|
1146 |
+
<?php if ( 'filesize' === $whatType ) { ?>
|
1147 |
+
<td><?php echo( self::filesize_compare( $currentVersion, $version, $compare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::render_warning_text( $errorType ) ); ?></td>
|
1148 |
+
<?php } elseif ( 'curlssl' === $whatType ) { ?>
|
1149 |
+
<td><?php echo( self::curlssl_compare( $version, $compare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::render_warning_text( $errorType ) ); ?></td>
|
1150 |
+
<?php } elseif ( ( 'get_max_input_time' === $getter || 'get_max_execution_time' === $getter ) && -1 == $currentVersion ) { ?>
|
1151 |
<td><?php echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>'; ?></td>
|
1152 |
<?php } else { ?>
|
1153 |
+
<td><?php echo ( version_compare( $currentVersion, $version, $compare ) || ( ( null != $extra_compare ) && version_compare( $currentVersion, $extra_version, $extra_compare ) ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::render_warning_text( $errorType ) ); ?></td>
|
1154 |
<?php } ?>
|
1155 |
</tr>
|
1156 |
<?php
|
1157 |
}
|
1158 |
|
1159 |
+
/**
|
1160 |
+
* Render warning text.
|
1161 |
+
*
|
1162 |
+
* @param string $errorType Error type.
|
1163 |
+
*
|
1164 |
+
* @used-by MainWP_Child_Server_Information::render_row_sec() Render the server information check secondary row.
|
1165 |
+
*
|
1166 |
+
* @return string Warning message HTML.
|
1167 |
+
*/
|
1168 |
+
public static function render_warning_text( $errorType = self::WARNING ) {
|
1169 |
+
if ( self::WARNING == $errorType ) {
|
1170 |
return '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>';
|
1171 |
}
|
1172 |
return '<span class="mainwp-fail"><i class="fa fa-exclamation-circle"></i> Fail</span>';
|
1173 |
}
|
1174 |
|
1175 |
+
/**
|
1176 |
+
* Render the Error log page.
|
1177 |
+
*
|
1178 |
+
* @uses MainWP_Child_Server_Information::render_error_log() Render the error log content.
|
1179 |
+
*
|
1180 |
+
* @used-by MainWP_Child_Server_Information::render_page() Rener the Server Information page.
|
1181 |
+
*
|
1182 |
+
* Credits
|
1183 |
+
*
|
1184 |
+
* Plugin-Name: Error Log Dashboard Widget
|
1185 |
+
* Plugin URI: http://wordpress.org/extend/plugins/error-log-dashboard-widget/
|
1186 |
+
* Description: Robust zero-configuration and low-memory way to keep an eye on error log.
|
1187 |
+
* Author: Andrey "Rarst" Savchenko
|
1188 |
+
* Author URI: http://www.rarst.net/
|
1189 |
+
* Version: 1.0.2
|
1190 |
+
* License: GPLv2 or later
|
1191 |
+
* Includes last_lines() function by phant0m, licensed under cc-wiki and GPLv2+
|
1192 |
+
*/
|
1193 |
+
private static function render_error_page() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1194 |
?>
|
1195 |
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0">
|
1196 |
<thead title="Click to Toggle" style="cursor: pointer;">
|
1197 |
+
<tr>
|
1198 |
+
<th scope="col" class="manage-column column-posts" style="width: 10%"><?php esc_html_e( 'Time', 'mainwp-child' ); ?></th>
|
1199 |
+
<th scope="col" class="manage-column column-posts"><?php esc_html_e( 'Error', 'mainwp-child' ); ?></th>
|
1200 |
+
</tr>
|
|
|
|
|
1201 |
</thead>
|
1202 |
<tbody class="list:sites" id="mainwp-error-log-table">
|
1203 |
+
<?php self::render_error_log(); ?>
|
1204 |
</tbody>
|
1205 |
</table>
|
1206 |
<?php
|
1207 |
}
|
1208 |
|
1209 |
+
/**
|
1210 |
+
* Render the error log content.
|
1211 |
+
*
|
1212 |
+
* @uses MainWP_Child_Server_Information::render_last_lines() Render the error log last lines.
|
1213 |
+
* @uses wp_kses_post() Sanitizes content for allowed HTML tags for post content.
|
1214 |
+
* @see https://developer.wordpress.org/reference/functions/wp_kses_post/
|
1215 |
+
*
|
1216 |
+
* @used-by MainWP_Child_Server_Information::render_error_page() Render the Error log page.
|
1217 |
+
*/
|
1218 |
+
public static function render_error_log() {
|
1219 |
$log_errors = ini_get( 'log_errors' );
|
1220 |
if ( ! $log_errors ) {
|
1221 |
echo '<tr><td colspan="2">' . esc_html__( 'Error logging disabled.', 'mainwp-child' ) . '</td></tr>';
|
1227 |
$lines = array();
|
1228 |
|
1229 |
foreach ( $logs as $log ) {
|
|
|
1230 |
if ( is_readable( $log ) ) {
|
1231 |
+
$lines = array_merge( $lines, self::render_last_lines( $log, $count ) );
|
1232 |
}
|
1233 |
}
|
1234 |
|
1236 |
$lines = array_filter( $lines );
|
1237 |
|
1238 |
if ( empty( $lines ) ) {
|
1239 |
+
$branding_title = MainWP_Child_Branding::instance()->get_branding_title();
|
1240 |
+
if ( '' == $branding_title ) {
|
1241 |
+
$branding_title = 'MainWP';
|
1242 |
+
}
|
1243 |
+
$msg = esc_html( stripslashes( $branding_title ) ) . ' is unable to find your error logs, please contact your host for server error logs.';
|
1244 |
+
echo '<tr><td colspan="2">' . $msg . '</td></tr>';
|
1245 |
return;
|
1246 |
}
|
1247 |
|
1273 |
echo wp_kses_post( "<tr><td>{$time}</td><td>{$error}</td></tr>" );
|
1274 |
}
|
1275 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1276 |
}
|
1277 |
|
1278 |
+
/**
|
1279 |
+
* Render the error log last lines.
|
1280 |
+
*
|
1281 |
+
* @param string $path Error log path.
|
1282 |
+
* @param int $line_count Line count.
|
1283 |
+
* @param int $block_size Block size.
|
1284 |
+
*
|
1285 |
+
* @return array Selected number of error log records to show.
|
1286 |
+
*/
|
1287 |
+
protected static function render_last_lines( $path, $line_count, $block_size = 512 ) {
|
1288 |
$lines = array();
|
1289 |
|
1290 |
+
// we will always have a fragment of a non-complete line.
|
1291 |
// keep this in here till we have our next entire line.
|
1292 |
$leftover = '';
|
1293 |
|
1294 |
+
// phpcs:disable WordPress.WP.AlternativeFunctions -- to custom read file.
|
1295 |
$fh = fopen( $path, 'r' );
|
1296 |
+
// go to the end of the file.
|
1297 |
fseek( $fh, 0, SEEK_END );
|
1298 |
|
1299 |
+
$count_lines = count( $lines );
|
1300 |
do {
|
1301 |
+
// need to know whether we can actually go back.
|
|
|
1302 |
$can_read = $block_size;
|
1303 |
|
1304 |
if ( ftell( $fh ) <= $block_size ) {
|
1309 |
break;
|
1310 |
}
|
1311 |
|
1312 |
+
// go back as many bytes as we can.
|
1313 |
+
// read them to $data and then move the file pointer.
|
1314 |
// back to where we were.
|
1315 |
fseek( $fh, - $can_read, SEEK_CUR );
|
1316 |
+
$data = fread( $fh, $can_read );
|
1317 |
$data .= $leftover;
|
1318 |
fseek( $fh, - $can_read, SEEK_CUR );
|
1319 |
|
1320 |
+
// split lines by \n. Then reverse them, now the last line is most likely not a complete line which is why we do not directly add it, but append it to the data read the next time.
|
|
|
|
|
|
|
1321 |
$split_data = array_reverse( explode( "\n", $data ) );
|
1322 |
$new_lines = array_slice( $split_data, 0, - 1 );
|
1323 |
$lines = array_merge( $lines, $new_lines );
|
1324 |
$leftover = $split_data[ count( $split_data ) - 1 ];
|
1325 |
+
} while ( $count_lines < $line_count && 0 !== ftell( $fh ) );
|
1326 |
|
1327 |
if ( 0 === ftell( $fh ) ) {
|
1328 |
$lines[] = $leftover;
|
1330 |
|
1331 |
fclose( $fh );
|
1332 |
|
1333 |
+
// phpcs:enable
|
1334 |
+
|
1335 |
// Usually, we will read too many lines, correct that here.
|
1336 |
return array_slice( $lines, 0, $line_count );
|
1337 |
}
|
1338 |
|
1339 |
+
/**
|
1340 |
+
* Render the connection details page content.
|
1341 |
+
*/
|
1342 |
+
public static function render_connection_details() {
|
1343 |
+
$branding_title = MainWP_Child_Branding::instance()->get_branding_title();
|
1344 |
+
if ( '' == $branding_title ) {
|
1345 |
+
$branding_title = 'MainWP';
|
1346 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1347 |
|
1348 |
+
/**
|
1349 |
+
* Current user global.
|
1350 |
+
*
|
1351 |
+
* @global string
|
1352 |
+
*/
|
1353 |
+
global $current_user;
|
1354 |
+
|
1355 |
+
$uniqueId = get_option( 'mainwp_child_uniqueId' );
|
1356 |
+
$details = array(
|
1357 |
+
'siteurl' => array(
|
1358 |
+
'title' => __( 'Site URL', 'mainwp-child' ),
|
1359 |
+
'value' => get_bloginfo( 'url' ),
|
1360 |
+
'desc' => get_bloginfo( 'url' ),
|
1361 |
+
),
|
1362 |
+
'adminuser' => array(
|
1363 |
+
'title' => __( 'Administrator name', 'mainwp-child' ),
|
1364 |
+
'value' => $current_user->user_login,
|
1365 |
+
'desc' => __( 'This is your Administrator username, however, you can use any existing Administrator username.', 'mainwp-child' ),
|
1366 |
+
),
|
1367 |
+
'friendly_name' => array(
|
1368 |
+
'title' => __( 'Friendly site name', 'mainwp-child' ),
|
1369 |
+
'value' => get_bloginfo( 'name' ),
|
1370 |
+
'desc' => __( 'For the friendly site name, you can use any name, this is just a suggestion.', 'mainwp-child' ),
|
1371 |
+
),
|
1372 |
+
'uniqueid' => array(
|
1373 |
+
'title' => __( 'Child unique security id', 'mainwp-child' ),
|
1374 |
+
'value' => ! empty( $uniqueId ) ? $uniqueId : __( 'Leave the field blank', 'mainwp-child' ),
|
1375 |
+
'desc' => sprintf( __( 'Child unique security id is not required, however, since you have enabled it, you need to add it to your %s dashboard.', 'mainwp-child' ), stripslashes( $branding_title ) ),
|
1376 |
+
),
|
1377 |
+
'verify_ssl' => array(
|
1378 |
+
'title' => __( 'Verify certificate', 'mainwp-child' ),
|
1379 |
+
'value' => __( 'Yes', 'mainwp-child' ),
|
1380 |
+
'desc' => __( 'If there is an issue with SSL certificate on this site, try to set this option to No.', 'mainwp-child' ),
|
1381 |
+
),
|
1382 |
+
'ssl_version' => array(
|
1383 |
+
'title' => __( 'SSL version', 'mainwp-child' ),
|
1384 |
+
'value' => __( 'Auto Detect', 'mainwp-child' ),
|
1385 |
+
'desc' => __( 'Auto Detect', 'mainwp-child' ),
|
1386 |
+
),
|
1387 |
|
1388 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1389 |
?>
|
1390 |
<div class="postbox" id="connection_detail">
|
1391 |
<h3 class="mainwp_box_title"><span><?php _e( 'Connection details', 'mainwp-child' ); ?></span></h3>
|
1392 |
<div class="inside">
|
1393 |
+
<div class="mainwp-postbox-actions-top mainwp-padding-5">
|
1394 |
+
<?php echo sprintf( __( 'If you are trying to connect this child site to your %s Dashboard, you can use following details to do that. Please note that these are only suggested values.', 'mainwp-child' ), stripslashes( $branding_title ) ); ?>
|
1395 |
+
</div>
|
1396 |
+
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0" style="border: 0">
|
1397 |
+
<tbody>
|
1398 |
+
<?php
|
1399 |
+
foreach ( $details as $row ) {
|
1400 |
+
?>
|
1401 |
+
<tr>
|
1402 |
+
<th style="width: 20%"><strong><?php echo esc_html( $row['title'] ); ?></strong></th>
|
1403 |
+
<td style="width: 20%"><strong><?php echo esc_html( $row['value'] ); ?></strong></td>
|
1404 |
+
<td><?php echo esc_html( $row['desc'] ); ?></td>
|
1405 |
+
</tr>
|
1406 |
+
<?php
|
1407 |
+
}
|
1408 |
+
?>
|
1409 |
+
</tbody>
|
1410 |
+
</table>
|
|
|
|
|
1411 |
</div>
|
1412 |
</div>
|
1413 |
<?php
|
1414 |
}
|
1415 |
|
1416 |
+
}
|
class/class-mainwp-child-skeleton-key.php
DELETED
@@ -1,242 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
class MainWP_Child_Skeleton_Key {
|
5 |
-
public static $instance = null;
|
6 |
-
public static $information = array();
|
7 |
-
public $plugin_translate = 'mainwp-child';
|
8 |
-
|
9 |
-
static function Instance() {
|
10 |
-
if ( null === MainWP_Child_Skeleton_Key::$instance ) {
|
11 |
-
MainWP_Child_Skeleton_Key::$instance = new MainWP_Child_Skeleton_Key();
|
12 |
-
}
|
13 |
-
|
14 |
-
return MainWP_Child_Skeleton_Key::$instance;
|
15 |
-
}
|
16 |
-
|
17 |
-
public function action() {
|
18 |
-
|
19 |
-
error_reporting( 0 );
|
20 |
-
function mainwp_skeleton_key_handle_fatal_error() {
|
21 |
-
$error = error_get_last();
|
22 |
-
if ( isset( $error['type'] ) && in_array($error['type'], array(1, 4, 16, 64, 256) ) && isset( $error['message'] ) ) {
|
23 |
-
MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
|
24 |
-
}
|
25 |
-
// to fix issue double <mainwp></mainwp> header in response
|
26 |
-
// else {
|
27 |
-
// MainWP_Helper::write( MainWP_Child_Skeleton_Key::$information );
|
28 |
-
// }
|
29 |
-
}
|
30 |
-
|
31 |
-
register_shutdown_function( 'mainwp_skeleton_key_handle_fatal_error' );
|
32 |
-
|
33 |
-
switch ( $_POST['action'] ) {
|
34 |
-
case 'skeleton_key_visit_site_as_browser':
|
35 |
-
$information = $this->visit_site_as_browser();
|
36 |
-
break;
|
37 |
-
case 'save_settings':
|
38 |
-
$information = $this->save_settings();
|
39 |
-
break;
|
40 |
-
default:
|
41 |
-
$information = array( 'error' => 'Unknown action' );
|
42 |
-
}
|
43 |
-
|
44 |
-
MainWP_Helper::write( $information );
|
45 |
-
//MainWP_Child_Skeleton_Key::$information = $information;
|
46 |
-
exit();
|
47 |
-
}
|
48 |
-
|
49 |
-
protected function visit_site_as_browser() {
|
50 |
-
if ( ! isset( $_POST['url'] ) || ! is_string( $_POST['url'] ) || strlen( $_POST['url'] ) < 2 ) {
|
51 |
-
return array( 'error' => 'Missing url' );
|
52 |
-
}
|
53 |
-
|
54 |
-
if ( ! isset( $_POST['args'] ) || ! is_array( $_POST['args'] ) ) {
|
55 |
-
return array( 'error' => 'Missing args' );
|
56 |
-
}
|
57 |
-
|
58 |
-
$_POST = stripslashes_deep( $_POST );
|
59 |
-
|
60 |
-
$args = $_POST['args'];
|
61 |
-
|
62 |
-
$current_user = wp_get_current_user();
|
63 |
-
|
64 |
-
$url = '/' . $_POST['url'];
|
65 |
-
|
66 |
-
$expiration = time() + 600;
|
67 |
-
$manager = WP_Session_Tokens::get_instance( $current_user->ID );
|
68 |
-
$token = $manager->create( $expiration );
|
69 |
-
|
70 |
-
|
71 |
-
$secure = is_ssl();
|
72 |
-
if ( $secure ) {
|
73 |
-
$auth_cookie_name = SECURE_AUTH_COOKIE;
|
74 |
-
$scheme = 'secure_auth';
|
75 |
-
} else {
|
76 |
-
$auth_cookie_name = AUTH_COOKIE;
|
77 |
-
$scheme = 'auth';
|
78 |
-
}
|
79 |
-
$auth_cookie = wp_generate_auth_cookie( $current_user->ID, $expiration, $scheme, $token );
|
80 |
-
$logged_in_cookie = wp_generate_auth_cookie( $current_user->ID, $expiration, 'logged_in', $token );
|
81 |
-
$_COOKIE[ $auth_cookie_name ] = $auth_cookie;
|
82 |
-
$_COOKIE[ LOGGED_IN_COOKIE ] = $logged_in_cookie;
|
83 |
-
$post_args = array();
|
84 |
-
$post_args['body'] = array();
|
85 |
-
$post_args['redirection'] = 5;
|
86 |
-
$post_args['decompress'] = false; // For gzinflate() data error bug
|
87 |
-
$post_args['cookies'] = array(
|
88 |
-
new WP_Http_Cookie( array( 'name' => $auth_cookie_name, 'value' => $auth_cookie ) ),
|
89 |
-
new WP_Http_Cookie( array( 'name' => LOGGED_IN_COOKIE, 'value' => $logged_in_cookie ) ),
|
90 |
-
);
|
91 |
-
|
92 |
-
if ( isset( $args['get'] ) ) {
|
93 |
-
$get_args = $args['get'];
|
94 |
-
parse_str( $args['get'], $get_args );
|
95 |
-
}
|
96 |
-
|
97 |
-
if ( ! isset( $get_args ) || ! is_array( $get_args ) ) {
|
98 |
-
$get_args = array();
|
99 |
-
}
|
100 |
-
|
101 |
-
$get_args['skeleton_keyuse_nonce_key'] = intval( time() );
|
102 |
-
$get_args['skeleton_keyuse_nonce_hmac'] = hash_hmac( 'sha256', $get_args['skeleton_keyuse_nonce_key'], NONCE_KEY );
|
103 |
-
|
104 |
-
$good_nonce = null;
|
105 |
-
if ( isset( $args['nonce'] ) && ! empty( $args['nonce'] ) ) {
|
106 |
-
parse_str( $args['nonce'], $temp_nonce );
|
107 |
-
$good_nonce = $this->wp_create_nonce_recursive( $temp_nonce );
|
108 |
-
$get_args = array_merge( $get_args, $good_nonce );
|
109 |
-
}
|
110 |
-
|
111 |
-
if ( isset( $args['post'] ) ) {
|
112 |
-
parse_str( $args['post'], $temp_post );
|
113 |
-
if ( ! isset( $temp_post ) || ! is_array( $temp_post ) ) {
|
114 |
-
$temp_post = array();
|
115 |
-
}
|
116 |
-
|
117 |
-
if ( ! empty( $good_nonce ) ) {
|
118 |
-
$temp_post = array_merge( $temp_post, $good_nonce );
|
119 |
-
}
|
120 |
-
|
121 |
-
$post_args['body'] = $temp_post;
|
122 |
-
}
|
123 |
-
|
124 |
-
$post_args['timeout'] = 25;
|
125 |
-
|
126 |
-
$full_url = add_query_arg( $get_args, get_site_url() . $url );
|
127 |
-
|
128 |
-
global $mainWPChild;
|
129 |
-
add_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 );
|
130 |
-
|
131 |
-
$response = wp_remote_post( $full_url, $post_args );
|
132 |
-
|
133 |
-
if ( is_wp_error( $response ) ) {
|
134 |
-
return array( 'error' => 'wp_remote_post error: ' . $response->get_error_message() );
|
135 |
-
}
|
136 |
-
|
137 |
-
$received_content = wp_remote_retrieve_body( $response );
|
138 |
-
|
139 |
-
if ( preg_match( '/<mainwp>(.*)<\/mainwp>/', $received_content, $received_result ) > 0 ) {
|
140 |
-
$received_content_mainwp = json_decode( base64_decode( $received_result[1] ), true ); // json format
|
141 |
-
if ( isset( $received_content_mainwp['error'] ) ) {
|
142 |
-
return array( 'error' => $received_content_mainwp['error'] );
|
143 |
-
}
|
144 |
-
}
|
145 |
-
|
146 |
-
$search_ok_counter = 0;
|
147 |
-
$search_fail_counter = 0;
|
148 |
-
|
149 |
-
if ( isset( $args['search']['ok'] ) ) {
|
150 |
-
foreach ( $args['search']['ok'] as $search ) {
|
151 |
-
if ( preg_match( '/' . preg_quote( $search, '/' ) . '/i', $received_content ) ) {
|
152 |
-
++ $search_ok_counter;
|
153 |
-
}
|
154 |
-
}
|
155 |
-
}
|
156 |
-
|
157 |
-
if ( isset( $args['search']['fail'] ) ) {
|
158 |
-
foreach ( $args['search']['fail'] as $search ) {
|
159 |
-
if ( preg_match( '/' . preg_quote( $search, '/' ) . '/i', $received_content ) ) {
|
160 |
-
++ $search_fail_counter;
|
161 |
-
}
|
162 |
-
}
|
163 |
-
}
|
164 |
-
unset( $get_args['skeleton_keyuse_nonce_key'] );
|
165 |
-
unset( $get_args['skeleton_keyuse_nonce_hmac'] );
|
166 |
-
|
167 |
-
return array(
|
168 |
-
'success' => 1,
|
169 |
-
'content' => $received_content,
|
170 |
-
'url' => $full_url,
|
171 |
-
'get' => $get_args,
|
172 |
-
'post' => $post_args['body'],
|
173 |
-
'search_ok_counter' => $search_ok_counter,
|
174 |
-
'search_fail_counter' => $search_fail_counter,
|
175 |
-
);
|
176 |
-
}
|
177 |
-
|
178 |
-
private function wp_create_nonce_recursive( $array ) {
|
179 |
-
foreach ( $array as $key => $value ) {
|
180 |
-
if ( is_array( $array[ $key ] ) ) {
|
181 |
-
$array[ $key ] = $this->wp_create_nonce_recursive( $array[ $key ] );
|
182 |
-
} else {
|
183 |
-
$array[ $key ] = wp_create_nonce( $array[ $key ] );
|
184 |
-
}
|
185 |
-
}
|
186 |
-
|
187 |
-
return $array;
|
188 |
-
}
|
189 |
-
|
190 |
-
public function save_settings() {
|
191 |
-
$settings = isset($_POST['settings']) ? $_POST['settings'] : array();
|
192 |
-
|
193 |
-
if (!is_array($settings) || empty($settings))
|
194 |
-
return array('error' => 'Invalid data. Please check and try again.');
|
195 |
-
|
196 |
-
$whitelist_options = array(
|
197 |
-
'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG' ),
|
198 |
-
);
|
199 |
-
|
200 |
-
if ( !is_multisite() ) {
|
201 |
-
if ( !defined( 'WP_SITEURL' ) )
|
202 |
-
$whitelist_options['general'][] = 'siteurl';
|
203 |
-
if ( !defined( 'WP_HOME' ) )
|
204 |
-
$whitelist_options['general'][] = 'home';
|
205 |
-
|
206 |
-
$whitelist_options['general'][] = 'admin_email';
|
207 |
-
$whitelist_options['general'][] = 'users_can_register';
|
208 |
-
$whitelist_options['general'][] = 'default_role';
|
209 |
-
}
|
210 |
-
|
211 |
-
//$whitelist_options = apply_filters( 'whitelist_options', $whitelist_options );
|
212 |
-
$whitelist_general = $whitelist_options[ 'general' ];
|
213 |
-
|
214 |
-
// Handle translation install.
|
215 |
-
if ( ! empty( $settings['WPLANG'] ) ) {
|
216 |
-
require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
|
217 |
-
if ( wp_can_install_language_pack() ) {
|
218 |
-
$language = wp_download_language_pack( $settings['WPLANG'] );
|
219 |
-
if ( $language ) {
|
220 |
-
$settings['WPLANG'] = $language;
|
221 |
-
}
|
222 |
-
}
|
223 |
-
}
|
224 |
-
|
225 |
-
$updated = false;
|
226 |
-
foreach($settings as $option => $value) {
|
227 |
-
if (in_array($option, $whitelist_general)) {
|
228 |
-
if ( ! is_array( $value ) )
|
229 |
-
$value = trim( $value );
|
230 |
-
$value = wp_unslash( $value );
|
231 |
-
update_option($option, $value);
|
232 |
-
$updated = true;
|
233 |
-
}
|
234 |
-
}
|
235 |
-
|
236 |
-
if (!$updated)
|
237 |
-
return false;
|
238 |
-
|
239 |
-
return array('result' => 'ok');
|
240 |
-
}
|
241 |
-
|
242 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class/class-mainwp-child-staging.php
CHANGED
@@ -1,6 +1,12 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
*
|
5 |
* Credits
|
6 |
*
|
@@ -12,388 +18,579 @@
|
|
12 |
*
|
13 |
* The code is used for the MainWP Staging Extension
|
14 |
* Extension URL: https://mainwp.com/extension/staging/
|
15 |
-
|
16 |
-
|
|
|
17 |
|
|
|
18 |
|
|
|
|
|
|
|
|
|
|
|
19 |
class MainWP_Child_Staging {
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
}
|
38 |
|
39 |
-
|
40 |
-
|
|
|
41 |
|
42 |
-
|
43 |
-
|
44 |
|
45 |
|
|
|
|
|
|
|
46 |
public function init() {
|
47 |
-
if ( get_option( 'mainwp_wp_staging_ext_enabled' )
|
48 |
-
|
|
|
49 |
|
50 |
-
|
51 |
-
|
|
|
52 |
|
53 |
-
if ( get_option( 'mainwp_wp_staging_hide_plugin' )
|
54 |
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
55 |
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
56 |
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
57 |
-
|
58 |
}
|
59 |
}
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
return $information;
|
70 |
}
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
151 |
MainWP_Helper::update_option( 'mainwp_wp_staging_hide_plugin', $hide, 'yes' );
|
152 |
$information['result'] = 'SUCCESS';
|
153 |
return $information;
|
154 |
}
|
155 |
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
|
|
|
|
|
|
|
|
171 |
'optimizer',
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
$scan->start();
|
196 |
-
|
197 |
-
// Get Options
|
198 |
-
$options = $scan->getOptions();
|
199 |
-
|
200 |
-
$return = array(
|
201 |
-
'options' => serialize($options),
|
202 |
-
'directoryListing' => $scan->directoryListing(),
|
203 |
-
'prefix' => WPStaging\WPStaging::getTablePrefix()
|
204 |
-
);
|
205 |
-
return $return;
|
206 |
-
}
|
207 |
-
|
208 |
-
|
209 |
-
public function ajaxCheckCloneName() {
|
210 |
-
$cloneName = sanitize_key( $_POST["cloneID"] );
|
211 |
-
$cloneNameLength = strlen( $cloneName );
|
212 |
-
$clones = get_option( "wpstg_existing_clones_beta", array() );
|
213 |
-
|
214 |
-
// Check clone name length
|
215 |
-
if( $cloneNameLength < 1 || $cloneNameLength > 16 ) {
|
216 |
-
echo array(
|
217 |
-
"status" => "failed",
|
218 |
-
"message" => "Clone name must be between 1 - 16 characters"
|
219 |
-
);
|
220 |
-
} elseif( array_key_exists( $cloneName, $clones ) ) {
|
221 |
-
return array(
|
222 |
-
"status" => "failed",
|
223 |
-
"message" => "Clone name is already in use, please choose an another clone name"
|
224 |
-
);
|
225 |
-
}
|
226 |
-
|
227 |
-
return array("status" => "success");
|
228 |
-
}
|
229 |
-
|
230 |
-
public function ajaxStartClone() {
|
231 |
-
|
232 |
-
$this->url = ''; // to fix warning
|
233 |
-
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
|
234 |
-
|
235 |
-
|
236 |
-
if( !$cloning->save() ) {
|
237 |
-
return;
|
238 |
-
}
|
239 |
-
|
240 |
-
ob_start();
|
241 |
-
require_once WPSTG_PLUGIN_DIR . "apps/Backend/views/clone/ajax/start.php";
|
242 |
-
$result = ob_get_clean();
|
243 |
-
return $result;
|
244 |
-
}
|
245 |
-
|
246 |
-
public function ajaxCloneDatabase() {
|
247 |
-
|
248 |
-
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
|
249 |
-
|
250 |
-
return $cloning->start();
|
251 |
-
}
|
252 |
-
|
253 |
-
/**
|
254 |
-
* Ajax Prepare Directories (get listing of files)
|
255 |
-
*/
|
256 |
-
public function ajaxPrepareDirectories() {
|
257 |
-
|
258 |
-
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
|
259 |
-
|
260 |
-
return $cloning->start();
|
261 |
-
}
|
262 |
-
|
263 |
-
/**
|
264 |
-
* Ajax Clone Files
|
265 |
-
*/
|
266 |
-
public function ajaxCopyFiles() {
|
267 |
-
|
268 |
-
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
|
269 |
-
|
270 |
-
return $cloning->start();
|
271 |
-
}
|
272 |
-
|
273 |
-
/**
|
274 |
-
* Ajax Replace Data
|
275 |
-
*/
|
276 |
-
public function ajaxReplaceData() {
|
277 |
-
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
|
278 |
-
return $cloning->start();
|
279 |
-
}
|
280 |
-
|
281 |
-
/**
|
282 |
-
* Ajax Finish
|
283 |
-
*/
|
284 |
-
public function ajaxFinish() {
|
285 |
-
|
286 |
-
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
|
287 |
-
$this->url = ''; // to fix warning
|
288 |
-
$return = $cloning->start();
|
289 |
-
$return->blogInfoName = get_bloginfo("name");
|
290 |
-
|
291 |
-
return $return;
|
292 |
-
}
|
293 |
-
|
294 |
-
/**
|
295 |
-
* Ajax Delete Confirmation
|
296 |
-
*/
|
297 |
-
public function ajaxDeleteConfirmation() {
|
298 |
-
|
299 |
-
$delete = new WPStaging\Backend\Modules\Jobs\Delete();
|
300 |
-
$delete->setData();
|
301 |
-
$clone = $delete->getClone();
|
302 |
-
$result = array(
|
303 |
-
'clone' => $clone,
|
304 |
-
'deleteTables' => $delete->getTables()
|
305 |
-
);
|
306 |
-
return $result;
|
307 |
-
}
|
308 |
-
|
309 |
-
/**
|
310 |
-
* Delete clone
|
311 |
-
*/
|
312 |
-
public function ajaxDeleteClone() {
|
313 |
-
|
314 |
-
$delete = new WPStaging\Backend\Modules\Jobs\Delete();
|
315 |
-
return $delete->start();
|
316 |
-
}
|
317 |
-
|
318 |
-
/**
|
319 |
-
* Delete clone
|
320 |
-
*/
|
321 |
-
public function ajaxCancelClone() {
|
322 |
-
$cancel = new WPStaging\Backend\Modules\Jobs\Cancel();
|
323 |
-
return $cancel->start();
|
324 |
-
}
|
325 |
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
|
331 |
-
|
332 |
-
|
333 |
-
|
|
|
|
|
|
|
|
|
|
|
334 |
|
335 |
-
|
336 |
-
|
|
|
|
|
|
|
337 |
}
|
338 |
|
339 |
ob_start();
|
340 |
-
|
|
|
|
|
|
|
|
|
341 |
$result = ob_get_clean();
|
342 |
return $result;
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
397 |
foreach ( $plugins as $key => $value ) {
|
398 |
$plugin_slug = basename( $key, '.php' );
|
399 |
if ( 'wp-staging' === $plugin_slug ) {
|
@@ -404,38 +601,55 @@ class MainWP_Child_Staging {
|
|
404 |
return $plugins;
|
405 |
}
|
406 |
|
|
|
|
|
|
|
407 |
public function remove_menu() {
|
408 |
-
|
409 |
-
$pos = stripos( $_SERVER['REQUEST_URI'], 'admin.php?page=wpstg_clone' );
|
410 |
if ( false !== $pos ) {
|
411 |
-
|
412 |
exit();
|
413 |
}
|
414 |
}
|
415 |
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
|
421 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
if ( isset( $_POST['mainwpsignature'] ) ) {
|
423 |
return $value;
|
424 |
}
|
425 |
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
|
430 |
if ( isset( $value->response['wp-staging/wp-staging.php'] ) ) {
|
431 |
unset( $value->response['wp-staging/wp-staging.php'] );
|
432 |
}
|
433 |
|
434 |
-
|
435 |
unset( $value->response['wp-staging-pro/wp-staging-pro.php'] );
|
436 |
}
|
437 |
|
438 |
return $value;
|
439 |
}
|
440 |
}
|
441 |
-
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Staging.
|
4 |
+
*
|
5 |
+
* MainWP Staging Extension handler.
|
6 |
+
*
|
7 |
+
* @link https://mainwp.com/extension/staging/
|
8 |
+
*
|
9 |
+
* @package MainWP\Child
|
10 |
*
|
11 |
* Credits
|
12 |
*
|
18 |
*
|
19 |
* The code is used for the MainWP Staging Extension
|
20 |
* Extension URL: https://mainwp.com/extension/staging/
|
21 |
+
*/
|
22 |
+
|
23 |
+
namespace MainWP\Child;
|
24 |
|
25 |
+
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- Required to achieve desired results. Pull requests appreciated.
|
26 |
|
27 |
+
/**
|
28 |
+
* Class MainWP_Child_Staging
|
29 |
+
*
|
30 |
+
* MainWP Staging Extension handler.
|
31 |
+
*/
|
32 |
class MainWP_Child_Staging {
|
33 |
|
34 |
+
/**
|
35 |
+
* Public static variable to hold the single instance of the class.
|
36 |
+
*
|
37 |
+
* @var mixed Default null
|
38 |
+
*/
|
39 |
+
public static $instance = null;
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Public variable to hold the information if the WP Staging plugin is installed on the child site.
|
43 |
+
*
|
44 |
+
* @var bool If WP Staging intalled, return true, if not, return false.
|
45 |
+
*/
|
46 |
+
public $is_plugin_installed = false;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Create a public static instance of MainWP_Child_Staging.
|
50 |
+
*
|
51 |
+
* @return MainWP_Child_Staging|null
|
52 |
+
*/
|
53 |
+
public static function instance() {
|
54 |
+
if ( null === self::$instance ) {
|
55 |
+
self::$instance = new self();
|
56 |
+
}
|
57 |
+
return self::$instance;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* MainWP_Child_Staging constructor.
|
62 |
+
*
|
63 |
+
* Run any time class is called.
|
64 |
+
*/
|
65 |
+
public function __construct() {
|
66 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
67 |
+
if ( is_plugin_active( 'wp-staging/wp-staging.php' ) && defined( 'WPSTG_PLUGIN_DIR' ) ) {
|
68 |
+
$this->is_plugin_installed = true;
|
69 |
+
} elseif ( is_plugin_active( 'wp-staging-pro/wp-staging-pro.php' ) ) {
|
70 |
+
$this->is_plugin_installed = true;
|
71 |
}
|
72 |
|
73 |
+
if ( ! $this->is_plugin_installed ) {
|
74 |
+
return;
|
75 |
+
}
|
76 |
|
77 |
+
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
78 |
+
}
|
79 |
|
80 |
|
81 |
+
/**
|
82 |
+
* Initiate actions & filters.
|
83 |
+
*/
|
84 |
public function init() {
|
85 |
+
if ( 'Y' !== get_option( 'mainwp_wp_staging_ext_enabled' ) ) {
|
86 |
+
return;
|
87 |
+
}
|
88 |
|
89 |
+
if ( ! $this->is_plugin_installed ) {
|
90 |
+
return;
|
91 |
+
}
|
92 |
|
93 |
+
if ( 'hide' === get_option( 'mainwp_wp_staging_hide_plugin' ) ) {
|
94 |
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
95 |
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
96 |
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
97 |
+
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );
|
98 |
}
|
99 |
}
|
100 |
|
101 |
+
/**
|
102 |
+
* Sync others data.
|
103 |
+
*
|
104 |
+
* Get an array of available clones of this Child Sites.
|
105 |
+
*
|
106 |
+
* @param array $information Holder for available clones.
|
107 |
+
* @param array $data Array of existing clones.
|
108 |
+
*
|
109 |
+
* @uses MainWP_Child_Staging::get_sync_data()
|
110 |
+
*
|
111 |
+
* @return array $information An array of available clones.
|
112 |
+
*/
|
113 |
+
public function sync_others_data( $information, $data = array() ) {
|
114 |
+
if ( isset( $data['syncWPStaging'] ) && $data['syncWPStaging'] ) {
|
115 |
+
try {
|
116 |
+
$information['syncWPStaging'] = $this->get_sync_data();
|
117 |
+
} catch ( \Exception $e ) {
|
118 |
+
// ok!
|
119 |
+
}
|
120 |
+
}
|
121 |
return $information;
|
122 |
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Fires off MainWP_Child_Staging::get_overview().
|
126 |
+
*
|
127 |
+
* @uses MainWP_Child_Staging::get_overview()
|
128 |
+
* @return array An array of available clones.
|
129 |
+
*/
|
130 |
+
public function get_sync_data() {
|
131 |
+
return $this->get_overview();
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* Fires of certain WP Staging plugin actions.
|
136 |
+
*
|
137 |
+
* @uses \WPStaging\WPStaging::getInstance()
|
138 |
+
* @uses MainWP_Helper::update_option
|
139 |
+
* @uses MainWP_Child_Staging::set_showhide()
|
140 |
+
* @uses MainWP_Child_Staging::save_settings()
|
141 |
+
* @uses MainWP_Child_Staging::get_overview()
|
142 |
+
* @uses MainWP_Child_Staging::get_scan()
|
143 |
+
* @uses MainWP_Child_Staging::ajax_check_free_space()
|
144 |
+
* @uses MainWP_Child_Staging::ajax_check_clone_name()
|
145 |
+
* @uses MainWP_Child_Staging::ajax_start_clone()
|
146 |
+
* @uses MainWP_Child_Staging::ajax_clone_database()
|
147 |
+
* @uses MainWP_Child_Staging::ajax_prepare_directories()
|
148 |
+
* @uses MainWP_Child_Staging::ajax_copy_files()
|
149 |
+
* @uses MainWP_Child_Staging::ajax_replace_data()
|
150 |
+
* @uses MainWP_Child_Staging::ajax_finish()
|
151 |
+
* @uses MainWP_Child_Staging::ajax_delete_confirmation()
|
152 |
+
* @uses MainWP_Child_Staging::ajax_delete_clone()
|
153 |
+
* @uses MainWP_Child_Staging::ajax_cancel_clone()
|
154 |
+
* @uses MainWP_Child_Staging::ajax_update_process()
|
155 |
+
* @uses MainWP_Child_Staging::ajax_cancel_update()
|
156 |
+
* @uses MainWP_Child_Staging::MainWP_Helper::write()
|
157 |
+
*/
|
158 |
+
public function action() { // phpcs:ignore -- ignore complex method notice.
|
159 |
+
if ( ! $this->is_plugin_installed ) {
|
160 |
+
MainWP_Helper::write( array( 'error' => __( 'Please install WP Staging plugin on child website', 'mainwp-child' ) ) );
|
161 |
+
}
|
162 |
+
|
163 |
+
if ( ! class_exists( '\WPStaging\WPStaging' ) ) {
|
164 |
+
if ( file_exists( WPSTG_PLUGIN_DIR . 'app/Core/WPStaging.php' ) ) {
|
165 |
+
require_once WPSTG_PLUGIN_DIR . 'app/Core/WPStaging.php';
|
166 |
+
} elseif ( file_exists( WPSTG_PLUGIN_DIR . 'Core/WPStaging.php' ) ) {
|
167 |
+
require_once WPSTG_PLUGIN_DIR . 'Core/WPStaging.php';
|
168 |
+
}
|
169 |
+
}
|
170 |
+
|
171 |
+
\WPStaging\WPStaging::getInstance();
|
172 |
+
$information = array();
|
173 |
+
|
174 |
+
if ( 'Y' !== get_option( 'mainwp_wp_staging_ext_enabled' ) ) {
|
175 |
+
MainWP_Helper::update_option( 'mainwp_wp_staging_ext_enabled', 'Y', 'yes' );
|
176 |
+
}
|
177 |
+
|
178 |
+
if ( isset( $_POST['mwp_action'] ) ) {
|
179 |
+
$mwp_action = ! empty( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
180 |
+
switch ( $mwp_action ) {
|
181 |
+
case 'set_showhide':
|
182 |
+
$information = $this->set_showhide();
|
183 |
+
break;
|
184 |
+
case 'save_settings':
|
185 |
+
$information = $this->save_settings();
|
186 |
+
break;
|
187 |
+
case 'get_overview':
|
188 |
+
$information = $this->get_overview();
|
189 |
+
break;
|
190 |
+
case 'get_scan':
|
191 |
+
$information = $this->get_scan();
|
192 |
+
break;
|
193 |
+
case 'check_disk_space':
|
194 |
+
$information = $this->ajax_check_free_space();
|
195 |
+
break;
|
196 |
+
case 'check_clone':
|
197 |
+
$information = $this->ajax_check_clone_name();
|
198 |
+
break;
|
199 |
+
case 'start_clone':
|
200 |
+
$information = $this->ajax_start_clone();
|
201 |
+
break;
|
202 |
+
case 'clone_database':
|
203 |
+
$information = $this->ajax_clone_database();
|
204 |
+
break;
|
205 |
+
case 'prepare_directories':
|
206 |
+
$information = $this->ajax_prepare_directories();
|
207 |
+
break;
|
208 |
+
case 'copy_files':
|
209 |
+
$information = $this->ajax_copy_files();
|
210 |
+
break;
|
211 |
+
case 'replace_data':
|
212 |
+
$information = $this->ajax_replace_data();
|
213 |
+
break;
|
214 |
+
case 'clone_finish':
|
215 |
+
$information = $this->ajax_finish();
|
216 |
+
break;
|
217 |
+
case 'delete_confirmation':
|
218 |
+
$information = $this->ajax_delete_confirmation();
|
219 |
+
break;
|
220 |
+
case 'delete_clone':
|
221 |
+
$information = $this->ajax_delete_clone();
|
222 |
+
break;
|
223 |
+
case 'cancel_clone':
|
224 |
+
$information = $this->ajax_cancel_clone();
|
225 |
+
break;
|
226 |
+
case 'staging_update':
|
227 |
+
$information = $this->ajax_update_process();
|
228 |
+
break;
|
229 |
+
case 'cancel_update':
|
230 |
+
$information = $this->ajax_cancel_update();
|
231 |
+
break;
|
232 |
+
}
|
233 |
+
}
|
234 |
+
MainWP_Helper::write( $information );
|
235 |
+
}
|
236 |
+
|
237 |
+
/**
|
238 |
+
* Sets whether or not to hide the WP Staging Plugin.
|
239 |
+
*
|
240 |
+
* @return array $information Action result.
|
241 |
+
*/
|
242 |
+
public function set_showhide() {
|
243 |
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
244 |
MainWP_Helper::update_option( 'mainwp_wp_staging_hide_plugin', $hide, 'yes' );
|
245 |
$information['result'] = 'SUCCESS';
|
246 |
return $information;
|
247 |
}
|
248 |
|
249 |
+
/**
|
250 |
+
* Save WP Staging settings.
|
251 |
+
*
|
252 |
+
* @return string[] Return 'Success'.
|
253 |
+
*/
|
254 |
+
public function save_settings() {
|
255 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
256 |
+
$filters = array(
|
257 |
+
'queryLimit',
|
258 |
+
'fileLimit',
|
259 |
+
'batchSize',
|
260 |
+
'cpuLoad',
|
261 |
+
'delayRequests',
|
262 |
+
'disableAdminLogin',
|
263 |
+
'querySRLimit',
|
264 |
+
'maxFileSize',
|
265 |
+
'debugMode',
|
266 |
+
'unInstallOnDelete',
|
267 |
+
'checkDirectorySize',
|
268 |
'optimizer',
|
269 |
+
);
|
270 |
+
|
271 |
+
$save_fields = array();
|
272 |
+
foreach ( $filters as $field ) {
|
273 |
+
if ( isset( $settings[ $field ] ) ) {
|
274 |
+
$save_fields[ $field ] = $settings[ $field ];
|
275 |
+
}
|
276 |
+
}
|
277 |
+
update_option( 'wpstg_settings', $save_fields );
|
278 |
+
return array( 'result' => 'success' );
|
279 |
+
}
|
280 |
+
|
281 |
+
/**
|
282 |
+
* Get array of available clones.
|
283 |
+
*
|
284 |
+
* @return array $return Action result.
|
285 |
+
*/
|
286 |
+
public function get_overview() {
|
287 |
+
$return = array(
|
288 |
+
'availableClones' => get_option( 'wpstg_existing_clones_beta', array() ),
|
289 |
+
);
|
290 |
+
return $return;
|
291 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
|
293 |
+
/**
|
294 |
+
* Get WP Staging Jobs.
|
295 |
+
*
|
296 |
+
* @uses WPStaging\Backend\Modules\Jobs\Scan::start()
|
297 |
+
* @uses WPStaging\Backend\Modules\Jobs\Scan::getOptions()
|
298 |
+
*
|
299 |
+
* @return array $return Action result.
|
300 |
+
*/
|
301 |
+
public function get_scan() {
|
302 |
+
$scan = new \WPStaging\Backend\Modules\Jobs\Scan();
|
303 |
+
$scan->start();
|
304 |
+
|
305 |
+
$options = $scan->getOptions();
|
306 |
+
|
307 |
+
$return = array(
|
308 |
+
'options' => serialize( $options ), // phpcs:ignore -- to compatible http encoding.
|
309 |
+
'directoryListing' => $scan->directoryListing(),
|
310 |
+
'prefix' => \WPStaging\WPStaging::getTablePrefix(),
|
311 |
+
);
|
312 |
+
return $return;
|
313 |
+
}
|
314 |
+
|
315 |
+
|
316 |
+
/**
|
317 |
+
* Check if clone name already exists & it's length.
|
318 |
+
*
|
319 |
+
* @return array|string[] Action result array[status, message] or return 'success'.
|
320 |
+
*/
|
321 |
+
public function ajax_check_clone_name() {
|
322 |
+
$cloneName = isset( $_POST['cloneID'] ) ? sanitize_key( wp_unslash( $_POST['cloneID'] ) ) : '';
|
323 |
+
$cloneNameLength = strlen( $cloneName );
|
324 |
+
$clones = get_option( 'wpstg_existing_clones_beta', array() );
|
325 |
+
|
326 |
+
if ( $cloneNameLength < 1 || $cloneNameLength > 16 ) {
|
327 |
+
echo array(
|
328 |
+
'status' => 'failed',
|
329 |
+
'message' => 'Clone name must be between 1 - 16 characters',
|
330 |
+
);
|
331 |
+
} elseif ( array_key_exists( $cloneName, $clones ) ) {
|
332 |
+
return array(
|
333 |
+
'status' => 'failed',
|
334 |
+
'message' => 'Clone name is already in use, please choose an another clone name',
|
335 |
+
);
|
336 |
+
}
|
337 |
+
|
338 |
+
return array( 'status' => 'success' );
|
339 |
+
}
|
340 |
|
341 |
+
/**
|
342 |
+
* Start clone via ajax.
|
343 |
+
*
|
344 |
+
* @uses WPStaging\Backend\Modules\Jobs\Cloning::save()
|
345 |
+
*
|
346 |
+
* @return false|string|void Return FALSE on failure, ajax response string on success, ELSE returns VOID.
|
347 |
+
*/
|
348 |
+
public function ajax_start_clone() {
|
349 |
|
350 |
+
$this->url = '';
|
351 |
+
$cloning = new \WPStaging\Backend\Modules\Jobs\Cloning();
|
352 |
+
|
353 |
+
if ( ! $cloning->save() ) {
|
354 |
+
return;
|
355 |
}
|
356 |
|
357 |
ob_start();
|
358 |
+
if ( file_exists( WPSTG_PLUGIN_DIR . 'app/Backend/views/clone/ajax/start.php' ) ) {
|
359 |
+
require_once WPSTG_PLUGIN_DIR . 'app/Backend/views/clone/ajax/start.php';
|
360 |
+
} elseif ( file_exists( WPSTG_PLUGIN_DIR . 'Backend/views/clone/ajax/start.php' ) ) {
|
361 |
+
require_once WPSTG_PLUGIN_DIR . 'Backend/views/clone/ajax/start.php';
|
362 |
+
}
|
363 |
$result = ob_get_clean();
|
364 |
return $result;
|
365 |
+
}
|
366 |
+
|
367 |
+
/**
|
368 |
+
* Clone database via ajax.
|
369 |
+
*
|
370 |
+
* @uses WPStaging\Backend\Modules\Jobs\Cloning::start()
|
371 |
+
*
|
372 |
+
* @return mixed Action result.
|
373 |
+
*/
|
374 |
+
public function ajax_clone_database() {
|
375 |
+
$cloning = new \WPStaging\Backend\Modules\Jobs\Cloning();
|
376 |
+
return $cloning->start();
|
377 |
+
}
|
378 |
+
|
379 |
+
/**
|
380 |
+
* Ajax Prepare Directories (get listing of files).
|
381 |
+
*
|
382 |
+
* @uses WPStaging\Backend\Modules\Jobs\Cloning::start()
|
383 |
+
*
|
384 |
+
* @return mixed Action result.
|
385 |
+
*/
|
386 |
+
public function ajax_prepare_directories() {
|
387 |
+
$cloning = new \WPStaging\Backend\Modules\Jobs\Cloning();
|
388 |
+
return $cloning->start();
|
389 |
+
}
|
390 |
+
|
391 |
+
/**
|
392 |
+
* Ajax Clone Files.
|
393 |
+
*
|
394 |
+
* @uses WPStaging\Backend\Modules\Jobs\Cloning::start()
|
395 |
+
*
|
396 |
+
* @return mixed Action result.
|
397 |
+
*/
|
398 |
+
public function ajax_copy_files() {
|
399 |
+
$cloning = new \WPStaging\Backend\Modules\Jobs\Cloning();
|
400 |
+
return $cloning->start();
|
401 |
+
}
|
402 |
+
|
403 |
+
/**
|
404 |
+
* Ajax Replace Data.
|
405 |
+
*
|
406 |
+
* @uses WPStaging\Backend\Modules\Jobs\Cloning::start()
|
407 |
+
*
|
408 |
+
* @return mixed Action result.
|
409 |
+
*/
|
410 |
+
public function ajax_replace_data() {
|
411 |
+
$cloning = new \WPStaging\Backend\Modules\Jobs\Cloning();
|
412 |
+
return $cloning->start();
|
413 |
+
}
|
414 |
+
|
415 |
+
/**
|
416 |
+
* Ajax Finish
|
417 |
+
*
|
418 |
+
* @uses WPStaging\Backend\Modules\Jobs\Cloning::start()
|
419 |
+
*
|
420 |
+
* @return mixed $return Action result.
|
421 |
+
*/
|
422 |
+
public function ajax_finish() {
|
423 |
+
$cloning = new \WPStaging\Backend\Modules\Jobs\Cloning();
|
424 |
+
$this->url = '';
|
425 |
+
$return = $cloning->start();
|
426 |
+
$return->blogInfoName = get_bloginfo( 'name' );
|
427 |
+
|
428 |
+
return $return;
|
429 |
+
}
|
430 |
+
|
431 |
+
/**
|
432 |
+
* Ajax Delete Confirmation.
|
433 |
+
*
|
434 |
+
* @uses WPStaging\Backend\Modules\Jobs\Delete::getClone()
|
435 |
+
* @uses WPStaging\Backend\Modules\Jobs\Delete::getClone()
|
436 |
+
*
|
437 |
+
* @return array $result Action result.
|
438 |
+
*/
|
439 |
+
public function ajax_delete_confirmation() {
|
440 |
+
$delete = new \WPStaging\Backend\Modules\Jobs\Delete();
|
441 |
+
$delete->setData();
|
442 |
+
$clone = $delete->getClone();
|
443 |
+
$result = array(
|
444 |
+
'clone' => $clone,
|
445 |
+
'deleteTables' => $delete->getTables(),
|
446 |
+
);
|
447 |
+
|
448 |
+
return $result;
|
449 |
+
}
|
450 |
+
|
451 |
+
/**
|
452 |
+
* Ajax Delete clone.
|
453 |
+
*
|
454 |
+
* @uses WPStaging\Backend\Modules\Jobs\Delete::start()
|
455 |
+
*
|
456 |
+
* @return mixed Action result.
|
457 |
+
*/
|
458 |
+
public function ajax_delete_clone() {
|
459 |
+
$delete = new \WPStaging\Backend\Modules\Jobs\Delete();
|
460 |
+
|
461 |
+
return $delete->start();
|
462 |
+
}
|
463 |
+
|
464 |
+
/**
|
465 |
+
* Ajax Cancel clone.
|
466 |
+
*
|
467 |
+
* @uses WPStaging\Backend\Modules\Jobs\Cancel::start()
|
468 |
+
*/
|
469 |
+
public function ajax_cancel_clone() {
|
470 |
+
$cancel = new \WPStaging\Backend\Modules\Jobs\Cancel();
|
471 |
+
|
472 |
+
return $cancel->start();
|
473 |
+
}
|
474 |
+
|
475 |
+
/**
|
476 |
+
* Ajax Cancel Update.
|
477 |
+
*
|
478 |
+
* @uses WPStaging\Backend\Modules\Jobs\CancelUpdate::start()
|
479 |
+
*
|
480 |
+
* @return mixed Action result.
|
481 |
+
*/
|
482 |
+
public function ajax_cancel_update() {
|
483 |
+
$cancel = new \WPStaging\Backend\Modules\Jobs\CancelUpdate();
|
484 |
+
|
485 |
+
return $cancel->start();
|
486 |
+
}
|
487 |
+
|
488 |
+
/**
|
489 |
+
* Ajax Update Process.
|
490 |
+
*
|
491 |
+
* @uses WPStaging\Backend\Modules\Jobs\Updating::save()
|
492 |
+
*
|
493 |
+
* @return false|string|void Return FALSE on failure, ajax response string on success, ELSE returns VOID.
|
494 |
+
*/
|
495 |
+
public function ajax_update_process() {
|
496 |
+
$cloning = new \WPStaging\Backend\Modules\Jobs\Updating();
|
497 |
+
|
498 |
+
if ( ! $cloning->save() ) {
|
499 |
+
return;
|
500 |
+
}
|
501 |
+
|
502 |
+
ob_start();
|
503 |
+
if ( file_exists( WPSTG_PLUGIN_DIR . 'app/Backend/views/clone/ajax/update.php' ) ) {
|
504 |
+
require_once WPSTG_PLUGIN_DIR . 'app/Backend/views/clone/ajax/update.php';
|
505 |
+
} elseif ( file_exists( WPSTG_PLUGIN_DIR . 'Backend/views/clone/ajax/update.php' ) ) {
|
506 |
+
require_once WPSTG_PLUGIN_DIR . 'Backend/views/clone/ajax/update.php';
|
507 |
+
}
|
508 |
+
$result = ob_get_clean();
|
509 |
+
return $result;
|
510 |
+
}
|
511 |
+
|
512 |
+
/**
|
513 |
+
* Ajax check for free disk space.
|
514 |
+
*
|
515 |
+
* @uses MainWP_Child_Staging::has_free_disk_space()
|
516 |
+
*
|
517 |
+
* @return array|null Action result or null
|
518 |
+
*/
|
519 |
+
public function ajax_check_free_space() {
|
520 |
+
return $this->has_free_disk_space();
|
521 |
+
}
|
522 |
+
|
523 |
+
/**
|
524 |
+
* Ajax check for free disk space.
|
525 |
+
*
|
526 |
+
* @uses MainWP_Child_Staging::format_size()
|
527 |
+
* @uses MainWP_Child_Staging::get_directory_size_incl_subdirs()
|
528 |
+
*
|
529 |
+
* @return array|null Action result or null
|
530 |
+
*/
|
531 |
+
public function has_free_disk_space() {
|
532 |
+
if ( ! function_exists( 'disk_free_space' ) ) {
|
533 |
+
return null;
|
534 |
+
}
|
535 |
+
$freeSpace = disk_free_space( ABSPATH );
|
536 |
+
if ( false === $freeSpace ) {
|
537 |
+
$data = array(
|
538 |
+
'freespace' => false,
|
539 |
+
'usedspace' => $this->format_size( $this->get_directory_size_incl_subdirs( ABSPATH ) ),
|
540 |
+
);
|
541 |
+
return $data;
|
542 |
+
}
|
543 |
+
$data = array(
|
544 |
+
'freespace' => $this->format_size( $freeSpace ),
|
545 |
+
'usedspace' => $this->format_size( $this->get_directory_size_incl_subdirs( ABSPATH ) ),
|
546 |
+
);
|
547 |
+
return $data;
|
548 |
+
}
|
549 |
+
|
550 |
+
/**
|
551 |
+
* Get size of directory & subdirectories.
|
552 |
+
*
|
553 |
+
* @param string $dir Directory to size.
|
554 |
+
*
|
555 |
+
* @return false|int FALSE on failure, int $size Directory size,
|
556 |
+
*/
|
557 |
+
public function get_directory_size_incl_subdirs( $dir ) {
|
558 |
+
$size = 0;
|
559 |
+
foreach ( glob( rtrim( $dir, '/' ) . '/*', GLOB_NOSORT ) as $each ) {
|
560 |
+
$size += is_file( $each ) ? filesize( $each ) : $this->get_directory_size_incl_subdirs( $each );
|
561 |
+
}
|
562 |
+
return $size;
|
563 |
+
}
|
564 |
+
|
565 |
+
/**
|
566 |
+
* Format file size into human readable string.
|
567 |
+
*
|
568 |
+
* @param string $bytes Original size of file.
|
569 |
+
* @param int $precision Number of digits after the decimal point.
|
570 |
+
* @return string Returned Size.
|
571 |
+
*/
|
572 |
+
public function format_size( $bytes, $precision = 2 ) {
|
573 |
+
if ( (float) $bytes < 1 ) {
|
574 |
+
return '';
|
575 |
+
}
|
576 |
+
|
577 |
+
$units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
|
578 |
+
|
579 |
+
$bytes = (float) $bytes;
|
580 |
+
$base = log( $bytes ) / log( 1000 );
|
581 |
+
$pow = pow( 1000, $base - floor( $base ) );
|
582 |
+
|
583 |
+
return round( $pow, $precision ) . ' ' . $units[ (int) floor( $base ) ];
|
584 |
+
}
|
585 |
+
|
586 |
+
|
587 |
+
/**
|
588 |
+
* Get list of all plugins except WPStaging.
|
589 |
+
*
|
590 |
+
* @param array $plugins All installed plugins.
|
591 |
+
* @return mixed Returned array of plugins without WPStaging included.
|
592 |
+
*/
|
593 |
+
public function all_plugins( $plugins ) {
|
594 |
foreach ( $plugins as $key => $value ) {
|
595 |
$plugin_slug = basename( $key, '.php' );
|
596 |
if ( 'wp-staging' === $plugin_slug ) {
|
601 |
return $plugins;
|
602 |
}
|
603 |
|
604 |
+
/**
|
605 |
+
* Remove WPStaging WordPress Menu.
|
606 |
+
*/
|
607 |
public function remove_menu() {
|
608 |
+
remove_menu_page( 'wpstg_clone' );
|
609 |
+
$pos = isset( $_SERVER['REQUEST_URI'] ) ? stripos( wp_unslash( $_SERVER['REQUEST_URI'] ), 'admin.php?page=wpstg_clone' ) : false;
|
610 |
if ( false !== $pos ) {
|
611 |
+
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
612 |
exit();
|
613 |
}
|
614 |
}
|
615 |
|
616 |
+
/**
|
617 |
+
* Hide all admin update notices.
|
618 |
+
*
|
619 |
+
* @param array $slugs WPStaging plugin slug.
|
620 |
+
* @return mixed Returned $slugs.
|
621 |
+
*/
|
622 |
+
public function hide_update_notice( $slugs ) {
|
623 |
+
$slugs[] = 'wp-staging/wp-staging.php';
|
624 |
+
|
625 |
+
return $slugs;
|
626 |
+
}
|
627 |
|
628 |
+
/**
|
629 |
+
* Remove WPStaging update Nag message.
|
630 |
+
*
|
631 |
+
* @uses MainWP_Helper::is_updates_screen()
|
632 |
+
*
|
633 |
+
* @param array $value WPStaging slug.
|
634 |
+
* @return mixed $value Response array.
|
635 |
+
*/
|
636 |
+
public function remove_update_nag( $value ) {
|
637 |
if ( isset( $_POST['mainwpsignature'] ) ) {
|
638 |
return $value;
|
639 |
}
|
640 |
|
641 |
+
if ( ! MainWP_Helper::is_updates_screen() ) {
|
642 |
+
return $value;
|
643 |
+
}
|
644 |
|
645 |
if ( isset( $value->response['wp-staging/wp-staging.php'] ) ) {
|
646 |
unset( $value->response['wp-staging/wp-staging.php'] );
|
647 |
}
|
648 |
|
649 |
+
if ( isset( $value->response['wp-staging-pro/wp-staging-pro.php'] ) ) {
|
650 |
unset( $value->response['wp-staging-pro/wp-staging-pro.php'] );
|
651 |
}
|
652 |
|
653 |
return $value;
|
654 |
}
|
655 |
}
|
|
class/class-mainwp-child-stats.php
ADDED
@@ -0,0 +1,1045 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Stats.
|
4 |
+
*
|
5 |
+
* Gather the child site data to send to the MainWP Dashboard.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
//phpcs:disable Generic.Metrics.CyclomaticComplexity -- Required to achieve desired results, pull request solutions appreciated.
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class MainWP_Child_Stats
|
16 |
+
*
|
17 |
+
* Gather the child site data to send to the MainWP Dashboard.
|
18 |
+
*/
|
19 |
+
class MainWP_Child_Stats {
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Public static variable to hold the single instance of the class.
|
23 |
+
*
|
24 |
+
* @var mixed Default null
|
25 |
+
*/
|
26 |
+
protected static $instance = null;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Class used to represent anonymous functions.
|
30 |
+
*
|
31 |
+
* @var null
|
32 |
+
*/
|
33 |
+
private $filterFunction = null;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Method get_class_name()
|
37 |
+
*
|
38 |
+
* Get class name.
|
39 |
+
*
|
40 |
+
* @return string __CLASS__ Class name.
|
41 |
+
*/
|
42 |
+
public static function get_class_name() {
|
43 |
+
return __CLASS__;
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* MainWP_Child_Stats constructor.
|
48 |
+
*
|
49 |
+
* Run any time class is called.
|
50 |
+
*/
|
51 |
+
public function __construct() {
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Checks if 'last_checked'.
|
55 |
+
*
|
56 |
+
* @param $a Object to check.
|
57 |
+
* @return object|bool $a Return object or FALSE on failure.
|
58 |
+
*/
|
59 |
+
$this->filterFunction = function( $a ) {
|
60 |
+
if ( null == $a ) {
|
61 |
+
return false; }
|
62 |
+
if ( is_object( $a ) && property_exists( $a, 'last_checked' ) && ! property_exists( $a, 'checked' ) ) {
|
63 |
+
return false;
|
64 |
+
}
|
65 |
+
return $a;
|
66 |
+
};
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Method get_instance()
|
71 |
+
*
|
72 |
+
* Create a public static instance.
|
73 |
+
*
|
74 |
+
* @return mixed Class instance.
|
75 |
+
*/
|
76 |
+
public static function get_instance() {
|
77 |
+
if ( null === self::$instance ) {
|
78 |
+
self::$instance = new self();
|
79 |
+
}
|
80 |
+
|
81 |
+
return self::$instance;
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Show stats without login. only allowed while no account is added yet.
|
86 |
+
*
|
87 |
+
* @param array $information Child Site Stats.
|
88 |
+
*
|
89 |
+
* @uses MainWP_Child::$version
|
90 |
+
* @uses MainWP_Helper::is_wp_engine()
|
91 |
+
* @uses MainWP_Helper::write()
|
92 |
+
*/
|
93 |
+
public function get_site_stats_no_auth( $information = array() ) {
|
94 |
+
if ( get_option( 'mainwp_child_pubkey' ) ) {
|
95 |
+
$hint = '<br/>' . __( 'Hint: Go to the child site, deactivate and reactivate the MainWP Child plugin and try again.', 'mainwp-child' );
|
96 |
+
MainWP_Helper::error( __( 'This site already contains a link. Please deactivate and reactivate the MainWP plugin.', 'mainwp-child' ) . $hint );
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* The installed version of WordPress.
|
101 |
+
*
|
102 |
+
* @global string $wp_version The installed version of WordPress.
|
103 |
+
*/
|
104 |
+
global $wp_version;
|
105 |
+
|
106 |
+
$information['version'] = MainWP_Child::$version;
|
107 |
+
$information['wpversion'] = $wp_version;
|
108 |
+
$information['wpe'] = MainWP_Helper::is_wp_engine() ? 1 : 0;
|
109 |
+
MainWP_Helper::write( $information );
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Check if ManageWP is installed.
|
114 |
+
*
|
115 |
+
* @param array $default Active plugins.
|
116 |
+
* @return array $default Active plugins array with managewp/init.php appended.
|
117 |
+
*/
|
118 |
+
public function default_option_active_plugins( $default ) {
|
119 |
+
if ( ! is_array( $default ) ) {
|
120 |
+
$default = array();
|
121 |
+
}
|
122 |
+
if ( ! in_array( 'managewp/init.php', $default ) ) {
|
123 |
+
$default[] = 'managewp/init.php';
|
124 |
+
}
|
125 |
+
|
126 |
+
return $default;
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Get Child Site Stats.
|
131 |
+
*
|
132 |
+
* @param array $information Holder for return array.
|
133 |
+
* @param bool $exit Whether or not to exit the method. Default: true.
|
134 |
+
*
|
135 |
+
* @uses MainWP_Child_Stats::update_external_settings()
|
136 |
+
* @uses MainWP_Child_Stats::stats_get_info()
|
137 |
+
* @uses MainWP_Child_Stats::stats_wp_update()
|
138 |
+
* @uses MainWP_Child_Stats::stats_plugin_update()
|
139 |
+
* @uses MainWP_Child_Stats::stats_theme_update()
|
140 |
+
* @uses MainWP_Child_Stats::stats_translation_updates()
|
141 |
+
* @uses MainWP_Child_Stats::get_recent_number()
|
142 |
+
* @uses MainWP_Child_Stats::scan_dir()
|
143 |
+
* @uses MainWP_Child_Stats::stats_get_categories()
|
144 |
+
* @uses MainWP_Child_Stats::stats_get_total_size()
|
145 |
+
* @uses MainWP_Child_Stats::get_all_plugins_int()
|
146 |
+
* @uses MainWP_Child_Stats::get_all_themes_int()
|
147 |
+
* @uses MainWP_Child_Stats::get_health_check_site_status()
|
148 |
+
* @uses MainWP_Child_Stats::stats_others_data()
|
149 |
+
* @uses MainWP_Child_Stats::check_premium_updates()
|
150 |
+
* @uses MainWP_Child_Branding::instance()::save_branding_options()
|
151 |
+
* @uses MainWP_Child_Plugins_Check::may_outdate_number_change()
|
152 |
+
* @uses MainWP_Child_Comments::get_instance()::get_recent_comments()
|
153 |
+
* @uses MainWP_Child_Posts::get_instance()::get_recent_posts()
|
154 |
+
* @uses MainWP_Child_DB::get_size()
|
155 |
+
* @uses MainWP_Child_Users::get_instance()::get_all_users_int()
|
156 |
+
* @uses MainWP_Child_Plugins_Check::instance()::get_plugins_outdate_info()
|
157 |
+
* @uses MainWP_Child_Themes_Check::instance()::get_themes_outdate_info()
|
158 |
+
* @uses MainWP_Security::get_stats_security()
|
159 |
+
* @uses MainWP_Connect::instance()::get_max_history()
|
160 |
+
* @uses MainWP_Utility::get_lasttime_backup()
|
161 |
+
* @uses MainWP_Utility::validate_mainwp_dir()
|
162 |
+
* @uses MainWP_Helper::update_option()
|
163 |
+
* @uses MainWP_Helper::set_limit()
|
164 |
+
* @uses MainWP_Helper::log_debug()
|
165 |
+
* @uses MainWP_Helper::write()
|
166 |
+
*
|
167 |
+
* @return array $information Child Site Stats.
|
168 |
+
*/
|
169 |
+
public function get_site_stats( $information = array(), $exit = true ) {
|
170 |
+
|
171 |
+
if ( $exit ) {
|
172 |
+
$this->update_external_settings();
|
173 |
+
}
|
174 |
+
|
175 |
+
MainWP_Child_Branding::instance()->save_branding_options( 'branding_disconnected', '' );
|
176 |
+
if ( isset( $_POST['server'] ) ) {
|
177 |
+
MainWP_Helper::update_option( 'mainwp_child_server', ! empty( $_POST['server'] ) ? wp_unslash( $_POST['server'] ) : '' );
|
178 |
+
}
|
179 |
+
|
180 |
+
MainWP_Child_Plugins_Check::may_outdate_number_change();
|
181 |
+
|
182 |
+
$this->stats_get_info( $information );
|
183 |
+
|
184 |
+
include_once ABSPATH . '/wp-admin/includes/update.php';
|
185 |
+
|
186 |
+
$timeout = 3 * 60 * 60;
|
187 |
+
MainWP_Helper::set_limit( $timeout );
|
188 |
+
|
189 |
+
// Check for new versions.
|
190 |
+
$information['wp_updates'] = $this->stats_wp_update();
|
191 |
+
|
192 |
+
add_filter( 'default_option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
193 |
+
add_filter( 'option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
194 |
+
|
195 |
+
$premiumPlugins = array();
|
196 |
+
$premiumThemes = array();
|
197 |
+
|
198 |
+
// First check for new premium updates.
|
199 |
+
$this->check_premium_updates( $information, $premiumPlugins, $premiumThemes );
|
200 |
+
|
201 |
+
remove_filter( 'default_option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
202 |
+
remove_filter( 'option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
203 |
+
|
204 |
+
$information['plugin_updates'] = $this->stats_plugin_update( $premiumPlugins );
|
205 |
+
|
206 |
+
$information['theme_updates'] = $this->stats_theme_update( $premiumThemes );
|
207 |
+
|
208 |
+
$information['translation_updates'] = $this->stats_translation_updates();
|
209 |
+
|
210 |
+
$information['recent_comments'] = MainWP_Child_Comments::get_instance()->get_recent_comments( array( 'approve', 'hold' ), 5 );
|
211 |
+
|
212 |
+
$recent_number = $this->get_recent_number();
|
213 |
+
|
214 |
+
$information['recent_posts'] = MainWP_Child_Posts::get_instance()->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), $recent_number );
|
215 |
+
$information['recent_pages'] = MainWP_Child_Posts::get_instance()->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), $recent_number, 'page' );
|
216 |
+
$information['securityIssues'] = MainWP_Security::get_stats_security();
|
217 |
+
$information['securityStats'] = MainWP_Child_Misc::get_security_stats( true );
|
218 |
+
|
219 |
+
// Directory listings!
|
220 |
+
$information['directories'] = $this->scan_dir( ABSPATH, 3 );
|
221 |
+
$information['categories'] = $this->stats_get_categories();
|
222 |
+
|
223 |
+
$totalsize = $this->stats_get_total_size();
|
224 |
+
if ( ! empty( $totalsize ) ) {
|
225 |
+
$information['totalsize'] = $totalsize;
|
226 |
+
}
|
227 |
+
|
228 |
+
$information['dbsize'] = MainWP_Child_DB::get_size();
|
229 |
+
|
230 |
+
$max_his = MainWP_Connect::instance()->get_max_history();
|
231 |
+
$auths = get_option( 'mainwp_child_auth' );
|
232 |
+
$information['extauth'] = ( $auths && isset( $auths[ $max_his ] ) ? $auths[ $max_his ] : null );
|
233 |
+
|
234 |
+
$information['plugins'] = $this->get_all_plugins_int( false );
|
235 |
+
$information['themes'] = $this->get_all_themes_int( false );
|
236 |
+
|
237 |
+
if ( isset( $_POST['optimize'] ) && ( '1' == $_POST['optimize'] ) ) {
|
238 |
+
$information['users'] = MainWP_Child_Users::get_instance()->get_all_users_int( 500 );
|
239 |
+
}
|
240 |
+
|
241 |
+
if ( ! empty( $_POST['primaryBackup'] ) ) {
|
242 |
+
$primary_bk = ! empty( $_POST['primaryBackup'] ) ? sanitize_text_field( wp_unslash( $_POST['primaryBackup'] ) ) : '';
|
243 |
+
$information['primaryLasttimeBackup'] = MainWP_Utility::get_lasttime_backup( $primary_bk );
|
244 |
+
}
|
245 |
+
|
246 |
+
$last_post = wp_get_recent_posts( array( 'numberposts' => absint( '1' ) ) );
|
247 |
+
if ( isset( $last_post[0] ) ) {
|
248 |
+
$last_post = $last_post[0];
|
249 |
+
}
|
250 |
+
if ( isset( $last_post ) && isset( $last_post['post_modified_gmt'] ) ) {
|
251 |
+
$information['last_post_gmt'] = strtotime( $last_post['post_modified_gmt'] );
|
252 |
+
}
|
253 |
+
$information['mainwpdir'] = ( MainWP_Utility::validate_mainwp_dir() ? 1 : - 1 );
|
254 |
+
$information['uniqueId'] = get_option( 'mainwp_child_uniqueId', '' );
|
255 |
+
$information['plugins_outdate_info'] = MainWP_Child_Plugins_Check::instance()->get_plugins_outdate_info();
|
256 |
+
$information['themes_outdate_info'] = MainWP_Child_Themes_Check::instance()->get_themes_outdate_info();
|
257 |
+
$information['health_site_status'] = $this->get_health_check_site_status();
|
258 |
+
|
259 |
+
if ( isset( $_POST['user'] ) ) {
|
260 |
+
$user = get_user_by( 'login', sanitize_text_field( wp_unslash( $_POST['user'] ) ) );
|
261 |
+
if ( $user && property_exists( $user, 'ID' ) && $user->ID ) {
|
262 |
+
$information['admin_nicename'] = $user->data->user_nicename;
|
263 |
+
$information['admin_useremail'] = $user->data->user_email;
|
264 |
+
}
|
265 |
+
}
|
266 |
+
|
267 |
+
try {
|
268 |
+
do_action( 'mainwp_child_site_stats' );
|
269 |
+
} catch ( \Exception $e ) {
|
270 |
+
MainWP_Helper::log_debug( $e->getMessage() );
|
271 |
+
}
|
272 |
+
|
273 |
+
if ( isset( $_POST['othersData'] ) ) {
|
274 |
+
$this->stats_others_data( $information );
|
275 |
+
}
|
276 |
+
|
277 |
+
if ( $exit ) {
|
278 |
+
MainWP_Helper::write( $information );
|
279 |
+
}
|
280 |
+
|
281 |
+
return $information;
|
282 |
+
}
|
283 |
+
|
284 |
+
/**
|
285 |
+
* Get other stats data.
|
286 |
+
*
|
287 |
+
* @param array $information Child Site Stats array.
|
288 |
+
*
|
289 |
+
* @uses MainWP_Helper::update_option()
|
290 |
+
* @uses MainWP_Helper::log_debug()
|
291 |
+
*/
|
292 |
+
private function stats_others_data( &$information ) {
|
293 |
+
|
294 |
+
$othersData = isset( $_POST['othersData'] ) ? json_decode( stripslashes( wp_unslash( $_POST['othersData'] ) ), true ) : array();
|
295 |
+
if ( ! is_array( $othersData ) ) {
|
296 |
+
$othersData = array();
|
297 |
+
}
|
298 |
+
|
299 |
+
if ( isset( $othersData['wpvulndbToken'] ) ) {
|
300 |
+
$wpvulndb_token = get_option( 'mainwp_child_wpvulndb_token', '' );
|
301 |
+
if ( $wpvulndb_token != $othersData['wpvulndbToken'] ) {
|
302 |
+
MainWP_Helper::update_option( 'mainwp_child_wpvulndb_token', $othersData['wpvulndbToken'] );
|
303 |
+
}
|
304 |
+
}
|
305 |
+
|
306 |
+
try {
|
307 |
+
$information = apply_filters_deprecated( 'mainwp-site-sync-others-data', array( $information, $othersData ), '4.0.7.1', 'mainwp_site_sync_others_data' );
|
308 |
+
$information = apply_filters( 'mainwp_site_sync_others_data', $information, $othersData );
|
309 |
+
|
310 |
+
} catch ( \Exception $e ) {
|
311 |
+
MainWP_Helper::log_debug( $e->getMessage() );
|
312 |
+
}
|
313 |
+
}
|
314 |
+
|
315 |
+
/**
|
316 |
+
* Translation update stats.
|
317 |
+
*
|
318 |
+
* @return array $results Returned results.
|
319 |
+
*/
|
320 |
+
private function stats_translation_updates() {
|
321 |
+
$results = array();
|
322 |
+
|
323 |
+
$translation_updates = wp_get_translation_updates();
|
324 |
+
if ( ! empty( $translation_updates ) ) {
|
325 |
+
foreach ( $translation_updates as $translation_update ) {
|
326 |
+
$new_translation_update = array(
|
327 |
+
'type' => $translation_update->type,
|
328 |
+
'slug' => $translation_update->slug,
|
329 |
+
'language' => $translation_update->language,
|
330 |
+
'version' => $translation_update->version,
|
331 |
+
);
|
332 |
+
if ( 'plugin' === $translation_update->type ) {
|
333 |
+
$all_plugins = get_plugins();
|
334 |
+
foreach ( $all_plugins as $file => $plugin ) {
|
335 |
+
$path = dirname( $file );
|
336 |
+
if ( $path == $translation_update->slug ) {
|
337 |
+
$new_translation_update['name'] = $plugin['Name'];
|
338 |
+
break;
|
339 |
+
}
|
340 |
+
}
|
341 |
+
} elseif ( 'theme' === $translation_update->type ) {
|
342 |
+
$theme = wp_get_theme( $translation_update->slug );
|
343 |
+
$new_translation_update['name'] = $theme->name;
|
344 |
+
} elseif ( ( 'core' === $translation_update->type ) && ( 'default' === $translation_update->slug ) ) {
|
345 |
+
$new_translation_update['name'] = 'WordPress core';
|
346 |
+
}
|
347 |
+
|
348 |
+
$results[] = $new_translation_update;
|
349 |
+
}
|
350 |
+
}
|
351 |
+
return $results;
|
352 |
+
}
|
353 |
+
|
354 |
+
/**
|
355 |
+
* Premium theme update stats.
|
356 |
+
*
|
357 |
+
* @param array $premiumThemes Array of premium themes.
|
358 |
+
*
|
359 |
+
* @uses MainWP_Child_Updates::get_instance()::upgrade_get_theme_updates()
|
360 |
+
*
|
361 |
+
* @return array $results Array of premium theme slugs.
|
362 |
+
*/
|
363 |
+
private function stats_theme_update( $premiumThemes ) {
|
364 |
+
|
365 |
+
$results = array();
|
366 |
+
|
367 |
+
if ( null !== $this->filterFunction ) {
|
368 |
+
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
369 |
+
}
|
370 |
+
|
371 |
+
wp_update_themes();
|
372 |
+
include_once ABSPATH . '/wp-admin/includes/theme.php';
|
373 |
+
$theme_updates = MainWP_Child_Updates::get_instance()->upgrade_get_theme_updates();
|
374 |
+
if ( is_array( $theme_updates ) ) {
|
375 |
+
foreach ( $theme_updates as $slug => $theme_update ) {
|
376 |
+
$name = ( is_array( $theme_update ) ? $theme_update['Name'] : $theme_update->Name );
|
377 |
+
if ( in_array( $name, $premiumThemes ) ) {
|
378 |
+
continue;
|
379 |
+
}
|
380 |
+
$results[ $slug ] = $theme_update;
|
381 |
+
}
|
382 |
+
}
|
383 |
+
if ( null !== $this->filterFunction ) {
|
384 |
+
remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
385 |
+
}
|
386 |
+
|
387 |
+
// Fixes premium themes update.
|
388 |
+
$cached_themes_update = get_site_transient( 'mainwp_update_themes_cached' );
|
389 |
+
if ( is_array( $cached_themes_update ) && ( count( $cached_themes_update ) > 0 ) ) {
|
390 |
+
|
391 |
+
foreach ( $cached_themes_update as $slug =>
|