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
|
|
|
if($keyword != null) { |
32
|
|
|
$items = array_values(array_filter($items, function($item) use ($keyword) { |
33
|
|
|
if($this->like_match("%".$keyword."%", $item['name'])) { |
34
|
|
|
return true; |
35
|
|
|
} else { |
36
|
|
|
return false; |
37
|
|
|
} |
38
|
|
|
})); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return [ |
42
|
|
|
'items' => $items, |
43
|
|
|
'paginator' => [ |
44
|
|
|
'current_page' => $currentPage, |
45
|
|
|
'total' => count($items), |
46
|
|
|
'per_page' => $perPage, |
47
|
|
|
], |
48
|
|
|
'display' => $this->helper->getDisplayMode(), |
49
|
|
|
'working_dir' => $this->lfm->path('working_dir'), |
50
|
|
|
]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function like_match($pattern, $subject) |
55
|
|
|
{ |
56
|
|
|
$pattern = str_replace('%', '.*', preg_quote($pattern, '/')); |
57
|
|
|
return (bool) preg_match("/^{$pattern}$/i", $subject); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function move() |
61
|
|
|
{ |
62
|
|
|
$items = request('items'); |
|
|
|
|
63
|
|
|
$folder_types = array_filter(['user', 'share'], function ($type) { |
64
|
|
|
return $this->helper->allowFolderType($type); |
|
|
|
|
65
|
|
|
}); |
66
|
|
|
return view('laravel-filemanager::move') |
|
|
|
|
67
|
|
|
->with([ |
68
|
|
|
'root_folders' => array_map(function ($type) use ($folder_types) { |
69
|
|
|
$path = $this->lfm->dir($this->helper->getRootFolder($type)); |
|
|
|
|
70
|
|
|
|
71
|
|
|
return (object) [ |
72
|
|
|
'name' => trans('laravel-filemanager::lfm.title-' . $type), |
|
|
|
|
73
|
|
|
'url' => $path->path('working_dir'), |
74
|
|
|
'children' => $path->folders(), |
75
|
|
|
'has_next' => ! ($type == end($folder_types)), |
76
|
|
|
]; |
77
|
|
|
}, $folder_types), |
78
|
|
|
]) |
79
|
|
|
->with('items', $items); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function domove() |
83
|
|
|
{ |
84
|
|
|
$target = $this->helper->input('goToFolder'); |
|
|
|
|
85
|
|
|
$items = $this->helper->input('items'); |
86
|
|
|
|
87
|
|
|
foreach ($items as $item) { |
88
|
|
|
$old_file = $this->lfm->pretty($item); |
|
|
|
|
89
|
|
|
$is_directory = $old_file->isDirectory(); |
90
|
|
|
|
91
|
|
|
if ($old_file->hasThumb()) { |
92
|
|
|
$new_file = $this->lfm->setName($item)->thumb()->dir($target); |
93
|
|
|
if ($is_directory) { |
94
|
|
|
event(new FolderIsMoving($old_file->path(), $new_file->path())); |
|
|
|
|
95
|
|
|
} else { |
96
|
|
|
event(new FileIsMoving($old_file->path(), $new_file->path())); |
97
|
|
|
} |
98
|
|
|
$this->lfm->setName($item)->thumb()->move($new_file); |
99
|
|
|
} |
100
|
|
|
$new_file = $this->lfm->setName($item)->dir($target); |
101
|
|
|
$this->lfm->setName($item)->move($new_file); |
102
|
|
|
if ($is_directory) { |
103
|
|
|
event(new FolderWasMoving($old_file->path(), $new_file->path())); |
104
|
|
|
} else { |
105
|
|
|
event(new FileWasMoving($old_file->path(), $new_file->path())); |
106
|
|
|
} |
107
|
|
|
}; |
108
|
|
|
|
109
|
|
|
return parent::$success_response; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
private static function getCurrentPageFromRequest() |
113
|
|
|
{ |
114
|
|
|
$currentPage = (int) request()->get('page', 1); |
|
|
|
|
115
|
|
|
$currentPage = $currentPage < 1 ? 1 : $currentPage; |
116
|
|
|
|
117
|
|
|
return $currentPage; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
private static function getKeywordFromRequest() |
|
|
|
|
121
|
|
|
{ |
122
|
|
|
$keyword = request()->get('keyword', ""); |
|
|
|
|
123
|
|
|
return $keyword; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
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.