Skip to content

Commit 23a26ae

Browse files
committed
Merge pull request #2 from UniSharp/master
Merge dev-master
2 parents fef3166 + 8ad8f3a commit 23a26ae

21 files changed

+344
-236
lines changed

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
The MIT License (MIT)
22

3+
Copyright (c) 2015 Trevor Sawler <https://github.com/tsawler>
4+
Copyright (c) 2015 All contributors from GitHub
35
Copyright (c) 2015 UniSharp
46

57
Permission is hereby granted, free of charge, to any person obtaining a copy

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
## Requirements
1111

1212
* php >= 5.5
13-
* Laravel 5 (working to support Laravel 4)
13+
* Laravel 5
1414
* requires [intervention/image](https://github.com/Intervention/image)(to make thumbs, crop and resize images).
1515

1616
## Installation
@@ -48,8 +48,10 @@
4848
```javascript
4949
<script>
5050
CKEDITOR.replace( 'editor', {
51-
filebrowserImageBrowseUrl: '/laravel-filemanager?type=Images'
52-
filebrowserBrowseUrl: '/laravel-filemanager?type=Files'
51+
filebrowserImageBrowseUrl: '/laravel-filemanager?type=Images',
52+
filebrowserImageUploadUrl: '/laravel-filemanager/upload?type=Images&_token={{csrf_token()}}',
53+
filebrowserBrowseUrl: '/laravel-filemanager?type=Files',
54+
filebrowserUploadUrl: '/laravel-filemanager/upload?type=Files&_token={{csrf_token()}}'
5355
});
5456
</script>
5557
```

src/controllers/CropController.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ class CropController extends LfmController {
1919
*/
2020
public function getCrop()
2121
{
22-
$dir = Input::get('dir');
23-
$image = Input::get('img');
22+
$working_dir = Input::get('working_dir');
23+
$img = parent::getUrl() . Input::get('img');
2424

2525
return View::make('laravel-filemanager::crop')
26-
->with('img', Config::get('lfm.images_url') . $dir . "/" . $image)
27-
->with('dir', $dir)
28-
->with('image', $image);
26+
->with(compact('working_dir', 'img'));
2927
}
3028

3129

@@ -34,22 +32,21 @@ public function getCrop()
3432
*/
3533
public function getCropimage()
3634
{
37-
$dir = Input::get('dir');
38-
$img = Input::get('img');
35+
$image = Input::get('img');
3936
$dataX = Input::get('dataX');
4037
$dataY = Input::get('dataY');
4138
$dataHeight = Input::get('dataHeight');
4239
$dataWidth = Input::get('dataWidth');
4340

4441
// crop image
45-
$image = Image::make(public_path() . $img);
46-
$image->crop($dataWidth, $dataHeight, $dataX, $dataY)
47-
->save(public_path() . $img);
42+
$tmp_img = Image::make(public_path() . $image);
43+
$tmp_img->crop($dataWidth, $dataHeight, $dataX, $dataY)
44+
->save(public_path() . $image);
4845

4946
// make new thumbnail
50-
$thumb_img = Image::make(public_path() . $img);
47+
$thumb_img = Image::make(public_path() . $image);
5148
$thumb_img->fit(200, 200)
52-
->save(base_path() . "/" . Config::get('lfm.images_dir') . $dir . "/thumbs/" . basename($img));
49+
->save(parent::getPath('thumb') . parent::getFileName($image));
5350
}
5451

5552
}

src/controllers/DeleteController.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Facades\File;
66
use Illuminate\Support\Facades\Input;
77
use Illuminate\Support\Facades\Session;
8+
use Lang;
89

910
/**
1011
* Class CropController
@@ -20,24 +21,19 @@ class DeleteController extends LfmController {
2021
public function getDelete()
2122
{
2223
$name_to_delete = Input::get('items');
23-
$base = Input::get('base');
2424

25-
$file_path = base_path() . '/' . $this->file_location;
26-
27-
if ($base !== '/') {
28-
$file_path = $file_path . $base . '/';
29-
}
25+
$file_path = parent::getPath();
3026

3127
$file_to_delete = $file_path . $name_to_delete;
32-
$thumb_to_delete = $file_path . 'thumbs/' . $name_to_delete;
28+
$thumb_to_delete = parent::getPath('thumb') . $name_to_delete;
3329

3430
if (!File::exists($file_to_delete)) {
3531
return $file_to_delete . ' not found!';
3632
}
3733

3834
if (File::isDirectory($file_to_delete)) {
3935
if (sizeof(File::files($file_to_delete)) != 0) {
40-
return 'You cannot delete this folder because it is not empty!';
36+
return Lang::get('laravel-filemanager::lfm.error-delete');
4137
}
4238

4339
File::deleteDirectory($file_to_delete);

src/controllers/DownloadController.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@ class DownloadController extends LfmController {
1919
*/
2020
public function getDownload()
2121
{
22-
$file_to_download = Input::get('file');
23-
$dir = Input::get('dir');
24-
return Response::download(base_path()
25-
. "/"
26-
. $this->file_location
27-
. $dir
28-
. "/"
29-
. $file_to_download);
22+
return Response::download(parent::getPath() . Input::get('file'));
3023
}
3124

3225
}

src/controllers/FolderController.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Support\Facades\Session;
88
use Illuminate\Support\Facades\View;
99
use Illuminate\Support\Str;
10+
use Lang;
1011

1112
/**
1213
* Class FolderController
@@ -27,7 +28,7 @@ public function getFolders()
2728
$share_path = $this->file_location . Config::get('lfm.shared_folder_name');
2829
$shared_folders = parent::getDirectories($share_path);
2930

30-
return View::make("laravel-filemanager::tree")
31+
return View::make('laravel-filemanager::tree')
3132
->with('dirs', $directories)
3233
->with('shares', $shared_folders);
3334
}
@@ -42,15 +43,15 @@ public function getAddfolder()
4243
{
4344
$folder_name = Input::get('name');
4445

45-
$path = base_path($this->file_location . Input::get('base')) . "/" . $folder_name;
46+
$path = parent::getPath() . $folder_name;
4647

4748
if (!File::exists($path)) {
4849
File::makeDirectory($path, $mode = 0777, true, true);
49-
return "OK";
50+
return 'OK';
5051
} else if (empty($folder_name)) {
51-
return 'Folder name cannot be empty!';
52+
return Lang::get('laravel-filemanager::lfm.error-folder-name');
5253
} else {
53-
return "A folder with this name already exists!";
54+
return Lang::get('laravel-filemanager::lfm.error-folder-exist');
5455
}
5556
}
5657

src/controllers/ItemsController.php

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,17 @@ class ItemsController extends LfmController {
2424
*/
2525
public function getItems()
2626
{
27-
$path = $this->file_location;
28-
29-
$base = Input::get('base');
30-
31-
$path .= Input::get('base');
32-
3327
$type = Input::get('type');
28+
$view = $this->getView($type);
29+
$path = $this->file_location . Input::get('working_dir');
3430

35-
$files = File::files(base_path($path));
36-
$file_info = $this->getFileInfos($files, $type);
31+
$files = File::files(base_path($path));
32+
$file_info = $this->getFileInfos($files, $type);
3733
$directories = parent::getDirectories($path);
38-
39-
$dir_location = $this->dir_location;
40-
$view = 'laravel-filemanager::images';
41-
42-
if ($type !== 'Images') {
43-
$dir_location = $this->file_location;
44-
$view = 'laravel-filemanager::files';
45-
}
46-
47-
if (Input::get('show_list') == 1) {
48-
$view .= '-list';
49-
}
34+
$thumb_url = parent::getUrl('thumb');
5035

5136
return View::make($view)
52-
->with(compact('files', 'file_info', 'directories', 'base', 'dir_location'));
37+
->with(compact('files', 'file_info', 'directories', 'thumb_url'));
5338
}
5439

5540

@@ -58,8 +43,7 @@ private function getFileInfos($files, $type = 'Images')
5843
$file_info = [];
5944

6045
foreach ($files as $key => $file) {
61-
$path_parts = explode('/', $file);
62-
$file_name = end($path_parts);
46+
$file_name = parent::getFileName($file);
6347
$file_created = filemtime($file);
6448

6549
$file_size = number_format((File::size($file) / 1024), 2, ".", "");
@@ -99,4 +83,19 @@ private function getFileInfos($files, $type = 'Images')
9983
return $file_info;
10084
}
10185

86+
87+
private function getView($type = 'Images')
88+
{
89+
$view = 'laravel-filemanager::images';
90+
91+
if ($type !== 'Images') {
92+
$view = 'laravel-filemanager::files';
93+
}
94+
95+
if (Input::get('show_list') == 1) {
96+
$view .= '-list';
97+
}
98+
99+
return $view;
100+
}
102101
}

src/controllers/LfmController.php

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public function __construct()
3636
}
3737

3838

39+
/*****************************
40+
*** Private Functions ***
41+
*****************************/
42+
43+
3944
private function setFilePath()
4045
{
4146
if ((Session::has('lfm_type')) && (Session::get('lfm_type') == 'Files')) {
@@ -59,7 +64,7 @@ private function setDirPath()
5964
private function checkMyFolderExists()
6065
{
6166
if (\Config::get('lfm.allow_multi_user') === true) {
62-
$path = base_path($this->file_location . Input::get('base'));
67+
$path = base_path($this->file_location . Input::get('working_dir'));
6368

6469
if (!File::exists($path)) {
6570
File::makeDirectory($path, $mode = 0777, true, true);
@@ -78,6 +83,47 @@ private function checkSharedFolderExists()
7883
}
7984

8085

86+
private function formatLocation($location, $type = null)
87+
{
88+
$working_dir = Input::get('working_dir');
89+
90+
if ($working_dir !== '/') {
91+
$location .= $working_dir . '/';
92+
}
93+
94+
if ($type === 'thumb') {
95+
$location = $location . Config::get('lfm.thumb_folder_name') . '/';
96+
}
97+
98+
return $location;
99+
}
100+
101+
102+
/****************************
103+
*** Shared Functions ***
104+
****************************/
105+
106+
107+
public function getPath($type = null)
108+
{
109+
$path = base_path() . '/' . $this->file_location;
110+
111+
$path = $this->formatLocation($path, $type);
112+
113+
return $path;
114+
}
115+
116+
117+
public function getUrl($type = null)
118+
{
119+
$url = $this->dir_location;
120+
121+
$url = $this->formatLocation($url, $type);
122+
123+
return $url;
124+
}
125+
126+
81127
public function getDirectories($path)
82128
{
83129
$thumb_folder_name = Config::get('lfm.thumb_folder_name');
@@ -86,8 +132,7 @@ public function getDirectories($path)
86132
$arr_dir = [];
87133

88134
foreach ($all_directories as $directory) {
89-
$path_parts = explode('/', $directory);
90-
$dir_name = end($path_parts);
135+
$dir_name = $this->getFileName($directory);
91136

92137
if ($dir_name !== $thumb_folder_name) {
93138
$arr_dir[] = $dir_name;
@@ -98,6 +143,16 @@ public function getDirectories($path)
98143
}
99144

100145

146+
public function getFileName($file)
147+
{
148+
$path_parts = explode('/', $file);
149+
150+
$filename = end($path_parts);
151+
152+
return $filename;
153+
}
154+
155+
101156
/**
102157
* Show the filemanager
103158
*
@@ -111,16 +166,13 @@ public function show()
111166
Session::put('lfm_type', 'Images');
112167
}
113168

114-
if (Input::has('base')) {
115-
$working_dir = Input::get('base');
116-
$base = $this->file_location . Input::get('base') . "/";
169+
if (Input::has('working_dir')) {
170+
$working_dir = Input::get('working_dir');
117171
} else {
118-
$working_dir = "/";
119-
$base = $this->file_location;
172+
$working_dir = '/';
120173
}
121174

122175
return View::make('laravel-filemanager::index')
123-
->with('base', $base)
124176
->with('working_dir', $working_dir);
125177
}
126178

0 commit comments

Comments
 (0)