1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2023 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Shop\Controller; |
10
|
|
|
|
11
|
|
|
use Illuminate\Support\Facades\View; |
12
|
|
|
use Illuminate\Support\Facades\Route; |
13
|
|
|
use Illuminate\Support\Facades\Request; |
14
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Aimeos controller for the JQuery admin interface |
19
|
|
|
*/ |
20
|
|
|
class JqadmController extends AdminController |
21
|
|
|
{ |
22
|
|
|
use AuthorizesRequests; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Returns the JS file content |
27
|
|
|
* |
28
|
|
|
* @return \Illuminate\Http\Response Response object containing the generated output |
29
|
|
|
*/ |
30
|
|
|
public function fileAction() |
31
|
|
|
{ |
32
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
33
|
|
|
$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$files = []; |
37
|
|
|
$aimeos = app( 'aimeos' )->get(); |
|
|
|
|
38
|
|
|
$name = Route::input( 'name', Request::get( 'name' ) ); |
39
|
|
|
|
40
|
|
|
foreach( $aimeos->getCustomPaths( 'admin/jqadm' ) as $base => $paths ) |
41
|
|
|
{ |
42
|
|
|
foreach( $paths as $path ) { |
43
|
|
|
$files[] = $base . '/' . $path; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$response = response( \Aimeos\Admin\JQAdm\Bundle::get( $files, $name ) ); |
48
|
|
|
|
49
|
|
|
if( str_ends_with( $name, 'js' ) ) { |
50
|
|
|
$response->header( 'Content-Type', 'application/javascript' ); |
51
|
|
|
} elseif( str_ends_with( $name, 'css' ) ) { |
52
|
|
|
$response->header( 'Content-Type', 'text/css' ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $response->header( 'Cache-Control', 'public, max-age=3600' ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns the HTML code for batch operations on a resource object |
61
|
|
|
* |
62
|
|
|
* @return string Generated output |
63
|
|
|
*/ |
64
|
|
|
public function batchAction() |
65
|
|
|
{ |
66
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
67
|
|
|
$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$cntl = $this->createAdmin(); |
71
|
|
|
|
72
|
|
|
if( ( $html = $cntl->batch() ) == '' ) { |
73
|
|
|
return $cntl->response(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $this->getHtml( (string) $html ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Returns the HTML code for a copy of a resource object |
82
|
|
|
* |
83
|
|
|
* @return string Generated output |
84
|
|
|
*/ |
85
|
|
|
public function copyAction() |
86
|
|
|
{ |
87
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
88
|
|
|
$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$cntl = $this->createAdmin(); |
92
|
|
|
|
93
|
|
|
if( ( $html = $cntl->copy() ) == '' ) { |
94
|
|
|
return $cntl->response(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $this->getHtml( (string) $html ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Returns the HTML code for a new resource object |
103
|
|
|
* |
104
|
|
|
* @return string Generated output |
105
|
|
|
*/ |
106
|
|
|
public function createAction() |
107
|
|
|
{ |
108
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
109
|
|
|
$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$cntl = $this->createAdmin(); |
113
|
|
|
|
114
|
|
|
if( ( $html = $cntl->create() ) == '' ) { |
115
|
|
|
return $cntl->response(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return $this->getHtml( (string) $html ); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Deletes the resource object or a list of resource objects |
124
|
|
|
* |
125
|
|
|
* @return string Generated output |
126
|
|
|
*/ |
127
|
|
|
public function deleteAction() |
128
|
|
|
{ |
129
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
130
|
|
|
$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$cntl = $this->createAdmin(); |
134
|
|
|
|
135
|
|
|
if( ( $html = $cntl->delete() ) == '' ) { |
136
|
|
|
return $cntl->response(); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
return $this->getHtml( (string) $html ); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Exports the data for a resource object |
145
|
|
|
* |
146
|
|
|
* @return string Generated output |
147
|
|
|
*/ |
148
|
|
|
public function exportAction() |
149
|
|
|
{ |
150
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
151
|
|
|
$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
$cntl = $this->createAdmin(); |
155
|
|
|
|
156
|
|
|
if( ( $html = $cntl->export() ) == '' ) { |
157
|
|
|
return $cntl->response(); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
return $this->getHtml( (string) $html ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Returns the HTML code for the requested resource object |
166
|
|
|
* |
167
|
|
|
* @return string Generated output |
168
|
|
|
*/ |
169
|
|
|
public function getAction() |
170
|
|
|
{ |
171
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
172
|
|
|
$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
$cntl = $this->createAdmin(); |
176
|
|
|
|
177
|
|
|
if( ( $html = $cntl->get() ) == '' ) { |
178
|
|
|
return $cntl->response(); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
return $this->getHtml( (string) $html ); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Imports the data for a resource object |
187
|
|
|
* |
188
|
|
|
* @return string Generated output |
189
|
|
|
*/ |
190
|
|
|
public function importAction() |
191
|
|
|
{ |
192
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
193
|
|
|
$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
$cntl = $this->createAdmin(); |
197
|
|
|
|
198
|
|
|
if( ( $html = $cntl->import() ) == '' ) { |
199
|
|
|
return $cntl->response(); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
return $this->getHtml( (string) $html ); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Saves a new resource object |
208
|
|
|
* |
209
|
|
|
* @return string Generated output |
210
|
|
|
*/ |
211
|
|
|
public function saveAction() |
212
|
|
|
{ |
213
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
214
|
|
|
$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
$cntl = $this->createAdmin(); |
218
|
|
|
|
219
|
|
|
if( ( $html = $cntl->save() ) == '' ) { |
220
|
|
|
return $cntl->response(); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
return $this->getHtml( (string) $html ); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Returns the HTML code for a list of resource objects |
229
|
|
|
* |
230
|
|
|
* @return string Generated output |
231
|
|
|
*/ |
232
|
|
|
public function searchAction() |
233
|
|
|
{ |
234
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
235
|
|
|
$this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
$cntl = $this->createAdmin(); |
239
|
|
|
|
240
|
|
|
if( ( $html = $cntl->search() ) == '' ) { |
241
|
|
|
return $cntl->response(); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
return $this->getHtml( (string) $html ); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Returns the resource controller |
250
|
|
|
* |
251
|
|
|
* @return \Aimeos\Admin\JQAdm\Iface JQAdm client |
252
|
|
|
*/ |
253
|
|
|
protected function createAdmin() : \Aimeos\Admin\JQAdm\Iface |
254
|
|
|
{ |
255
|
|
|
$site = Route::input( 'site', Request::get( 'site', config( 'shop.mshop.locale.site', 'default' ) ) ); |
|
|
|
|
256
|
|
|
$lang = Request::get( 'locale', config( 'app.locale', 'en' ) ); |
257
|
|
|
$resource = Route::input( 'resource' ); |
258
|
|
|
|
259
|
|
|
$aimeos = app( 'aimeos' )->get(); |
|
|
|
|
260
|
|
|
|
261
|
|
|
$context = app( 'aimeos.context' )->get( false, 'backend' ); |
|
|
|
|
262
|
|
|
$context->setI18n( app( 'aimeos.i18n' )->get( array( $lang, 'en' ) ) ); |
|
|
|
|
263
|
|
|
$context->setLocale( app( 'aimeos.locale' )->getBackend( $context, $site )->setLanguageId( $lang ) ); |
264
|
|
|
|
265
|
|
|
$siteManager = \Aimeos\MShop::create( $context, 'locale/site' ); |
266
|
|
|
$context->config()->apply( $siteManager->find( $site )->getConfig() ); |
|
|
|
|
267
|
|
|
|
268
|
|
|
$paths = $aimeos->getTemplatePaths( 'admin/jqadm/templates', $context->locale()->getSiteItem()->getTheme() ); |
269
|
|
|
$view = app( 'aimeos.view' )->create( $context, $paths, $lang ); |
270
|
|
|
|
271
|
|
|
$view->aimeosType = 'Laravel'; |
272
|
|
|
$view->aimeosVersion = app( 'aimeos' )->getVersion(); |
273
|
|
|
$view->aimeosExtensions = implode( ',', $aimeos->getExtensions() ); |
274
|
|
|
|
275
|
|
|
$context->setView( $view ); |
276
|
|
|
|
277
|
|
|
return \Aimeos\Admin\JQAdm::create( $context, $aimeos, $resource ); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Returns the generated HTML code |
283
|
|
|
* |
284
|
|
|
* @param string $content Content from admin client |
285
|
|
|
* @return \Illuminate\Contracts\View\View View for rendering the output |
286
|
|
|
*/ |
287
|
|
|
protected function getHtml( string $content ) |
288
|
|
|
{ |
289
|
|
|
$site = Route::input( 'site', Request::get( 'site', config( 'shop.mshop.locale.site', 'default' ) ) ); |
|
|
|
|
290
|
|
|
$lang = Request::get( 'locale', config( 'app.locale', 'en' ) ); |
291
|
|
|
|
292
|
|
|
return View::make( 'shop::jqadm.index', [ |
293
|
|
|
'content' => $content, |
294
|
|
|
'site' => $site, |
295
|
|
|
'locale' => $lang, |
296
|
|
|
'localeDir' => in_array( $lang, ['ar', 'az', 'dv', 'fa', 'he', 'ku', 'ur'] ) ? 'rtl' : 'ltr', |
297
|
|
|
'theme' => ( $_COOKIE['aimeos_backend_theme'] ?? '' ) == 'dark' ? 'dark' : 'light' |
298
|
|
|
] ); |
299
|
|
|
} |
300
|
|
|
} |
301
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.