PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.1.3
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.1.3
4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / Filesystem / PathChecker.php
wp-staging / Framework / Filesystem Last commit date
Filters 2 years ago Scanning 5 years ago DebugLogReader.php 2 years ago DirectoryListing.php 3 years ago DiskWriteCheck.php 3 years ago FileObject.php 2 years ago Filesystem.php 2 years ago FilesystemExceptions.php 5 years ago FilterableDirectoryIterator.php 3 years ago LogCleanup.php 2 years ago LogFiles.php 2 years ago MissingFileException.php 3 years ago PathChecker.php 2 years ago PathIdentifier.php 2 years ago Permissions.php 5 years ago WpUploadsFolderSymlinker.php 4 years ago
PathChecker.php
88 lines
1 <?php
2
3 namespace WPStaging\Framework\Filesystem;
4
5 use UnexpectedValueException;
6 use WPStaging\Framework\Adapter\Directory;
7
8 /**
9 * Class PathChecker
10 *
11 * @package WPStaging\Framework\Filesystem
12 */
13 class PathChecker
14 {
15 /** @var Filesystem */
16 private $filesystem;
17
18 /** @var Directory */
19 private $directory;
20
21 /** @var PathIdentifier */
22 private $pathIdentifier;
23
24 /**
25 * PathChecker constructor.
26 *
27 * @param Filesystem $filesystem
28 * @param Directory $directory
29 * @param PathIdentifier $pathIdentifier
30 */
31 public function __construct(Filesystem $filesystem, Directory $directory, PathIdentifier $pathIdentifier)
32 {
33 $this->filesystem = $filesystem;
34 $this->directory = $directory;
35 $this->pathIdentifier = $pathIdentifier;
36 }
37
38 /**
39 * Check whether the path exists in the list.
40 * If the isRelative flag is checked it will ignore ABSPATH (root path of WP Installation),
41 * from both the paths during checking
42 *
43 * @param string $path The path to check
44 * @param array $list List of path to check against
45 * @param bool $isRelative Should the ABSPATH be ignored when checking. Default false
46 * @param string $basePath Use ABSPATH if null or empty otherwise use the provided path as base path
47 *
48 * @return bool
49 */
50 public function isPathInPathsList($path, $list, $isRelative = false, $basePath = null)
51 {
52 if (empty($basePath)) {
53 $basePath = $this->directory->getAbsPath();
54 }
55
56 $basePath = $this->filesystem->normalizePath($basePath);
57 $path = $this->filesystem->normalizePath($path);
58 // remove ABSPATH and add leading slash if not present
59 if ($isRelative) {
60 $path = '/' . ltrim(str_replace($basePath, '', $path), '/');
61 }
62
63 foreach ($list as $pathItem) {
64 $pathItem = $this->filesystem->normalizePath($pathItem);
65 try {
66 $pathItem = $this->pathIdentifier->transformIdentifiableToPath($pathItem);
67 } catch (UnexpectedValueException $ex) {
68 }
69
70 // remove ABSPATH and add leading slash if not present
71 if ($isRelative) {
72 $pathItem = '/' . ltrim(str_replace($basePath, '', $pathItem), '/');
73 }
74
75 if ($path === $pathItem) {
76 return true;
77 }
78
79 // Check whether directory a child of any excluded directories
80 if (strpos($path, $pathItem . '/') === 0) {
81 return true;
82 }
83 }
84
85 return false;
86 }
87 }
88