Skip to content

Commit b341922

Browse files
committed
make thumb folder configurable, refactor item controller
1 parent 9ca69e0 commit b341922

File tree

10 files changed

+55
-82
lines changed

10 files changed

+55
-82
lines changed

src/config/lfm.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
'rename_file' => true,
99

10-
'user_field' => "name",
10+
'user_field' => 'name',
1111

1212
'shared_folder_name' => 'shares',
13+
'thumb_folder_name' => 'thumbs',
1314

1415
'middlewares' => ['auth'],
1516

src/controllers/ItemsController.php

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,71 +16,40 @@
1616
*/
1717
class ItemsController extends LfmController {
1818

19+
1920
/**
20-
* Return json list of files
21+
* Get the images to load for a selected folder
2122
*
2223
* @return mixed
2324
*/
24-
public function getFiles()
25+
public function getItems()
2526
{
2627
$path = $this->file_location;
2728

28-
if (Input::has('base')) {
29-
$path .= Input::get('base');
30-
}
29+
$base = Input::get('base');
3130

32-
$files = File::files(base_path($path));
31+
$path .= Input::get('base');
3332

34-
$file_info = $this->getFileInfos($files, 'Files');
33+
$type = Input::get('type');
3534

35+
$files = File::files(base_path($path));
36+
$file_info = $this->getFileInfos($files, $type);
3637
$directories = parent::getDirectories($path);
3738

38-
if (Input::get('show_list') == 1) {
39-
$view = 'laravel-filemanager::files-list';
40-
} else {
41-
$view = 'laravel-filemanager::files';
42-
}
43-
44-
return View::make($view)
45-
->with('files', $files)
46-
->with('file_info', $file_info)
47-
->with('directories', $directories)
48-
->with('base', Input::get('base'))
49-
->with('dir_location', $this->file_location);
50-
}
51-
52-
53-
/**
54-
* Get the images to load for a selected folder
55-
*
56-
* @return mixed
57-
*/
58-
public function getImages()
59-
{
60-
$path = $this->file_location;
39+
$dir_location = $this->dir_location;
40+
$view = 'laravel-filemanager::images';
6141

62-
if (Input::has('base')) {
63-
$path .= Input::get('base');
42+
if ($type !== 'Images') {
43+
$dir_location = $this->file_location;
44+
$view = 'laravel-filemanager::files';
6445
}
6546

66-
$files = File::files(base_path($path));
67-
68-
$file_info = $this->getFileInfos($files, 'Images');
69-
70-
$directories = parent::getDirectories($path);
71-
7247
if (Input::get('show_list') == 1) {
73-
$view = 'laravel-filemanager::images-list';
74-
} else {
75-
$view = 'laravel-filemanager::images';
48+
$view .= '-list';
7649
}
7750

7851
return View::make($view)
79-
->with('files', $files)
80-
->with('file_info', $file_info)
81-
->with('directories', $directories)
82-
->with('base', Input::get('base'))
83-
->with('dir_location', $this->dir_location);
52+
->with(compact('files', 'file_info', 'directories', 'base', 'dir_location'));
8453
}
8554

8655

src/controllers/LfmController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ private function checkSharedFolderExists()
8080

8181
public function getDirectories($path)
8282
{
83+
$thumb_folder_name = Config::get('lfm.thumb_folder_name');
8384
$all_directories = File::directories(base_path($path));
8485

8586
$arr_dir = [];
@@ -88,7 +89,7 @@ public function getDirectories($path)
8889
$path_parts = explode('/', $directory);
8990
$dir_name = end($path_parts);
9091

91-
if ($dir_name !== 'thumbs') {
92+
if ($dir_name !== $thumb_folder_name) {
9293
$arr_dir[] = $dir_name;
9394
}
9495
}

src/controllers/RenameController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function getRename()
3636
$new_name = str_replace($extension, '', $new_name) . '.' . $extension;
3737
}
3838

39-
$thumb_path = $user_path . 'thumbs/';
39+
$thumb_path = $user_path . Config::get('lfm.thumb_folder_name') . '/';
4040

4141
$new_file = $user_path . $new_name;
4242
$new_thumb = $thumb_path . $new_name;

src/controllers/UploadController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ public function upload()
6161

6262
private function makeThumb($destinationPath, $new_filename)
6363
{
64-
if (!File::exists($destinationPath . "thumbs")) {
65-
File::makeDirectory($destinationPath . "thumbs");
64+
$thumb_folder_name = Config::get('lfm.thumb_folder_name');
65+
66+
if (!File::exists($destinationPath . $thumb_folder_name)) {
67+
File::makeDirectory($destinationPath . $thumb_folder_name);
6668
}
6769

6870
$thumb_img = Image::make($destinationPath . $new_filename);
6971
$thumb_img->fit(200, 200)
70-
->save($destinationPath . "thumbs/" . $new_filename);
72+
->save($destinationPath . $thumb_folder_name . '/' . $new_filename);
7173
unset($thumb_img);
7274
}
7375

src/routes.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
Route::any('/upload', 'Unisharp\Laravelfilemanager\controllers\UploadController@upload');
1313

1414
// list images & files
15-
Route::get('/jsonimages', 'Unisharp\Laravelfilemanager\controllers\ItemsController@getImages');
16-
Route::get('/jsonfiles', 'Unisharp\Laravelfilemanager\controllers\ItemsController@getFiles');
15+
Route::get('/jsonitems', 'Unisharp\Laravelfilemanager\controllers\ItemsController@getItems');
1716

1817
// folders
1918
Route::get('/newfolder', 'Unisharp\Laravelfilemanager\controllers\FolderController@getAddfolder');

src/views/crop.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<div class="img-preview center-block"></div>
1111
<br>
1212
<button class="btn btn-primary" onclick="performCrop()">{{ Lang::get('laravel-filemanager::lfm.btn-crop') }}</button>
13-
<button class="btn btn-info" onclick="loadImages()">{{ Lang::get('laravel-filemanager::lfm.btn-cancel') }}</button>
13+
<button class="btn btn-info" onclick="loadItems()">{{ Lang::get('laravel-filemanager::lfm.btn-cancel') }}</button>
1414
<form action="{{url('/laravel-filemanager/crop')}}" role='form' name='cropForm' id='cropForm' mathod='post'>
1515
<input type="hidden" id="img" name="img" value="{{ $img }}">
1616
<input type="hidden" id="dir" name="dir" value="{{ $dir }}">
@@ -61,7 +61,7 @@ function performCrop() {
6161
},
6262
cache: false
6363
}).done(function (data) {
64-
loadImages();
64+
loadItems();
6565
});
6666
}
6767
</script>

src/views/images.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333
@foreach($files as $key => $file)
3434

3535
<?php $file_name = $file_info[$key]['name'];?>
36+
<?php $thumb_src = $dir_location . $base . '/' . Config::get('lfm.thumb_folder_name') . '/' . $file_name . '?r=' . str_random(40);?>
3637

3738
<div class="col-sm-6 col-md-2 img-row">
3839

3940
<div class="thumbnail thumbnail-img" data-id="{{ $file_name }}" id="img_thumbnail_{{ $key }}">
40-
<img id="{{ $file }}" src="{{ $dir_location }}{{ $base }}/thumbs/{{ $file_name }}?r={{ str_random(40) }}" alt="" style="cursor:pointer;" onclick="useFile('{{ $file_name }}')">
41+
<img id="{{ $file }}" src="{{ $thumb_src }}" alt="" style="cursor:pointer;" onclick="useFile('{{ $file_name }}')">
4142
</div>
4243

4344
<div class="caption text-center">

src/views/index.blade.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
}).done(function (data) {
145145
$("#tree1").html(data);
146146
});
147-
loadImages();
147+
loadItems();
148148
refreshFolders();
149149
});
150150
@@ -166,7 +166,7 @@ function showResponse(responseText, statusText, xhr, $form) {
166166
notify(responseText);
167167
}
168168
$("#file_to_upload").val('');
169-
loadImages();
169+
loadItems();
170170
}
171171
172172
$("#uploadForm").ajaxSubmit(options);
@@ -178,15 +178,15 @@ function clickRoot() {
178178
$('#folder_shared > i').removeClass('fa-folder-open').addClass('fa-folder');
179179
$('#folder_root > i').addClass('fa-folder-open').removeClass('fa-folder');
180180
$("#working_dir").val("{{ (Config::get('lfm.allow_multi_user')) ? Auth::user()->user_field : '/'}}");
181-
loadImages();
181+
loadItems();
182182
}
183183
184184
function clickShared() {
185185
$('.folder-item').removeClass('fa-folder-open').addClass('fa-folder');
186186
$('#folder_root > i').removeClass('fa-folder-open').addClass('fa-folder');
187187
$('#folder_shared > i').addClass('fa-folder-open').removeClass('fa-folder');
188188
$("#working_dir").val("{{ Config::get('lfm.shared_folder_name') }}");
189-
loadImages();
189+
loadItems();
190190
}
191191
192192
function clickFolder(x, y) {
@@ -204,7 +204,7 @@ function clickFolder(x, y) {
204204
}
205205
}
206206
$("#working_dir").val("{{ (Config::get('lfm.allow_multi_user')) ? Auth::user()->user_field.'/' : '' }}" + $('#' + x).data('id'));
207-
loadImages();
207+
loadItems();
208208
}
209209
210210
function clickSharedFolder(x, y) {
@@ -222,7 +222,7 @@ function clickSharedFolder(x, y) {
222222
}
223223
}
224224
$("#working_dir").val("{{ Config::get('lfm.shared_folder_name').'/' }}" + $('#' + x).data('id'));
225-
loadImages();
225+
loadItems();
226226
}
227227
228228
function download(x) {
@@ -233,20 +233,21 @@ function download(x) {
233233
+ x;
234234
}
235235
236-
function loadImages() {
237-
var load_url = "/laravel-filemanager/jsonimages";
236+
function loadItems() {
237+
var type = 'Images';
238238
239239
@if ((Session::has('lfm_type')) && (Session::get('lfm_type') == "Files"))
240-
load_url = "/laravel-filemanager/jsonfiles";
240+
type = 'Files';
241241
@endif
242242
243243
$.ajax({
244244
type: "GET",
245245
dataType: "html",
246-
url: load_url,
246+
url: '/laravel-filemanager/jsonitems',
247247
data: {
248248
base: $("#working_dir").val(),
249-
show_list: $("#show_list").val()
249+
show_list: $("#show_list").val(),
250+
type: type
250251
},
251252
cache: false
252253
}).done(function (data) {
@@ -276,7 +277,7 @@ function trash(x) {
276277
if ($("#working_dir").val() == "{{Auth::user()->user_field}}") {
277278
loadFolders();
278279
}
279-
loadImages();
280+
loadItems();
280281
}
281282
});
282283
}
@@ -298,7 +299,7 @@ function loadFolders() {
298299
});
299300
}
300301
301-
function refreshFolders(){
302+
function refreshFolders() {
302303
var wd = $("#working_dir").val();
303304
if (wd != "/") {
304305
try {
@@ -343,7 +344,7 @@ function notImp() {
343344
}).done(function (data) {
344345
if (data == "OK") {
345346
loadFolders();
346-
loadImages();
347+
loadItems();
347348
refreshFolders();
348349
} else {
349350
notify(data);
@@ -400,7 +401,7 @@ function rename(x) {
400401
cache: false
401402
}).done(function (data) {
402403
if (data == "OK") {
403-
loadImages();
404+
loadItems();
404405
loadFolders();
405406
} else {
406407
notify(data);
@@ -432,24 +433,23 @@ function resizeImage(x) {
432433
433434
$("#thumbnail-display").click(function () {
434435
$("#show_list").val(0);
435-
loadImages();
436+
loadItems();
436437
});
437438
438439
$("#list-display").click(function () {
439440
$("#show_list").val(1);
440-
loadImages();
441+
loadItems();
441442
});
442443
443-
function fileView(x){
444+
function fileView(x) {
444445
var rnd = makeRandom();
445-
$('#fileview_body').html(
446-
"<img class='img img-responsive center-block' src='{{ Config::get('lfm.images_url') }}" + $("#working_dir").val() + "/" + x + "?id=" + rnd + "'>"
447-
);
446+
var img_src = "{{ Config::get('lfm.images_url') }}" + $("#working_dir").val() + "/" + x + "?id=" + rnd;
447+
var img = "<img class='img img-responsive center-block' src='" + img_src + "'>";
448+
$('#fileview_body').html(img);
448449
$('#fileViewModal').modal();
449450
}
450451
451-
function makeRandom()
452-
{
452+
function makeRandom() {
453453
var text = "";
454454
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
455455

src/views/resize.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</table>
4141

4242
<button class="btn btn-primary" onclick="doResize()">{{ Lang::get('laravel-filemanager::lfm.btn-resize') }}</button>
43-
<button class="btn btn-info" onclick="loadImages()">{{ Lang::get('laravel-filemanager::lfm.btn-cancel') }}</button>
43+
<button class="btn btn-info" onclick="loadItems()">{{ Lang::get('laravel-filemanager::lfm.btn-cancel') }}</button>
4444

4545
<input type="hidden" name="ratio" value="{{ $ratio }}"><br>
4646
<input type="hidden" name="scaled" value="{{ $scaled }}"><br>
@@ -87,7 +87,7 @@ function doResize() {
8787
cache: false
8888
}).done(function (data) {
8989
if (data == "OK") {
90-
loadImages();
90+
loadItems();
9191
} else {
9292
notify(data);
9393
}

0 commit comments

Comments
 (0)