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 | $contents = ''; |
||
37 | $files = array(); |
||
38 | $aimeos = app( 'aimeos' )->get(); |
||
39 | $name = Route::input( 'name', Request::get( 'name' ) ); |
||
40 | |||
41 | foreach( $aimeos->getCustomPaths( 'admin/jqadm' ) as $base => $paths ) |
||
42 | { |
||
43 | foreach( $paths as $path ) |
||
44 | { |
||
45 | $jsbAbsPath = $base . '/' . $path; |
||
46 | $jsb2 = new \Aimeos\MW\Jsb2\Standard( $jsbAbsPath, dirname( $jsbAbsPath ) ); |
||
47 | $files = array_merge( $files, $jsb2->getFiles( $name ) ); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | foreach( $files as $file ) |
||
52 | { |
||
53 | if( ( $content = file_get_contents( $file ) ) !== false ) { |
||
54 | $contents .= $content; |
||
55 | } |
||
56 | } |
||
57 | |||
58 | $response = response( $contents ); |
||
59 | |||
60 | if( str_ends_with( $name, 'js' ) ) { |
||
61 | $response->header( 'Content-Type', 'application/javascript' ); |
||
62 | } elseif( str_ends_with( $name, 'css' ) ) { |
||
63 | $response->header( 'Content-Type', 'text/css' ); |
||
64 | } |
||
65 | |||
66 | return $response->header( 'Cache-Control', 'public, max-age=3600' ); |
||
67 | } |
||
68 | |||
69 | |||
70 | /** |
||
71 | * Returns the HTML code for batch operations on a resource object |
||
72 | * |
||
73 | * @return string Generated output |
||
74 | */ |
||
75 | public function batchAction() |
||
76 | { |
||
77 | if( config( 'shop.authorize', true ) ) { |
||
78 | $this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
||
79 | } |
||
80 | |||
81 | $cntl = $this->createAdmin(); |
||
82 | |||
83 | if( ( $html = $cntl->batch() ) == '' ) { |
||
84 | return $cntl->response(); |
||
85 | } |
||
86 | |||
87 | return $this->getHtml( (string) $html ); |
||
88 | } |
||
89 | |||
90 | |||
91 | /** |
||
92 | * Returns the HTML code for a copy of a resource object |
||
93 | * |
||
94 | * @return string Generated output |
||
95 | */ |
||
96 | public function copyAction() |
||
97 | { |
||
98 | if( config( 'shop.authorize', true ) ) { |
||
99 | $this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
||
100 | } |
||
101 | |||
102 | $cntl = $this->createAdmin(); |
||
103 | |||
104 | if( ( $html = $cntl->copy() ) == '' ) { |
||
105 | return $cntl->response(); |
||
106 | } |
||
107 | |||
108 | return $this->getHtml( (string) $html ); |
||
109 | } |
||
110 | |||
111 | |||
112 | /** |
||
113 | * Returns the HTML code for a new resource object |
||
114 | * |
||
115 | * @return string Generated output |
||
116 | */ |
||
117 | public function createAction() |
||
118 | { |
||
119 | if( config( 'shop.authorize', true ) ) { |
||
120 | $this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
||
121 | } |
||
122 | |||
123 | $cntl = $this->createAdmin(); |
||
124 | |||
125 | if( ( $html = $cntl->create() ) == '' ) { |
||
126 | return $cntl->response(); |
||
127 | } |
||
128 | |||
129 | return $this->getHtml( (string) $html ); |
||
130 | } |
||
131 | |||
132 | |||
133 | /** |
||
134 | * Deletes the resource object or a list of resource objects |
||
135 | * |
||
136 | * @return string Generated output |
||
137 | */ |
||
138 | public function deleteAction() |
||
139 | { |
||
140 | if( config( 'shop.authorize', true ) ) { |
||
141 | $this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
||
142 | } |
||
143 | |||
144 | $cntl = $this->createAdmin(); |
||
145 | |||
146 | if( ( $html = $cntl->delete() ) == '' ) { |
||
147 | return $cntl->response(); |
||
148 | } |
||
149 | |||
150 | return $this->getHtml( (string) $html ); |
||
151 | } |
||
152 | |||
153 | |||
154 | /** |
||
155 | * Exports the data for a resource object |
||
156 | * |
||
157 | * @return string Generated output |
||
158 | */ |
||
159 | public function exportAction() |
||
160 | { |
||
161 | if( config( 'shop.authorize', true ) ) { |
||
162 | $this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
||
163 | } |
||
164 | |||
165 | $cntl = $this->createAdmin(); |
||
166 | |||
167 | if( ( $html = $cntl->export() ) == '' ) { |
||
168 | return $cntl->response(); |
||
169 | } |
||
170 | |||
171 | return $this->getHtml( (string) $html ); |
||
172 | } |
||
173 | |||
174 | |||
175 | /** |
||
176 | * Returns the HTML code for the requested resource object |
||
177 | * |
||
178 | * @return string Generated output |
||
179 | */ |
||
180 | public function getAction() |
||
181 | { |
||
182 | if( config( 'shop.authorize', true ) ) { |
||
183 | $this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
||
184 | } |
||
185 | |||
186 | $cntl = $this->createAdmin(); |
||
187 | |||
188 | if( ( $html = $cntl->get() ) == '' ) { |
||
189 | return $cntl->response(); |
||
190 | } |
||
191 | |||
192 | return $this->getHtml( (string) $html ); |
||
193 | } |
||
194 | |||
195 | |||
196 | /** |
||
197 | * Imports the data for a resource object |
||
198 | * |
||
199 | * @return string Generated output |
||
200 | */ |
||
201 | public function importAction() |
||
202 | { |
||
203 | if( config( 'shop.authorize', true ) ) { |
||
204 | $this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
||
205 | } |
||
206 | |||
207 | $cntl = $this->createAdmin(); |
||
208 | |||
209 | if( ( $html = $cntl->import() ) == '' ) { |
||
210 | return $cntl->response(); |
||
211 | } |
||
212 | |||
213 | return $this->getHtml( (string) $html ); |
||
214 | } |
||
215 | |||
216 | |||
217 | /** |
||
218 | * Saves a new resource object |
||
219 | * |
||
220 | * @return string Generated output |
||
221 | */ |
||
222 | public function saveAction() |
||
223 | { |
||
224 | if( config( 'shop.authorize', true ) ) { |
||
225 | $this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
||
226 | } |
||
227 | |||
228 | $cntl = $this->createAdmin(); |
||
229 | |||
230 | if( ( $html = $cntl->save() ) == '' ) { |
||
231 | return $cntl->response(); |
||
232 | } |
||
233 | |||
234 | return $this->getHtml( (string) $html ); |
||
235 | } |
||
236 | |||
237 | |||
238 | /** |
||
239 | * Returns the HTML code for a list of resource objects |
||
240 | * |
||
241 | * @return string Generated output |
||
242 | */ |
||
243 | public function searchAction() |
||
244 | { |
||
245 | if( config( 'shop.authorize', true ) ) { |
||
246 | $this->authorize( 'admin', [JqadmController::class, config( 'shop.roles', ['admin', 'editor'] )] ); |
||
247 | } |
||
248 | |||
249 | $cntl = $this->createAdmin(); |
||
250 | |||
251 | if( ( $html = $cntl->search() ) == '' ) { |
||
252 | return $cntl->response(); |
||
253 | } |
||
254 | |||
255 | return $this->getHtml( (string) $html ); |
||
256 | } |
||
257 | |||
258 | |||
259 | /** |
||
260 | * Returns the resource controller |
||
261 | * |
||
262 | * @return \Aimeos\Admin\JQAdm\Iface JQAdm client |
||
263 | */ |
||
264 | protected function createAdmin() : \Aimeos\Admin\JQAdm\Iface |
||
265 | { |
||
266 | $site = Route::input( 'site', Request::get( 'site', config( 'shop.mshop.locale.site', 'default' ) ) ); |
||
267 | $lang = Request::get( 'locale', config( 'app.locale', 'en' ) ); |
||
268 | $resource = Route::input( 'resource' ); |
||
269 | |||
270 | $aimeos = app( 'aimeos' )->get(); |
||
271 | |||
272 | $context = app( 'aimeos.context' )->get( false, 'backend' ); |
||
273 | $context->setI18n( app( 'aimeos.i18n' )->get( array( $lang, 'en' ) ) ); |
||
274 | $context->setLocale( app( 'aimeos.locale' )->getBackend( $context, $site ) ); |
||
275 | |||
276 | $siteManager = \Aimeos\MShop::create( $context, 'locale/site'); |
||
277 | $context->config()->apply( $siteManager->find( $site )->getConfig() ); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
278 | |||
279 | $paths = $aimeos->getTemplatePaths( 'admin/jqadm/templates', $context->locale()->getSiteItem()->getTheme() ); |
||
280 | $view = app( 'aimeos.view' )->create( $context, $paths, $lang ); |
||
281 | |||
282 | $view->aimeosType = 'Laravel'; |
||
283 | $view->aimeosVersion = app( 'aimeos' )->getVersion(); |
||
284 | $view->aimeosExtensions = implode( ',', $aimeos->getExtensions() ); |
||
285 | |||
286 | $context->setView( $view ); |
||
287 | |||
288 | return \Aimeos\Admin\JQAdm::create( $context, $aimeos, $resource ); |
||
289 | } |
||
290 | |||
291 | |||
292 | /** |
||
293 | * Returns the generated HTML code |
||
294 | * |
||
295 | * @param string $content Content from admin client |
||
296 | * @return \Illuminate\Contracts\View\View View for rendering the output |
||
297 | */ |
||
298 | protected function getHtml( string $content ) |
||
299 | { |
||
300 | $site = Route::input( 'site', Request::get( 'site', config( 'shop.mshop.locale.site', 'default' ) ) ); |
||
301 | $lang = Request::get( 'locale', config( 'app.locale', 'en' ) ); |
||
302 | |||
303 | return View::make( 'shop::jqadm.index', [ |
||
304 | 'content' => $content, |
||
305 | 'site' => $site, |
||
306 | 'locale' => $lang, |
||
307 | 'localeDir' => in_array( $lang, ['ar', 'az', 'dv', 'fa', 'he', 'ku', 'ur'] ) ? 'rtl' : 'ltr', |
||
308 | 'theme' => ( $_COOKIE['aimeos_backend_theme'] ?? '' ) == 'dark' ? 'dark' : 'light' |
||
309 | ] ); |
||
310 | } |
||
311 | } |
||
312 |