1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace UniSharp\LaravelFilemanager\Controllers; |
4
|
|
|
|
5
|
|
|
use UniSharp\LaravelFilemanager\Events\FolderIsCreating; |
6
|
|
|
use UniSharp\LaravelFilemanager\Events\FolderWasCreated; |
7
|
|
|
|
8
|
|
|
class FolderController extends LfmController |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Get list of folders as json to populate treeview. |
12
|
|
|
* |
13
|
|
|
* @return mixed |
14
|
|
|
*/ |
15
|
|
|
public function getFolders() |
16
|
|
|
{ |
17
|
|
|
$folder_types = array_filter(['user', 'share'], function ($type) { |
18
|
|
|
return $this->helper->allowFolderType($type); |
|
|
|
|
19
|
|
|
}); |
20
|
|
|
|
21
|
|
|
return view('laravel-filemanager::tree') |
|
|
|
|
22
|
|
|
->with([ |
23
|
|
|
'root_folders' => array_map(function ($type) use ($folder_types) { |
24
|
|
|
$path = $this->lfm->dir($this->helper->getRootFolder($type)); |
|
|
|
|
25
|
|
|
|
26
|
|
|
return (object) [ |
27
|
|
|
'name' => trans('laravel-filemanager::lfm.title-' . $type), |
|
|
|
|
28
|
|
|
'url' => $path->path('working_dir'), |
29
|
|
|
'children' => $path->folders(), |
30
|
|
|
'has_next' => ! ($type == end($folder_types)), |
31
|
|
|
]; |
32
|
|
|
}, $folder_types), |
33
|
|
|
]); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Add a new folder. |
38
|
|
|
* |
39
|
|
|
* @return mixed |
40
|
|
|
*/ |
41
|
|
|
public function getAddfolder() |
42
|
|
|
{ |
43
|
|
|
$folder_name = $this->helper->input('name'); |
|
|
|
|
44
|
|
|
|
45
|
|
|
$new_path = $this->lfm->setName($folder_name)->path('absolute'); |
|
|
|
|
46
|
|
|
|
47
|
|
|
event(new FolderIsCreating($new_path)); |
|
|
|
|
48
|
|
|
|
49
|
|
|
try { |
50
|
|
|
if ($folder_name === null || $folder_name == '') { |
51
|
|
|
return $this->helper->error('folder-name'); |
52
|
|
|
} elseif ($this->lfm->setName($folder_name)->exists()) { |
53
|
|
|
return $this->helper->error('folder-exist'); |
54
|
|
|
} elseif (config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $folder_name)) { |
|
|
|
|
55
|
|
|
return $this->helper->error('folder-alnum'); |
56
|
|
|
} else { |
57
|
|
|
$this->lfm->setName($folder_name)->createFolder(); |
58
|
|
|
} |
59
|
|
|
} catch (\Exception $e) { |
60
|
|
|
return $e->getMessage(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
event(new FolderWasCreated($new_path)); |
64
|
|
|
|
65
|
|
|
return parent::$success_response; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.