Skip to content

Commit 09920b0

Browse files
committed
Rename improvements; file list improvements
1 parent 29bb94a commit 09920b0

File tree

8 files changed

+150
-87
lines changed

8 files changed

+150
-87
lines changed

src/controllers/DownloadController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Illuminate\Support\Facades\Session;
88

99
/**
10-
* Class LfmController
10+
* Class DownloadController
1111
* @package Tsawler\Laravelfilemanager\controllers
1212
*/
1313
class DownloadController extends Controller {
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php namespace Tsawler\Laravelfilemanager\controllers;
2+
3+
use App\Http\Controllers\Controller;
4+
use Illuminate\Support\Facades\Config;
5+
use Illuminate\Support\Facades\File;
6+
use Illuminate\Support\Facades\Input;
7+
use Illuminate\Support\Facades\Redirect;
8+
use Illuminate\Support\Str;
9+
use Illuminate\Support\Facades\Session;
10+
use Illuminate\Support\Facades\View;
11+
use Intervention\Image\Facades\Image;
12+
13+
/**
14+
* Class ItemsController
15+
* @package Tsawler\Laravelfilemanager\controllers
16+
*/
17+
class ItemsController extends Controller {
18+
19+
20+
/**
21+
* @var
22+
*/
23+
protected $file_location;
24+
25+
26+
/**
27+
* constructor
28+
*/
29+
function __construct()
30+
{
31+
if (Session::get('lfm_type') == "Images")
32+
$this->file_location = Config::get('lfm.images_dir');
33+
else
34+
$this->file_location = Config::get('lfm.files_dir');
35+
}
36+
37+
38+
public function getFiles()
39+
{
40+
return "List of files";
41+
}
42+
43+
44+
/**
45+
* Get the images to load for a selected folder
46+
*
47+
* @return mixed
48+
*/
49+
public function getImages()
50+
{
51+
if (Input::has('base'))
52+
{
53+
$files = File::files(base_path($this->file_location . Input::get('base')));
54+
$all_directories = File::directories(base_path($this->file_location . Input::get('base')));
55+
} else
56+
{
57+
$files = File::files(base_path($this->file_location));
58+
$all_directories = File::directories(base_path($this->file_location));
59+
}
60+
61+
$directories = [];
62+
63+
foreach ($all_directories as $directory)
64+
{
65+
if (basename($directory) != "thumbs")
66+
{
67+
$directories[] = basename($directory);
68+
}
69+
}
70+
71+
$file_info = [];
72+
73+
foreach ($files as $file)
74+
{
75+
$file_name = $file;
76+
$file_size = number_format((Image::make($file)->filesize() / 1024), 2, ".", "");
77+
if ($file_size > 1000)
78+
{
79+
$file_size = number_format((Image::make($file)->filesize() / 1024), 2, ".", "") . " Mb";
80+
} else
81+
{
82+
$file_size = $file_size . " Kb";
83+
}
84+
$file_created = filemtime($file);
85+
$file_type = Image::make($file)->mime();
86+
$file_info[] = [
87+
'name' => $file_name,
88+
'size' => $file_size,
89+
'created' => $file_created,
90+
'type' => $file_type
91+
];
92+
}
93+
94+
if ((Session::has('lfm_type')) && (Session::get('lfm_type') == "Images"))
95+
$dir_location = Config::get('lfm.images_url');
96+
else
97+
$dir_location = Config::get('lfm.files_url');
98+
99+
if (Input::get('show_list') == 1)
100+
{
101+
return View::make('laravel-filemanager::images-list')
102+
->with('directories', $directories)
103+
->with('base', Input::get('base'))
104+
->with('file_info', $file_info)
105+
->with('dir_location', $dir_location);
106+
} else
107+
{
108+
return View::make('laravel-filemanager::images')
109+
->with('files', $files)
110+
->with('directories', $directories)
111+
->with('base', Input::get('base'))
112+
->with('dir_location', $dir_location);
113+
}
114+
115+
}
116+
117+
}

src/controllers/LfmController.php

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -66,85 +66,4 @@ public function show()
6666
->with('working_dir', $working_dir);
6767
}
6868

69-
70-
71-
public function getFiles()
72-
{
73-
return "List of files";
74-
}
75-
76-
77-
/**
78-
* Get the images to load for a selected folder
79-
*
80-
* @return mixed
81-
*/
82-
public function getImages()
83-
{
84-
if (Input::has('base'))
85-
{
86-
$files = File::files(base_path($this->file_location . Input::get('base')));
87-
$all_directories = File::directories(base_path($this->file_location . Input::get('base')));
88-
} else
89-
{
90-
$files = File::files(base_path($this->file_location));
91-
$all_directories = File::directories(base_path($this->file_location));
92-
}
93-
94-
$directories = [];
95-
96-
foreach ($all_directories as $directory)
97-
{
98-
if (basename($directory) != "thumbs")
99-
{
100-
$directories[] = basename($directory);
101-
}
102-
}
103-
104-
$file_info = [];
105-
106-
foreach ($files as $file)
107-
{
108-
$file_name = $file;
109-
$file_size = number_format((Image::make($file)->filesize() / 1024), 2, ".", "");
110-
if ($file_size > 1000)
111-
{
112-
$file_size = number_format((Image::make($file)->filesize() / 1024), 2, ".", "") . " Mb";
113-
} else
114-
{
115-
$file_size = $file_size . " Kb";
116-
}
117-
$file_created = filemtime($file);
118-
$file_type = Image::make($file)->mime();
119-
$file_info[] = [
120-
'name' => $file_name,
121-
'size' => $file_size,
122-
'created' => $file_created,
123-
'type' => $file_type
124-
];
125-
}
126-
127-
if ((Session::has('lfm_type')) && (Session::get('lfm_type') == "Images"))
128-
$dir_location = Config::get('lfm.images_url');
129-
else
130-
$dir_location = Config::get('lfm.files_url');
131-
132-
if (Input::get('show_list') == 1)
133-
{
134-
return View::make('laravel-filemanager::images-list')
135-
->with('directories', $directories)
136-
->with('base', Input::get('base'))
137-
->with('file_info', $file_info)
138-
->with('dir_location', $dir_location);
139-
} else
140-
{
141-
return View::make('laravel-filemanager::images')
142-
->with('files', $files)
143-
->with('directories', $directories)
144-
->with('base', Input::get('base'))
145-
->with('dir_location', $dir_location);
146-
}
147-
148-
}
149-
15069
}

src/controllers/RenameController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function __construct()
2323
$this->file_location = Config::get('lfm.files_dir');
2424
}
2525

26+
2627
/**
2728
* @return string
2829
*/
@@ -47,6 +48,9 @@ function getRename(){
4748
return "OK";
4849
} else
4950
{
51+
$extension = File::extension(base_path() . "/" . $this->file_location . $file_to_rename);
52+
$new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension;
53+
5054
File::move(base_path() . "/" . $this->file_location . $file_to_rename,
5155
base_path() . "/" . $this->file_location . $new_name);
5256

@@ -73,6 +77,9 @@ function getRename(){
7377
base_path() . "/" . $this->file_location . $dir . "/" . $new_name);
7478
} else
7579
{
80+
$extension = File::extension(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename);
81+
$new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension;
82+
7683
File::move(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename,
7784
base_path() . "/" . $this->file_location . $dir . "/" . $new_name);
7885

src/controllers/ResizeController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Intervention\Image\Facades\Image;
88

99
/**
10-
* Class ScaleController
10+
* Class ResizeController
1111
* @package Tsawler\Laravelfilemanager\controllers
1212
*/
1313
class ResizeController extends Controller {

src/controllers/UploadController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Intervention\Image\Facades\Image;
1010

1111
/**
12-
* Class LfmController
12+
* Class UploadController
1313
* @package Tsawler\Laravelfilemanager\controllers
1414
*/
1515
class UploadController extends Controller {

src/routes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
Route::any('/laravel-filemanager/upload', 'Tsawler\Laravelfilemanager\controllers\UploadController@upload');
1313

1414
// list images & files
15-
Route::get('/laravel-filemanager/jsonimages', 'Tsawler\Laravelfilemanager\controllers\LfmController@getImages');
16-
Route::get('/laravel-filemanager/jsonfiles', 'Tsawler\Laravelfilemanager\controllers\LfmController@getFiles');
15+
Route::get('/laravel-filemanager/jsonimages', 'Tsawler\Laravelfilemanager\controllers\ItemsController@getImages');
16+
Route::get('/laravel-filemanager/jsonfiles', 'Tsawler\Laravelfilemanager\controllers\ItemsController@getFiles');
1717

1818
// folders
1919
Route::get('/laravel-filemanager/newfolder', 'Tsawler\Laravelfilemanager\controllers\FolderController@getAddfolder');

src/views/images-list.blade.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<th>Size</th>
88
<th>Type</th>
99
<th>Modified</th>
10+
<th>Action</th>
1011
</tr>
1112
</thead>
1213
<tbody>
@@ -22,16 +23,21 @@
2223
<td></td>
2324
<td>Folder</td>
2425
<td></td>
26+
<td></td>
2527
</tr>
2628
@endforeach
2729

2830
@foreach($file_info as $file)
2931
<tr>
3032
<td>
3133
<i class="fa fa-image"></i>
32-
<a href="javascript:useFile('{!! basename($file['name']) !!}')">
34+
<a href="javascript:useFile('<?= basename($file['name']) ?>')">
3335
{!! basename($file['name']) !!}
3436
</a>
37+
&nbsp;&nbsp;
38+
<a href="javascript:rename('<?= basename($file['name']) ?>')">
39+
<i class="fa fa-edit"></i>
40+
</a>
3541
</td>
3642
<td>
3743
{!! $file['size'] !!}
@@ -42,6 +48,20 @@
4248
<td>
4349
{!! date("Y-m-d h:m", $file['created']) !!}
4450
</td>
51+
<td>
52+
<a href="javascript:trash('<?= basename($file['name']) ?>')">
53+
<i class="fa fa-trash fa-fw"></i>
54+
</a>
55+
<a href="javascript:cropImage('<?= basename($file['name']) ?>')">
56+
<i class="fa fa-crop fa-fw"></i>
57+
</a>
58+
<a href="javascript:resizeImage('<?= basename($file['name']) ?>')">
59+
<i class="fa fa-arrows fa-fw"></i>
60+
</a>
61+
<a href="javascript:notImp()">
62+
<i class="fa fa-rotate-left fa-fw"></i>
63+
</a>
64+
</td>
4565
</tr>
4666
@endforeach
4767
</tbody>

0 commit comments

Comments
 (0)