1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace A17\Twill\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use A17\Twill\Services\Blocks\BlockMaker; |
6
|
|
|
use Illuminate\Filesystem\Filesystem; |
7
|
|
|
use Illuminate\Support\Collection; |
8
|
|
|
use Str; |
9
|
|
|
use Symfony\Component\Finder\SplFileInfo; |
10
|
|
|
|
11
|
|
|
class IconsController extends Controller |
12
|
|
|
{ |
13
|
|
|
public function __construct(Filesystem $files, BlockMaker $blockMaker) |
14
|
|
|
{ |
15
|
|
|
$this->files = $files; |
|
|
|
|
16
|
|
|
$this->blockMaker = $blockMaker; |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function index() |
20
|
|
|
{ |
21
|
|
|
$icons = collect( |
22
|
|
|
config('twill.block_editor.directories.source.icons') |
23
|
|
|
)->reduce(function (Collection $keep, $path) { |
24
|
|
|
if (!$this->files->exists($path)) { |
25
|
|
|
return $keep; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$files = collect($this->files->files($path))->map(function ( |
29
|
|
|
SplFileInfo $file |
30
|
|
|
) { |
31
|
|
|
if (in_array($file->getFilename(), config('twill.internal_icons'))) { |
32
|
|
|
return null; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return [ |
36
|
|
|
'name' => Str::before($file->getFilename(), '.svg'), |
37
|
|
|
'url' => route('admin.icons.show', [ |
38
|
|
|
'file' => $file->getFilename(), |
39
|
|
|
]), |
40
|
|
|
]; |
41
|
|
|
})->filter(); |
42
|
|
|
|
43
|
|
|
return $keep->merge($files); |
44
|
|
|
}, collect()); |
45
|
|
|
|
46
|
|
|
return view('twill::blocks.icons', compact('icons')); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function show($file) |
50
|
|
|
{ |
51
|
|
|
$file = $this->blockMaker->getIconFile($file, false); |
52
|
|
|
|
53
|
|
|
if (!$this->files->exists($file)) { |
54
|
|
|
abort(404); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return response()->stream(function () use ($file) { |
58
|
|
|
echo $this->files->get($file); |
59
|
|
|
}, 200, ["Content-Type" => "image/svg+xml"]); |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|