|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package Cadmium\System\Modules\Filemanager |
|
5
|
|
|
* @author Anton Romanov |
|
6
|
|
|
* @copyright Copyright (c) 2015-2017, Anton Romanov |
|
7
|
|
|
* @link http://cadmium-cms.com |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Modules\Filemanager\Utils { |
|
11
|
|
|
|
|
12
|
|
|
use Explorer; |
|
13
|
|
|
|
|
14
|
|
|
abstract class Container { |
|
15
|
|
|
|
|
16
|
|
|
private $scheme = [], $path = ''; |
|
17
|
|
|
|
|
18
|
|
|
protected $path_full = ''; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Constructor |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
public function __construct(string $path = '') { |
|
25
|
|
|
|
|
26
|
|
|
$scheme = array_diff(preg_split('/[\/\\\\]+/', $path, -1, PREG_SPLIT_NO_EMPTY), ['.', '..']); |
|
27
|
|
|
|
|
28
|
|
|
$path_full = ($this->path_full . (('' !== ($path = implode('/', $scheme))) ? ($path . '/') : '')); |
|
29
|
|
|
|
|
30
|
|
|
if (!Explorer::isDir($path_full)) return; |
|
31
|
|
|
|
|
32
|
|
|
$this->scheme = $scheme; $this->path = $path; $this->path_full = $path_full; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Get the container breadcrumbs |
|
37
|
|
|
* |
|
38
|
|
|
* @return array : the list of ancestor directories where each item is an array of type |
|
39
|
|
|
* ['origin' => $origin, 'path' => $path, 'name' => $name], where $origin is a container's origin directory name, |
|
40
|
|
|
* $path is a directory's relative path, and $name is an directory's file name |
|
41
|
|
|
*/ |
|
42
|
|
|
|
|
43
|
|
|
public function getBreadcrumbs() : array { |
|
44
|
|
|
|
|
45
|
|
|
$scheme = []; $breadcrumbs = []; |
|
46
|
|
|
|
|
47
|
|
|
foreach ($this->scheme as $name) { |
|
48
|
|
|
|
|
49
|
|
|
$scheme[] = $name; $path = implode('/', $scheme); |
|
50
|
|
|
|
|
51
|
|
|
$breadcrumbs[] = ['origin' => static::$origin, 'path' => $path, 'name' => $name]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
# ------------------------ |
|
55
|
|
|
|
|
56
|
|
|
return $breadcrumbs; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get the container relative path |
|
61
|
|
|
*/ |
|
62
|
|
|
|
|
63
|
|
|
public function getPath() : string { |
|
64
|
|
|
|
|
65
|
|
|
return $this->path; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get the container full path |
|
70
|
|
|
*/ |
|
71
|
|
|
|
|
72
|
|
|
public function getPathFull() : string { |
|
73
|
|
|
|
|
74
|
|
|
return $this->path_full; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Get the origin directory name |
|
79
|
|
|
*/ |
|
80
|
|
|
|
|
81
|
|
|
public function getOrigin() : string { |
|
82
|
|
|
|
|
83
|
|
|
return static::$origin; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get the list of container permissions (inherited from origin) |
|
88
|
|
|
*/ |
|
89
|
|
|
|
|
90
|
|
|
public function getPermissions() : array { |
|
91
|
|
|
|
|
92
|
|
|
return static::$permissions; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Check whether the container is set to ignore hidden files or not (inherited from origin) |
|
97
|
|
|
*/ |
|
98
|
|
|
|
|
99
|
|
|
public function isIgnoreHidden() : bool { |
|
100
|
|
|
|
|
101
|
|
|
return static::$ignore_hidden; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|