UniSharp /
laravel-filemanager
| 1 | <?php |
||
| 2 | |||
| 3 | namespace UniSharp\LaravelFilemanager\Middlewares; |
||
| 4 | |||
| 5 | use Closure; |
||
| 6 | use Illuminate\Support\Str; |
||
| 7 | use UniSharp\LaravelFilemanager\Lfm; |
||
| 8 | |||
| 9 | class MultiUser |
||
| 10 | { |
||
| 11 | private $helper; |
||
| 12 | |||
| 13 | public function __construct() |
||
| 14 | { |
||
| 15 | $this->helper = app(Lfm::class); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 16 | } |
||
| 17 | |||
| 18 | public function handle($request, Closure $next) |
||
| 19 | { |
||
| 20 | if ($this->helper->allowFolderType('user')) { |
||
| 21 | $previous_dir = $request->input('working_dir'); |
||
| 22 | $working_dir = $this->helper->getRootFolder('user'); |
||
| 23 | |||
| 24 | if ($previous_dir == null) { |
||
| 25 | $request->merge(compact('working_dir')); |
||
| 26 | } elseif (! $this->validDir($previous_dir)) { |
||
| 27 | $request->replace(compact('working_dir')); |
||
| 28 | } |
||
| 29 | } |
||
| 30 | |||
| 31 | return $next($request); |
||
| 32 | } |
||
| 33 | |||
| 34 | private function validDir($previous_dir) |
||
| 35 | { |
||
| 36 | if (Str::startsWith($previous_dir, $this->helper->getRootFolder('share'))) { |
||
| 37 | return true; |
||
| 38 | } |
||
| 39 | |||
| 40 | if (Str::startsWith($previous_dir, $this->helper->getRootFolder('user'))) { |
||
| 41 | return true; |
||
| 42 | } |
||
| 43 | |||
| 44 | return false; |
||
| 45 | } |
||
| 46 | } |
||
| 47 |