1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace crocodicstudio\crudbooster\Modules\SettingModule; |
4
|
|
|
|
5
|
|
|
use crocodicstudio\crudbooster\controllers\CBController; |
6
|
|
|
use Illuminate\Support\Facades\Storage; |
7
|
|
|
use Illuminate\Support\Facades\Request; |
8
|
|
|
use Illuminate\Support\Facades\Cache; |
9
|
|
|
use CRUDBooster; |
|
|
|
|
10
|
|
|
|
11
|
|
|
class AdminSettingsController extends CBController |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* AdminSettingsController constructor. |
15
|
|
|
*/ |
16
|
|
|
public function __construct() |
17
|
|
|
{ |
18
|
|
|
$this->table = 'cms_settings'; |
19
|
|
|
$this->title_field = "name"; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function cbInit() |
23
|
|
|
{ |
24
|
|
|
$this->index_orderby = ['name' => 'asc']; |
|
|
|
|
25
|
|
|
|
26
|
|
|
$this->setButtons(); |
27
|
|
|
|
28
|
|
|
$this->col = []; |
29
|
|
|
|
30
|
|
|
$this->form = SettingsForm::makeForm(request('group_setting', 'General Setting')); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function getShow() |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$this->cbLoader(); |
36
|
|
|
|
37
|
|
|
$this->allowOnlySuperAdmin(); |
38
|
|
|
|
39
|
|
|
$data['page_title'] = urldecode(request('group')); |
|
|
|
|
40
|
|
|
|
41
|
|
|
return view('CbSettings::setting', $data); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function hookBeforeEdit(&$posdata, $id) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$this->return_url = CRUDBooster::mainpath("show")."?group=".$posdata['group_setting']; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function getDeleteFileSetting() |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$id = request('id'); |
52
|
|
|
$content = CRUDBooster::first($this->table, $id)->content; |
53
|
|
|
|
54
|
|
|
Storage::delete($content); |
55
|
|
|
|
56
|
|
|
$this->table()->where('id', $id)->update(['content' => null]); |
57
|
|
|
|
58
|
|
|
CRUDBooster::redirect(Request::server('HTTP_REFERER'), cbTrans('alert_delete_data_success'), 'success'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
function postSaveSetting() |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$this->allowOnlySuperAdmin(); |
64
|
|
|
|
65
|
|
|
$group = request('group_setting'); |
66
|
|
|
|
67
|
|
|
$settings = $this->table()->where('group_setting', $group)->get(); |
68
|
|
|
|
69
|
|
|
foreach ($settings as $setting) { |
70
|
|
|
|
71
|
|
|
$name = $setting->name; |
72
|
|
|
|
73
|
|
|
$content = request($name); |
74
|
|
|
if (Request::hasFile($name)) { |
75
|
|
|
$content = $this->uploadFile($setting); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$this->table()->where('name', $name)->update(['content' => $content]); |
79
|
|
|
|
80
|
|
|
Cache::forget('setting_'.$name); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
backWithMsg(cbTrans('Update_Setting')); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
function hookBeforeAdd(&$arr) |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
$arr['name'] = str_slug($arr['label'], '_'); |
89
|
|
|
$this->return_url = CRUDBooster::mainpath("show")."?group=".$arr['group_setting']; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
function hookAfterEdit($id) |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
$row = $this->table()->where($this->primary_key, $id)->first(); |
95
|
|
|
|
96
|
|
|
/* REMOVE CACHE */ |
97
|
|
|
Cache::forget('setting_'.$row->name); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param $name |
102
|
|
|
* @param $set |
103
|
|
|
*/ |
104
|
|
|
private function validateFileType($set) |
105
|
|
|
{ |
106
|
|
|
$name = $set->name; |
107
|
|
|
$rules = [$name => 'image|max:10000']; |
108
|
|
|
|
109
|
|
|
if ($set->content_input_type !== 'upload_image') { |
110
|
|
|
$rules = [$name => 'mimes:doc,docx,xls,xlsx,ppt,pptx,pdf,zip,rar|max:20000']; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
CRUDBooster::valid($rules, 'view'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
private function allowOnlySuperAdmin() |
117
|
|
|
{ |
118
|
|
|
if (CRUDBooster::isSuperadmin()) { |
119
|
|
|
return true; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
CRUDBooster::insertTryLog('view', 'Setting'); |
123
|
|
|
CRUDBooster::denyAccess(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param $set |
128
|
|
|
* @param $name |
129
|
|
|
* @return string |
130
|
|
|
*/ |
131
|
|
|
private function uploadFile($set) |
132
|
|
|
{ |
133
|
|
|
$this->validateFileType($set); |
134
|
|
|
$month = date('Y-m'); |
135
|
|
|
|
136
|
|
|
$file = Request::file($set->name); |
137
|
|
|
//Create Directory Monthly |
138
|
|
|
Storage::makeDirectory($month); |
139
|
|
|
|
140
|
|
|
//Move file to storage |
141
|
|
|
$filename = md5(str_random(5)).'.'.$file->getClientOriginalExtension(); |
142
|
|
|
if ($file->move(storage_path('app'.DIRECTORY_SEPARATOR.$month), $filename)) { |
143
|
|
|
$content = 'uploads/'.$month.'/'.$filename; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
return $content; |
|
|
|
|
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
private function setButtons() |
150
|
|
|
{ |
151
|
|
|
$this->button_delete = true; |
152
|
|
|
$this->button_show = false; |
153
|
|
|
$this->button_cancel = false; |
154
|
|
|
$this->button_import = false; |
155
|
|
|
$this->button_export = false; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths