1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\LangFileManager\app\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Http\Requests; |
6
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
7
|
|
|
use Backpack\LangFileManager\app\Services\LangFiles; |
8
|
|
|
use Backpack\LangFileManager\app\Models\Language; |
9
|
|
|
use Illuminate\Http\Request; |
10
|
|
|
// VALIDATION: change the requests to match your own file names if you need form validation |
11
|
|
|
use Backpack\LangFileManager\app\Http\Requests\LanguageRequest as StoreRequest; |
12
|
|
|
use Backpack\LangFileManager\app\Http\Requests\LanguageRequest as UpdateRequest; |
13
|
|
|
|
14
|
|
|
class LanguageCrudController extends CrudController |
15
|
|
|
{ |
16
|
|
|
public function __construct() |
17
|
|
|
{ |
18
|
|
|
parent::__construct(); |
19
|
|
|
|
20
|
|
|
$this->crud->setModel("Backpack\LangFileManager\app\Models\Language"); |
21
|
|
|
$this->crud->setRoute('admin/language'); |
22
|
|
|
$this->crud->setEntityNameStrings(trans('backpack::langfilemanager.language'), trans('backpack::langfilemanager.languages')); |
|
|
|
|
23
|
|
|
|
24
|
|
|
$this->crud->setColumns([ |
25
|
|
|
[ |
26
|
|
|
'name' => 'name', |
27
|
|
|
'label' => trans('backpack::langfilemanager.language_name'), |
28
|
|
|
], |
29
|
|
|
[ |
30
|
|
|
'name' => 'active', |
31
|
|
|
'label' => trans('backpack::langfilemanager.active'), |
32
|
|
|
'type' => 'boolean', |
33
|
|
|
], |
34
|
|
|
[ |
35
|
|
|
'name' => 'default', |
36
|
|
|
'label' => trans('backpack::langfilemanager.default'), |
37
|
|
|
'type' => 'boolean', |
38
|
|
|
], |
39
|
|
|
]); |
40
|
|
|
$this->crud->addField([ |
41
|
|
|
'name' => 'name', |
42
|
|
|
'label' => trans('backpack::langfilemanager.language_name'), |
43
|
|
|
'type' => 'text', |
44
|
|
|
]); |
45
|
|
|
$this->crud->addField([ |
46
|
|
|
'name' => 'native', |
47
|
|
|
'label' => trans('backpack::langfilemanager.native_name'), |
48
|
|
|
'type' => 'text', |
49
|
|
|
]); |
50
|
|
|
$this->crud->addField([ |
51
|
|
|
'name' => 'abbr', |
52
|
|
|
'label' => trans('backpack::langfilemanager.code_iso639-1'), |
53
|
|
|
'type' => 'text', |
54
|
|
|
]); |
55
|
|
|
$this->crud->addField([ |
56
|
|
|
'name' => 'flag', |
57
|
|
|
'label' => trans('backpack::langfilemanager.flag_image'), |
58
|
|
|
'type' => 'browse', |
59
|
|
|
]); |
60
|
|
|
$this->crud->addField([ |
61
|
|
|
'name' => 'active', |
62
|
|
|
'label' => trans('backpack::langfilemanager.active'), |
63
|
|
|
'type' => 'checkbox', |
64
|
|
|
]); |
65
|
|
|
$this->crud->addField([ |
66
|
|
|
'name' => 'default', |
67
|
|
|
'label' => trans('backpack::langfilemanager.default'), |
68
|
|
|
'type' => 'checkbox', |
69
|
|
|
]); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function store(StoreRequest $request) |
73
|
|
|
{ |
74
|
|
|
$defaultLang = Language::where('default', 1)->first(); |
75
|
|
|
|
76
|
|
|
// Copy the default language folder to the new language folder |
77
|
|
|
\File::copyDirectory(resource_path('lang/'.$defaultLang->abbr), resource_path('lang/'.$request->input('abbr'))); |
78
|
|
|
|
79
|
|
|
return parent::storeCrud(); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function update(UpdateRequest $request) |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
return parent::updateCrud(); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* After delete remove also the language folder. |
89
|
|
|
* |
90
|
|
|
* @param int $id |
91
|
|
|
* |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
|
|
public function destroy($id) |
95
|
|
|
{ |
96
|
|
|
$language = Language::find($id); |
97
|
|
|
$destroyResult = parent::destroy($id); |
98
|
|
|
|
99
|
|
|
if ($destroyResult) |
100
|
|
|
{ |
101
|
|
|
\File::deleteDirectory(resource_path('lang/' . $language->abbr)); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $destroyResult; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function showTexts(LangFiles $langfile, Language $languages, $lang = '', $file = 'site') |
|
|
|
|
108
|
|
|
{ |
109
|
|
|
// SECURITY |
110
|
|
|
// check if that file isn't forbidden in the config file |
111
|
|
|
if (in_array($file, config('backpack.langfilemanager.language_ignore'))) { |
112
|
|
|
abort('403', trans('backpack::langfilemanager.cant_edit_online')); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
if ($lang) { |
116
|
|
|
$langfile->setLanguage($lang); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$langfile->setFile($file); |
120
|
|
|
$this->data['crud'] = $this->crud; |
121
|
|
|
$this->data['currentFile'] = $file; |
122
|
|
|
$this->data['currentLang'] = $lang ?: config('app.locale'); |
123
|
|
|
$this->data['currentLangObj'] = Language::where('abbr', '=', $this->data['currentLang'])->first(); |
124
|
|
|
$this->data['browsingLangObj'] = Language::where('abbr', '=', config('app.locale'))->first(); |
125
|
|
|
$this->data['languages'] = $languages->orderBy('name')->get(); |
126
|
|
|
$this->data['langFiles'] = $langfile->getlangFiles(); |
127
|
|
|
$this->data['fileArray'] = $langfile->getFileContent(); |
128
|
|
|
$this->data['langfile'] = $langfile; |
129
|
|
|
$this->data['title'] = trans('backpack::langfilemanager.translations'); |
130
|
|
|
|
131
|
|
|
return view('langfilemanager::translations', $this->data); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function updateTexts(LangFiles $langfile, Request $request, $lang = '', $file = 'site') |
|
|
|
|
135
|
|
|
{ |
136
|
|
|
// SECURITY |
137
|
|
|
// check if that file isn't forbidden in the config file |
138
|
|
|
if (in_array($file, config('backpack.langfilemanager.language_ignore'))) { |
139
|
|
|
abort('403', trans('backpack::langfilemanager.cant_edit_online')); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
$message = trans('error.error_general'); |
|
|
|
|
143
|
|
|
$status = false; |
|
|
|
|
144
|
|
|
|
145
|
|
|
if ($lang) { |
146
|
|
|
$langfile->setLanguage($lang); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
$langfile->setFile($file); |
150
|
|
|
|
151
|
|
|
$fields = $langfile->testFields($request->all()); |
152
|
|
|
if (empty($fields)) { |
153
|
|
|
if ($langfile->setFileContent($request->all())) { |
154
|
|
|
\Alert::success(trans('backpack::langfilemanager.saved'))->flash(); |
155
|
|
|
$status = true; |
|
|
|
|
156
|
|
|
} |
157
|
|
|
} else { |
158
|
|
|
$message = trans('admin.language.fields_required'); |
|
|
|
|
159
|
|
|
\Alert::error(trans('backpack::langfilemanager.please_fill_all_fields'))->flash(); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return redirect()->back(); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.