PluginProbe
ManageWP Worker / 4.9.34
ManageWP Worker v4.9.34
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / Action / IncrementalBackup / Abstract.php

Abstract.php in ManageWP Worker 4.9.34, at src/MWP/Action/IncrementalBackup/Abstract.php

90 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <[email protected]>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 class MWP_Action_IncrementalBackup_Abstract extends MWP_Action_Abstract
12 {
13 /**
14 * @param array $result
15 *
16 * @return array
17 */
18 protected function createResult(array $result)
19 {
20 return array(
21 'result' => $result,
22 'server' => $this->getServerStatistics()->toArray(),
23 );
24 }
25
26 /**
27 * Get file real path given a path relative to WordPress root.
28 *
29 * @param string $relativePath
30 *
31 * @param bool $virtual Don't do real filesystem touch, simulate instead
32 *
33 * @return string
34 */
35 protected function getRealPath($relativePath, $virtual = false)
36 {
37 if ($virtual) {
38 return $this->virtualGetAbsolutePath(untrailingslashit(ABSPATH).'/'.$relativePath);
39 }
40
41 return realpath(untrailingslashit(ABSPATH).'/'.$relativePath);
42 }
43
44 /**
45 * @return MWP_IncrementalBackup_Model_ServerStatistics
46 */
47 private function getServerStatistics()
48 {
49 return MWP_IncrementalBackup_Model_ServerStatistics::factory();
50 }
51
52 /**
53 * @param string $path
54 *
55 * @return string
56 */
57 private function virtualGetAbsolutePath($path)
58 {
59 $originalPath = $path;
60
61 $isWindows = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
62
63 if ($isWindows) {
64 $path = str_replace('\\', '/', $path);
65 }
66
67 $parts = array_filter(explode('/', $path), 'strlen');
68 $absolutes = array();
69 foreach ($parts as $part) {
70 if ('.' == $part) {
71 continue;
72 }
73 if ('..' == $part) {
74 array_pop($absolutes);
75 } else {
76 $absolutes[] = $part;
77 }
78 }
79
80 if (strpos($originalPath, '\\\\') === 0) { // NAS mount
81 return '//'.implode(DIRECTORY_SEPARATOR, $absolutes);
82 } elseif (strpos($path, '/') === 0) {
83 return '/'.implode(DIRECTORY_SEPARATOR, $absolutes);
84 } else {
85 return implode(DIRECTORY_SEPARATOR, $absolutes);
86 }
87 }
88
89 }
90