1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace UniSharp\LaravelFilemanager\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
|
7
|
|
|
use UniSharp\LaravelFilemanager\Events\FileIsMoving; |
8
|
|
|
use UniSharp\LaravelFilemanager\Events\FileWasMoving; |
9
|
|
|
use UniSharp\LaravelFilemanager\Events\FolderIsMoving; |
10
|
|
|
use UniSharp\LaravelFilemanager\Events\FolderWasMoving; |
11
|
|
|
|
12
|
|
|
class ItemsController extends LfmController |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Get the images to load for a selected folder. |
16
|
|
|
* |
17
|
|
|
* @return mixed |
18
|
|
|
*/ |
19
|
|
|
public function getItems(Request $request) |
20
|
|
|
{ |
21
|
|
|
$currentPage = self::getCurrentPageFromRequest(); |
22
|
|
|
$keyword = $request->keyword; |
23
|
|
|
|
24
|
|
|
$perPage = $this->helper->getPaginationPerPage(); |
|
|
|
|
25
|
|
|
$items = array_merge($this->lfm->folders(), $this->lfm->files()); |
|
|
|
|
26
|
|
|
|
27
|
|
|
$items = array_map(function ($item) { |
28
|
|
|
return $item->fill()->attributes; |
29
|
|
|
}, array_slice($items, ($currentPage - 1) * $perPage, $perPage)); |
30
|
|
|
|
31
|
|
|
$c = count($items); |
32
|
|
|
|
33
|
|
|
if (!empty($keyword)) { |
34
|
|
|
$items = array_values(array_filter($items, function ($item) use ($keyword) { |
35
|
|
|
if ($this->like_match("%".$keyword."%", $item['name'])) { |
36
|
|
|
return true; |
37
|
|
|
} else { |
38
|
|
|
return false; |
39
|
|
|
} |
40
|
|
|
})); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return [ |
44
|
|
|
'items' => $items, |
45
|
|
|
'paginator' => [ |
46
|
|
|
'current_page' => $currentPage, |
47
|
|
|
'total' => $c, |
48
|
|
|
'per_page' => $perPage, |
49
|
|
|
], |
50
|
|
|
'display' => $this->helper->getDisplayMode(), |
51
|
|
|
'working_dir' => $this->lfm->path('working_dir'), |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
public function like_match($pattern, $subject) |
57
|
|
|
{ |
58
|
|
|
$pattern = str_replace('%', '.*', preg_quote($pattern, '/')); |
59
|
|
|
return (bool) preg_match("/^{$pattern}$/i", $subject); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function move() |
63
|
|
|
{ |
64
|
|
|
$items = request('items'); |
|
|
|
|
65
|
|
|
$folder_types = array_filter(['user', 'share'], function ($type) { |
66
|
|
|
return $this->helper->allowFolderType($type); |
|
|
|
|
67
|
|
|
}); |
68
|
|
|
return view('laravel-filemanager::move') |
|
|
|
|
69
|
|
|
->with([ |
70
|
|
|
'root_folders' => array_map(function ($type) use ($folder_types) { |
71
|
|
|
$path = $this->lfm->dir($this->helper->getRootFolder($type)); |
|
|
|
|
72
|
|
|
|
73
|
|
|
return (object) [ |
74
|
|
|
'name' => trans('laravel-filemanager::lfm.title-' . $type), |
|
|
|
|
75
|
|
|
'url' => $path->path('working_dir'), |
76
|
|
|
'children' => $path->folders(), |
77
|
|
|
'has_next' => ! ($type == end($folder_types)), |
78
|
|
|
]; |
79
|
|
|
}, $folder_types), |
80
|
|
|
]) |
81
|
|
|
->with('items', $items); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function domove() |
85
|
|
|
{ |
86
|
|
|
$target = $this->helper->input('goToFolder'); |
|
|
|
|
87
|
|
|
$items = $this->helper->input('items'); |
88
|
|
|
|
89
|
|
|
foreach ($items as $item) { |
90
|
|
|
$old_file = $this->lfm->pretty($item); |
|
|
|
|
91
|
|
|
$is_directory = $old_file->isDirectory(); |
92
|
|
|
|
93
|
|
|
if ($old_file->hasThumb()) { |
94
|
|
|
$new_file = $this->lfm->setName($item)->thumb()->dir($target); |
95
|
|
|
if ($is_directory) { |
96
|
|
|
event(new FolderIsMoving($old_file->path(), $new_file->path())); |
|
|
|
|
97
|
|
|
} else { |
98
|
|
|
event(new FileIsMoving($old_file->path(), $new_file->path())); |
99
|
|
|
} |
100
|
|
|
$this->lfm->setName($item)->thumb()->move($new_file); |
101
|
|
|
} |
102
|
|
|
$new_file = $this->lfm->setName($item)->dir($target); |
103
|
|
|
$this->lfm->setName($item)->move($new_file); |
104
|
|
|
if ($is_directory) { |
105
|
|
|
event(new FolderWasMoving($old_file->path(), $new_file->path())); |
106
|
|
|
} else { |
107
|
|
|
event(new FileWasMoving($old_file->path(), $new_file->path())); |
108
|
|
|
} |
109
|
|
|
}; |
110
|
|
|
|
111
|
|
|
return parent::$success_response; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
private static function getCurrentPageFromRequest() |
115
|
|
|
{ |
116
|
|
|
$currentPage = (int) request()->get('page', 1); |
|
|
|
|
117
|
|
|
$currentPage = $currentPage < 1 ? 1 : $currentPage; |
118
|
|
|
|
119
|
|
|
return $currentPage; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
private static function getKeywordFromRequest() |
|
|
|
|
123
|
|
|
{ |
124
|
|
|
$keyword = request()->get('keyword', ""); |
|
|
|
|
125
|
|
|
return $keyword; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
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.