|
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
|
|
|
parent::__construct(); |
|
18
|
|
|
|
|
19
|
|
|
$this->crud->setModel("Backpack\LangFileManager\app\Models\Language"); |
|
20
|
|
|
$this->crud->setRoute("admin/language"); |
|
21
|
|
|
$this->crud->setEntityNameStrings('language', 'languages'); |
|
22
|
|
|
|
|
23
|
|
|
$this->crud->setColumns([ |
|
24
|
|
|
[ |
|
25
|
|
|
'name' => 'name', |
|
26
|
|
|
'label' => 'Language name', |
|
27
|
|
|
], |
|
28
|
|
|
[ |
|
29
|
|
|
'name' => 'active', |
|
30
|
|
|
'label' => 'Active', |
|
31
|
|
|
'type' => 'boolean', |
|
32
|
|
|
], |
|
33
|
|
|
[ |
|
34
|
|
|
'name' => 'default', |
|
35
|
|
|
'label' => 'Default', |
|
36
|
|
|
'type' => 'boolean', |
|
37
|
|
|
], |
|
38
|
|
|
]); |
|
39
|
|
|
$this->crud->addField([ |
|
40
|
|
|
'name' => 'name', |
|
41
|
|
|
'label' => 'Language Name', |
|
42
|
|
|
'type' => 'text', |
|
43
|
|
|
]); |
|
44
|
|
|
$this->crud->addField([ |
|
45
|
|
|
'name' => 'abbr', |
|
46
|
|
|
'label' => 'Code (ISO 639-1)', |
|
47
|
|
|
'type' => 'text', |
|
48
|
|
|
]); |
|
49
|
|
|
$this->crud->addField([ |
|
50
|
|
|
'name' => 'flag', |
|
51
|
|
|
'label' => 'Flag image', |
|
52
|
|
|
'type' => 'browse', |
|
53
|
|
|
]); |
|
54
|
|
|
$this->crud->addField([ |
|
55
|
|
|
'name' => 'active', |
|
56
|
|
|
'label' => 'Active', |
|
57
|
|
|
'type' => 'checkbox', |
|
58
|
|
|
]); |
|
59
|
|
|
$this->crud->addField([ |
|
60
|
|
|
'name' => 'default', |
|
61
|
|
|
'label' => 'Default', |
|
62
|
|
|
'type' => 'checkbox', |
|
63
|
|
|
]); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function store(StoreRequest $request) |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
return parent::storeCrud(); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function update(UpdateRequest $request) |
|
|
|
|
|
|
72
|
|
|
{ |
|
73
|
|
|
return parent::updateCrud(); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function showTexts(LangFiles $langfile, Language $languages, $lang = '', $file = 'site') |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
// SECURITY |
|
79
|
|
|
// check if that file isn't forbidden in the config file |
|
80
|
|
|
if (in_array($file, config('langfilemanager.language_ignore'))) { |
|
81
|
|
|
abort('403', 'This language file cannot be edited online.'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
if ($lang) { |
|
85
|
|
|
$langfile->setLanguage($lang); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$langfile->setFile($file); |
|
89
|
|
|
$this->data['crud'] = $this->crud; |
|
90
|
|
|
$this->data['currentFile'] = $file; |
|
91
|
|
|
$this->data['currentLang'] = $lang ?: config('app.locale'); |
|
92
|
|
|
$this->data['currentLangObj'] = Language::where('abbr', '=', $this->data['currentLang'])->first(); |
|
93
|
|
|
$this->data['browsingLangObj'] = Language::where('abbr', '=', config('app.locale'))->first(); |
|
94
|
|
|
$this->data['languages'] = $languages->orderBy('name')->get(); |
|
95
|
|
|
$this->data['langFiles'] = $langfile->getlangFiles(); |
|
96
|
|
|
$this->data['fileArray'] = $langfile->getFileContent(); |
|
97
|
|
|
$this->data['langfile'] = $langfile; |
|
98
|
|
|
$this->data['title'] = 'Translations'; |
|
99
|
|
|
|
|
100
|
|
|
return view('langfilemanager::translations', $this->data); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function updateTexts(LangFiles $langfile, Request $request, $lang = '', $file = 'site') |
|
|
|
|
|
|
104
|
|
|
{ |
|
105
|
|
|
// SECURITY |
|
106
|
|
|
// check if that file isn't forbidden in the config file |
|
107
|
|
|
if (in_array($file, config('langfilemanager.language_ignore'))) { |
|
108
|
|
|
abort('403', 'This language file cannot be edited online.'); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
$message = trans('error.error_general'); |
|
|
|
|
|
|
112
|
|
|
$status = false; |
|
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
if ($lang) { |
|
115
|
|
|
$langfile->setLanguage($lang); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
$langfile->setFile($file); |
|
119
|
|
|
|
|
120
|
|
|
$fields = $langfile->testFields($request->all()); |
|
121
|
|
|
if (empty($fields)) { |
|
122
|
|
|
if ($langfile->setFileContent($request->all())) { |
|
123
|
|
|
\Alert::success('Saved')->flash(); |
|
124
|
|
|
$status = true; |
|
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
} else { |
|
127
|
|
|
$message = trans('admin.language.fields_required'); |
|
|
|
|
|
|
128
|
|
|
\Alert::error('Please fill all fields')->flash(); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
return redirect()->back(); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.