|
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
|
|
|
protected static $defaultLogo = 'epesi-logo.png'; |
|
18
|
|
|
|
|
19
|
|
|
public static function access() |
|
20
|
|
|
{ |
|
21
|
|
|
return Auth::user()->can('modify system settings'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function body() |
|
25
|
|
|
{ |
|
26
|
|
|
$layout = $this->add(['View'])->addStyle('max-width:1200px;margin:auto;'); |
|
27
|
|
|
$layout->add(['Header', __($this->label)]); |
|
28
|
|
|
$segment = $layout->add(['View', ['ui' => 'segment']]); |
|
29
|
|
|
|
|
30
|
|
|
$form = $segment->add(new Form()); |
|
31
|
|
|
|
|
32
|
|
|
$form->addField('title', __('Base page title'))->set(Variable::get('system.title')); |
|
33
|
|
|
|
|
34
|
|
|
$form->addField('custom_logo', ['CheckBox', 'caption' => __('Use custom logo')])->set((bool) Variable::get('system.logo')); |
|
35
|
|
|
|
|
36
|
|
|
$logo = $form->addField('logo', [ |
|
37
|
|
|
'UploadImg', |
|
38
|
|
|
'defaultSrc' => url('logo'), |
|
39
|
|
|
'thumbnail' => (new View(['element'=>'img', 'class' => ['right', 'floated', 'image'], 'ui' => true]))->setStyle('max-width', '150px'), |
|
40
|
|
|
'placeholder' => __('Upload file to replace system logo') |
|
41
|
|
|
]); |
|
42
|
|
|
|
|
43
|
|
|
$form->addFieldsDisplayRules(['logo' => ['custom_logo' => 'checked']]); |
|
44
|
|
|
|
|
45
|
|
|
$logo->onDelete(function($fileName) use ($logo) { |
|
|
|
|
|
|
46
|
|
|
$this->storage()->delete(self::alias() . '/tmp/' . $fileName); |
|
47
|
|
|
|
|
48
|
|
|
$logo->setThumbnailSrc(asset('storage/' . self::alias() . '/' . self::$defaultLogo)); |
|
|
|
|
|
|
49
|
|
|
}); |
|
50
|
|
|
|
|
51
|
|
|
$logo->onUpload(function ($files) use ($form, $logo) { |
|
|
|
|
|
|
52
|
|
|
if ($files === 'error') return $form->error('logo', __('Error uploading image')); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
$tmpPath = self::alias() . '/tmp/' . $files['name']; |
|
55
|
|
|
|
|
56
|
|
|
$logo->setThumbnailSrc(asset('storage/' . $tmpPath)); |
|
57
|
|
|
|
|
58
|
|
|
$this->storage()->put($tmpPath, file_get_contents($files['tmp_name'])); |
|
59
|
|
|
}); |
|
60
|
|
|
|
|
61
|
|
|
$form->onSubmit(function($form) { |
|
62
|
|
|
if ($name = $form->model['custom_logo']? $form->model['logo']: null) { |
|
63
|
|
|
$storage = $this->storage(); |
|
64
|
|
|
$from = self::alias() . '/tmp/' . $name; |
|
65
|
|
|
$to = self::alias() . '/' . $name; |
|
66
|
|
|
|
|
67
|
|
|
if ($storage->exists($to)) { |
|
68
|
|
|
$storage->delete($to); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$storage->move($from, $to); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
Variable::put('system.logo', $name); |
|
75
|
|
|
|
|
76
|
|
|
Variable::put('system.title', $form->model['title']); |
|
77
|
|
|
|
|
78
|
|
|
return $form->notify(__('Title and logo updated! Refresh page to see changes ...')); |
|
79
|
|
|
}); |
|
80
|
|
|
|
|
81
|
|
|
ActionBar::addButton('back')->link(url('view/system')); |
|
82
|
|
|
|
|
83
|
|
|
ActionBar::addButton('save')->on('click', $form->submit()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public static function getLogoFile() |
|
87
|
|
|
{ |
|
88
|
|
|
return self::storage()->path(self::alias() . '/' . Variable::get('system.logo', self::$defaultLogo)); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public static function getTitle() |
|
92
|
|
|
{ |
|
93
|
|
|
return Variable::get('system.title', config('epesi.app.title')); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public static function storage() |
|
97
|
|
|
{ |
|
98
|
|
|
return Storage::disk('public'); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|