|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
|
6
|
|
|
* @package laravel |
|
7
|
|
|
* @subpackage Controller |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Shop\Controller; |
|
12
|
|
|
|
|
13
|
|
|
use Illuminate\Support\Facades\View; |
|
14
|
|
|
use Illuminate\Support\Facades\Route; |
|
15
|
|
|
use Illuminate\Support\Facades\Input; |
|
16
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Aimeos controller for the JQuery admin interface |
|
21
|
|
|
* |
|
22
|
|
|
* @package laravel |
|
23
|
|
|
* @subpackage Controller |
|
24
|
|
|
*/ |
|
25
|
|
|
class JqadmController extends AdminController |
|
26
|
|
|
{ |
|
27
|
|
|
use AuthorizesRequests; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Returns the JS file content |
|
32
|
|
|
* |
|
33
|
|
|
* @return \Illuminate\Http\Response Response object containing the generated output |
|
34
|
|
|
*/ |
|
35
|
|
|
public function fileAction() |
|
36
|
|
|
{ |
|
37
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
38
|
|
|
$this->authorize( 'admin', [['admin', 'editor']] ); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$contents = ''; |
|
42
|
|
|
$files = array(); |
|
43
|
|
|
$aimeos = app( '\Aimeos\Shop\Base\Aimeos' )->get(); |
|
44
|
|
|
$type = Route::input( 'type', Input::get( 'type', 'js' ) ); |
|
45
|
|
|
|
|
46
|
|
View Code Duplication |
foreach( $aimeos->getCustomPaths( 'admin/jqadm' ) as $base => $paths ) |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
|
|
foreach( $paths as $path ) |
|
49
|
|
|
{ |
|
50
|
|
|
$jsbAbsPath = $base . '/' . $path; |
|
51
|
|
|
$jsb2 = new \Aimeos\MW\Jsb2\Standard( $jsbAbsPath, dirname( $jsbAbsPath ) ); |
|
52
|
|
|
$files = array_merge( $files, $jsb2->getFiles( $type ) ); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
foreach( $files as $file ) |
|
57
|
|
|
{ |
|
58
|
|
|
if( ( $content = file_get_contents( $file ) ) !== false ) { |
|
59
|
|
|
$contents .= $content; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$response = response( $contents ); |
|
64
|
|
|
|
|
65
|
|
|
if( $type === 'js' ) { |
|
66
|
|
|
$response->header( 'Content-Type', 'application/javascript' ); |
|
|
|
|
|
|
67
|
|
|
} elseif( $type === 'css' ) { |
|
68
|
|
|
$response->header( 'Content-Type', 'text/css' ); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $response; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Returns the HTML code for a copy of a resource object |
|
77
|
|
|
* |
|
78
|
|
|
* @return string Generated output |
|
79
|
|
|
*/ |
|
80
|
|
View Code Duplication |
public function copyAction() |
|
|
|
|
|
|
81
|
|
|
{ |
|
82
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
83
|
|
|
$this->authorize( 'admin', [['admin', 'editor']] ); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$cntl = $this->createClient(); |
|
87
|
|
|
return $this->getHtml( $cntl->copy() ); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Returns the HTML code for a new resource object |
|
93
|
|
|
* |
|
94
|
|
|
* @return string Generated output |
|
95
|
|
|
*/ |
|
96
|
|
View Code Duplication |
public function createAction() |
|
|
|
|
|
|
97
|
|
|
{ |
|
98
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
99
|
|
|
$this->authorize( 'admin', [['admin', 'editor']] ); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
$cntl = $this->createClient(); |
|
103
|
|
|
return $this->getHtml( $cntl->create() ); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Deletes the resource object or a list of resource objects |
|
109
|
|
|
* |
|
110
|
|
|
* @return string Generated output |
|
111
|
|
|
*/ |
|
112
|
|
View Code Duplication |
public function deleteAction() |
|
|
|
|
|
|
113
|
|
|
{ |
|
114
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
115
|
|
|
$this->authorize( 'admin', [['admin', 'editor']] ); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
$cntl = $this->createClient(); |
|
119
|
|
|
return $this->getHtml( $cntl->delete() . $cntl->search() ); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Returns the HTML code for the requested resource object |
|
125
|
|
|
* |
|
126
|
|
|
* @return string Generated output |
|
127
|
|
|
*/ |
|
128
|
|
View Code Duplication |
public function getAction() |
|
|
|
|
|
|
129
|
|
|
{ |
|
130
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
131
|
|
|
$this->authorize( 'admin', [['admin', 'editor']] ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
$cntl = $this->createClient(); |
|
135
|
|
|
return $this->getHtml( $cntl->get() ); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Saves a new resource object |
|
141
|
|
|
* |
|
142
|
|
|
* @return string Generated output |
|
143
|
|
|
*/ |
|
144
|
|
View Code Duplication |
public function saveAction() |
|
|
|
|
|
|
145
|
|
|
{ |
|
146
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
147
|
|
|
$this->authorize( 'admin', [['admin', 'editor']] ); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
$cntl = $this->createClient(); |
|
151
|
|
|
return $this->getHtml( ( $cntl->save() ? : $cntl->search() ) ); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Returns the HTML code for a list of resource objects |
|
157
|
|
|
* |
|
158
|
|
|
* @return string Generated output |
|
159
|
|
|
*/ |
|
160
|
|
View Code Duplication |
public function searchAction() |
|
|
|
|
|
|
161
|
|
|
{ |
|
162
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
163
|
|
|
$this->authorize( 'admin', [['admin', 'editor']] ); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
$cntl = $this->createClient(); |
|
167
|
|
|
return $this->getHtml( $cntl->search() ); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Returns the resource controller |
|
173
|
|
|
* |
|
174
|
|
|
* @return \Aimeos\Admin\JQAdm\Iface JQAdm client |
|
175
|
|
|
*/ |
|
176
|
|
View Code Duplication |
protected function createClient() |
|
|
|
|
|
|
177
|
|
|
{ |
|
178
|
|
|
$site = Route::input( 'site', Input::get( 'site', 'default' ) ); |
|
179
|
|
|
$lang = Input::get( 'lang', config( 'app.locale', 'en' ) ); |
|
180
|
|
|
$resource = Route::input( 'resource' ); |
|
181
|
|
|
|
|
182
|
|
|
$aimeos = app( '\Aimeos\Shop\Base\Aimeos' )->get(); |
|
183
|
|
|
$templatePaths = $aimeos->getCustomPaths( 'admin/jqadm/templates' ); |
|
184
|
|
|
|
|
185
|
|
|
$context = app( '\Aimeos\Shop\Base\Context' )->get( false, 'backend' ); |
|
186
|
|
|
$context->setI18n( app('\Aimeos\Shop\Base\I18n')->get( array( $lang, 'en' ) ) ); |
|
187
|
|
|
$context->setLocale( app('\Aimeos\Shop\Base\Locale')->getBackend( $context, $site ) ); |
|
188
|
|
|
$context->setView( app( '\Aimeos\Shop\Base\View' )->create( $context->getConfig(), $templatePaths, $lang ) ); |
|
189
|
|
|
|
|
190
|
|
|
return \Aimeos\Admin\JQAdm\Factory::createClient( $context, $templatePaths, $resource ); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* Returns the generated HTML code |
|
196
|
|
|
* |
|
197
|
|
|
* @param string $content Content from admin client |
|
198
|
|
|
* @return \Illuminate\Contracts\View\View View for rendering the output |
|
199
|
|
|
*/ |
|
200
|
|
|
protected function getHtml( $content ) |
|
201
|
|
|
{ |
|
202
|
|
|
$version = app( '\Aimeos\Shop\Base\Aimeos' )->getVersion(); |
|
203
|
|
|
$site = Route::input( 'site', Input::get( 'site', 'default' ) ); |
|
204
|
|
|
$content = str_replace( ['{type}', '{version}'], ['Laravel', $version], $content ); |
|
205
|
|
|
|
|
206
|
|
|
return View::make( 'shop::jqadm.index', array( 'content' => $content, 'site' => $site ) ); |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.