| 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_AbstractFiles extends MWP_Action_IncrementalBackup_Abstract |
| 12 |
{ |
| 13 |
|
| 14 |
/** @var bool */ |
| 15 |
protected $isWindows; |
| 16 |
|
| 17 |
public function __construct() |
| 18 |
{ |
| 19 |
$this->isWindows = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Replace Windows \\ with / on set of files |
| 24 |
* |
| 25 |
* @param $files |
| 26 |
* |
| 27 |
* @return array |
| 28 |
*/ |
| 29 |
protected function replaceWindowsPaths($files) |
| 30 |
{ |
| 31 |
if ($this->isWindows) { |
| 32 |
foreach ($files as $key => $file) { |
| 33 |
$files[$key]['path'] = str_replace('\\', '/', $file['path']); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
return $files; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Replace Windows \\ with / |
| 42 |
* |
| 43 |
* @param $path |
| 44 |
* |
| 45 |
* @return string |
| 46 |
*/ |
| 47 |
protected function replaceWindowsPath($path) |
| 48 |
{ |
| 49 |
if ($this->isWindows) { |
| 50 |
$path = str_replace('\\', '/', $path); |
| 51 |
} |
| 52 |
|
| 53 |
return $path; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Return encoded path for user across systems |
| 58 |
* |
| 59 |
* @param $path |
| 60 |
* |
| 61 |
* @return string |
| 62 |
*/ |
| 63 |
protected function pathEncode($path) |
| 64 |
{ |
| 65 |
$split = explode('/', $path); |
| 66 |
$encodedPaths = array_map("urlencode", $split); |
| 67 |
$encodedPath = implode('/', $encodedPaths); |
| 68 |
|
| 69 |
return $encodedPath; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Return decoded path |
| 74 |
* |
| 75 |
* @param $path |
| 76 |
* |
| 77 |
* @return string |
| 78 |
*/ |
| 79 |
protected function pathDecode($path) |
| 80 |
{ |
| 81 |
|
| 82 |
return urldecode($path); |
| 83 |
} |
| 84 |
} |
| 85 |
|