|
3 | 3 | namespace UniSharp\LaravelFilemanager\Controllers; |
4 | 4 |
|
5 | 5 | use Illuminate\Support\Facades\Storage; |
| 6 | +use Illuminate\Support\Str; |
| 7 | +use UniSharp\LaravelFilemanager\Events\ImageIsRenaming; |
| 8 | +use UniSharp\LaravelFilemanager\Events\ImageWasRenamed; |
6 | 9 | use UniSharp\LaravelFilemanager\Events\FolderIsRenaming; |
7 | 10 | use UniSharp\LaravelFilemanager\Events\FolderWasRenamed; |
8 | 11 | use UniSharp\LaravelFilemanager\Events\FileIsRenaming; |
@@ -35,19 +38,34 @@ public function getRename() |
35 | 38 | } |
36 | 39 | } |
37 | 40 |
|
38 | | - if ($is_directory && config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $new_name)) { |
39 | | - return response()->json(parent::error('folder-alnum'), 400); |
40 | | - } elseif (config('lfm.alphanumeric_filename') && preg_match('/[^.\w-]/i', $new_name)) { |
41 | | - return response()->json(parent::error('file-alnum'), 400); |
42 | | - } elseif ($this->lfm->setName($new_name)->exists()) { |
43 | | - return response()->json(parent::error('rename'), 400); |
44 | | - } |
| 41 | + if ($is_directory && config('lfm.alphanumeric_directory')) { |
| 42 | + if (config('lfm.convert_to_alphanumeric')) { |
| 43 | + $new_name = Str::slug($new_name); |
| 44 | + } |
45 | 45 |
|
46 | | - if (! $is_directory) { |
| 46 | + if (preg_match('/[^\w\-_]/i', $new_name)) { |
| 47 | + return parent::error('folder-alnum'); |
| 48 | + } |
| 49 | + } elseif (!$is_directory && config('lfm.alphanumeric_filename')) { |
| 50 | + // Remove extension for checks to alphanum characters |
47 | 51 | $extension = $old_file->extension(); |
48 | 52 | if ($extension) { |
49 | | - $new_name = str_replace('.' . $extension, '', $new_name) . '.' . $extension; |
| 53 | + $new_name = str_replace('.' . $extension, '', $new_name); |
| 54 | + } |
| 55 | + |
| 56 | + if (config('lfm.convert_to_alphanumeric')) { |
| 57 | + $new_name = Str::slug($new_name); |
| 58 | + } |
| 59 | + |
| 60 | + if (preg_match('/[^\w\-_]/i', $new_name)) { |
| 61 | + return parent::error('file-alnum'); |
50 | 62 | } |
| 63 | + |
| 64 | + $new_name .= ($extension) ? '.' . $extension : null; |
| 65 | + } |
| 66 | + |
| 67 | + if ($this->lfm->setName($new_name)->exists()) { |
| 68 | + return parent::error('rename'); |
51 | 69 | } |
52 | 70 |
|
53 | 71 | $new_path = $this->lfm->setName($new_name)->path('absolute'); |
|
0 commit comments