1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Epesi\Core\System\Logo; |
4
|
|
|
|
5
|
|
|
use Epesi\Core\System\Integration\Modules\ModuleView; |
6
|
|
|
use Illuminate\Support\Facades\Auth; |
7
|
|
|
use Epesi\Core\System\Seeds\Form; |
8
|
|
|
use Epesi\Core\System\Database\Models\Variable; |
9
|
|
|
use Illuminate\Support\Facades\Storage; |
10
|
|
|
use Epesi\Core\Layout\Seeds\ActionBar; |
11
|
|
|
use atk4\ui\View; |
12
|
|
|
|
13
|
|
|
class LogoSettings extends ModuleView |
14
|
|
|
{ |
15
|
|
|
protected $label = 'Title & Logo'; |
16
|
|
|
|
17
|
|
|
public static function access() |
18
|
|
|
{ |
19
|
|
|
return Auth::user()->can('modify system settings'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function body() |
23
|
|
|
{ |
24
|
|
|
$layout = $this->add(['View'])->addStyle('max-width:1200px;margin:auto;'); |
25
|
|
|
$layout->add(['Header', __($this->label)]); |
26
|
|
|
$segment = $layout->add(['View', ['ui' => 'segment']]); |
27
|
|
|
|
28
|
|
|
$form = $segment->add(new Form()); |
29
|
|
|
|
30
|
|
|
$form->addField('title', __('Base page title'))->set(Variable::get('system.title')); |
31
|
|
|
$logo = $form->addField('logo', [ |
32
|
|
|
'UploadImg', |
33
|
|
|
'defaultSrc' => url('logo'), |
34
|
|
|
'thumbnail' => (new View(['element'=>'img', 'class' => ['right', 'floated', 'image'], 'ui' => true]))->setStyle('max-width', '150px'), |
35
|
|
|
'placeholder' => __('Upload new logo') |
36
|
|
|
]); |
37
|
|
|
|
38
|
|
|
$logo->onDelete(function($fileName) { |
|
|
|
|
39
|
|
|
$token = md5($fileName); |
40
|
|
|
|
41
|
|
|
Storage::delete(self::alias() . '/tmp/' . $token); |
42
|
|
|
}); |
43
|
|
|
|
44
|
|
|
$logo->onUpload(function ($files) use ($form, $logo) { |
|
|
|
|
45
|
|
|
if ($files === 'error') return $form->error('logo', __('Error uploading image')); |
|
|
|
|
46
|
|
|
|
47
|
|
|
$tmpPath = self::alias() . '/tmp/' . $files['name']; |
48
|
|
|
|
49
|
|
|
$logo->setThumbnailSrc(asset('storage/' . $tmpPath)); |
|
|
|
|
50
|
|
|
|
51
|
|
|
Storage::disk('public')->put($tmpPath, file_get_contents($files['tmp_name'])); |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
$form->onSubmit(function($form) { |
55
|
|
|
$name = $form->model['logo']; |
56
|
|
|
|
57
|
|
|
Storage::disk('public')->move(self::alias() . '/tmp/' . $name, self::alias() . '/' . $name); |
58
|
|
|
|
59
|
|
|
Variable::put('system.title', $form->model['title']); |
60
|
|
|
|
61
|
|
|
Variable::put('system.logo', $name); |
62
|
|
|
|
63
|
|
|
return $form->notify(__('Title and logo updated!')); |
64
|
|
|
}); |
65
|
|
|
|
66
|
|
|
ActionBar::addButton('back')->link(url('view/system')); |
67
|
|
|
|
68
|
|
|
ActionBar::addButton('save')->on('click', $form->submit()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public static function getLogoPath() |
72
|
|
|
{ |
73
|
|
|
return self::alias() . '/' . Variable::get('system.logo', 'epesi-logo.png'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public static function getLogoMeta() |
77
|
|
|
{ |
78
|
|
|
$logoPath = self::getLogoPath(); |
79
|
|
|
|
80
|
|
|
return array_merge(Storage::getMetadata($logoPath), [ |
81
|
|
|
'mime' => Storage::mimeType($logoPath), |
82
|
|
|
'contents' => Storage::get($logoPath) |
83
|
|
|
]); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public static function getTitle() |
87
|
|
|
{ |
88
|
|
|
return Variable::get('system.title', config('epesi.app.title')); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|