|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace UniSharp\LaravelFilemanager; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Storage; |
|
6
|
|
|
|
|
7
|
|
|
class LfmStorageRepository |
|
8
|
|
|
{ |
|
9
|
|
|
private $disk; |
|
10
|
|
|
private $path; |
|
11
|
|
|
private $helper; |
|
12
|
|
|
|
|
13
|
|
|
public function __construct($storage_path, $helper) |
|
14
|
|
|
{ |
|
15
|
|
|
$this->helper = $helper; |
|
16
|
|
|
$this->disk = Storage::disk($this->helper->config('disk')); |
|
17
|
|
|
$this->path = $storage_path; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function __call($function_name, $arguments) |
|
21
|
|
|
{ |
|
22
|
|
|
if ($function_name == 'directories') { |
|
23
|
|
|
$directories = $this->disk->directories($this->path, ...$arguments); |
|
|
|
|
|
|
24
|
|
|
$config = $this->helper->config('private_folder_name'); |
|
25
|
|
|
|
|
26
|
|
|
if(method_exists(app()->make($config), 'userAuthDirs')) { |
|
|
|
|
|
|
27
|
|
|
return $this->getAuthDirectories($directories, app()->make($config)->userAuthDirs()); |
|
28
|
|
|
} else { |
|
29
|
|
|
return $directories; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
} else { |
|
33
|
|
|
// TODO: check function exists |
|
34
|
|
|
return $this->disk->$function_name($this->path, ...$arguments); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function rootPath() |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->disk->path(''); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function move($new_lfm_path) |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->disk->move($this->path, $new_lfm_path->path('storage')); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function save($file) |
|
49
|
|
|
{ |
|
50
|
|
|
$nameint = strripos($this->path, "/"); |
|
51
|
|
|
$nameclean = substr($this->path, $nameint + 1); |
|
52
|
|
|
$pathclean = substr_replace($this->path, "", $nameint); |
|
53
|
|
|
$this->disk->putFileAs($pathclean, $file, $nameclean); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function url($path) |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->disk->url($path); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function makeDirectory() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->disk->makeDirectory($this->path, ...func_get_args()); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
// some filesystems (e.g. Google Storage, S3?) don't let you set ACLs on directories (because they don't exist) |
|
66
|
|
|
// https://cloud.google.com/storage/docs/naming#object-considerations |
|
67
|
|
|
if ($this->disk->has($this->path)) { |
|
|
|
|
|
|
68
|
|
|
$this->disk->setVisibility($this->path, 'public'); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function extension() |
|
73
|
|
|
{ |
|
74
|
|
|
setlocale(LC_ALL, 'en_US.UTF-8'); |
|
75
|
|
|
return pathinfo($this->path, PATHINFO_EXTENSION); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function getAuthDirectories($directories, $auth_dirs) |
|
79
|
|
|
{ |
|
80
|
|
|
$check = $directories; |
|
81
|
|
|
|
|
82
|
|
|
if(count($auth_dirs)){ |
|
83
|
|
|
// remove unauthorized directories |
|
84
|
|
|
foreach($check as $i => $directory) { |
|
85
|
|
|
if(!in_array($directory, $auth_dirs)){ |
|
86
|
|
|
unset($directories[$i]); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return $directories; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|