|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Flextype\Plugin\Admin\Controllers; |
|
6
|
|
|
|
|
7
|
|
|
use Flextype\Component\Arrays\Arrays; |
|
8
|
|
|
use Flextype\Component\Filesystem\Filesystem; |
|
9
|
|
|
use Psr\Http\Message\ResponseInterface as Response; |
|
|
|
|
|
|
10
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request; |
|
|
|
|
|
|
11
|
|
|
use function array_merge; |
|
12
|
|
|
use function array_replace_recursive; |
|
13
|
|
|
use function Flextype\Component\I18n\__; |
|
|
|
|
|
|
14
|
|
|
use function trim; |
|
15
|
|
|
|
|
16
|
|
|
class PluginsController |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Index page |
|
20
|
|
|
* |
|
21
|
|
|
* @param Request $request PSR7 request |
|
22
|
|
|
* @param Response $response PSR7 response |
|
23
|
|
|
*/ |
|
24
|
|
|
public function index(/** @scrutinizer ignore-unused */ Request $request, Response $response) : Response |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
$plugins_list = flextype('registry')->get('plugins'); |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
ksort($plugins_list); |
|
30
|
|
|
|
|
31
|
|
|
return flextype('twig')->render( |
|
32
|
|
|
$response, |
|
33
|
|
|
'plugins/admin/templates/extends/plugins/index.html', |
|
34
|
|
|
[ |
|
35
|
|
|
'plugins_list' => $plugins_list, |
|
36
|
|
|
'menu_item' => 'plugins', |
|
37
|
|
|
'links' => [ |
|
38
|
|
|
'plugins' => [ |
|
39
|
|
|
'link' => flextype('router')->pathFor('admin.plugins.index'), |
|
40
|
|
|
'title' => __('admin_plugins'), |
|
|
|
|
|
|
41
|
|
|
'active' => true |
|
42
|
|
|
], |
|
43
|
|
|
], |
|
44
|
|
|
'buttons' => [ |
|
45
|
|
|
'plugins_get_more' => [ |
|
46
|
|
|
'link' => 'https://flextype.org/en/downloads/extend/plugins', |
|
47
|
|
|
'title' => __('admin_get_more_plugins'), |
|
48
|
|
|
'target' => '_blank' |
|
49
|
|
|
], |
|
50
|
|
|
], |
|
51
|
|
|
] |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Сhange plugin status process |
|
57
|
|
|
* |
|
58
|
|
|
* @param Request $request PSR7 request |
|
59
|
|
|
* @param Response $response PSR7 response |
|
60
|
|
|
*/ |
|
61
|
|
|
public function pluginStatusProcess(Request $request, Response $response) : Response |
|
62
|
|
|
{ |
|
63
|
|
|
// Get data from the request |
|
64
|
|
|
$post_data = $request->getParsedBody(); |
|
65
|
|
|
|
|
66
|
|
|
$custom_plugin_settings_file = PATH['project'] . '/config/plugins/' . $post_data['plugin-key'] . '/settings.yaml'; |
|
|
|
|
|
|
67
|
|
|
$custom_plugin_settings_file_content = Filesystem::read($custom_plugin_settings_file); |
|
68
|
|
|
$custom_plugin_settings_file_data = empty($custom_plugin_settings_file_content) ? [] : flextype('serializers')->yaml()->decode($custom_plugin_settings_file_content); |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
$status = ($post_data['plugin-set-status'] == 'true') ? true : false; |
|
71
|
|
|
|
|
72
|
|
|
Arrays::set($custom_plugin_settings_file_data, 'enabled', $status); |
|
73
|
|
|
|
|
74
|
|
|
Filesystem::write($custom_plugin_settings_file, flextype('serializers')->yaml()->encode($custom_plugin_settings_file_data)); |
|
75
|
|
|
|
|
76
|
|
|
// clear cache |
|
77
|
|
|
Filesystem::deleteDir(PATH['tmp'] . '/data'); |
|
78
|
|
|
|
|
79
|
|
|
// Redirect to plugins index page |
|
80
|
|
|
return $response->withRedirect(flextype('router')->pathFor('admin.plugins.index')); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Plugin information |
|
85
|
|
|
* |
|
86
|
|
|
* @param Request $request PSR7 request |
|
87
|
|
|
* @param Response $response PSR7 response |
|
88
|
|
|
*/ |
|
89
|
|
|
public function information(Request $request, Response $response) : Response |
|
90
|
|
|
{ |
|
91
|
|
|
// Get Plugin ID |
|
92
|
|
|
$id = $request->getQueryParams()['id']; |
|
93
|
|
|
|
|
94
|
|
|
// Set plugin custom manifest content |
|
95
|
|
|
$custom_plugin_manifest_file = PATH['project'] . '/plugins/' . '/' . $id . '/plugin.yaml'; |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
// Get plugin custom manifest content |
|
98
|
|
|
$custom_plugin_manifest_file_content = Filesystem::read($custom_plugin_manifest_file); |
|
99
|
|
|
|
|
100
|
|
|
return flextype('twig')->render( |
|
|
|
|
|
|
101
|
|
|
$response, |
|
102
|
|
|
'plugins/admin/templates/extends/plugins/information.html', |
|
103
|
|
|
[ |
|
104
|
|
|
'menu_item' => 'plugins', |
|
105
|
|
|
'id' => $id, |
|
106
|
|
|
'plugin_manifest' => flextype('serializers')->yaml()->decode($custom_plugin_manifest_file_content), |
|
107
|
|
|
'links' => [ |
|
108
|
|
|
'plugins' => [ |
|
109
|
|
|
'link' => flextype('router')->pathFor('admin.plugins.index'), |
|
110
|
|
|
'title' => __('admin_plugins'), |
|
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
], |
|
113
|
|
|
'plugins_information' => [ |
|
114
|
|
|
'link' => flextype('router')->pathFor('admin.plugins.information') . '?id=' . $request->getQueryParams()['id'], |
|
115
|
|
|
'title' => __('admin_information'), |
|
116
|
|
|
'active' => true |
|
117
|
|
|
], |
|
118
|
|
|
], |
|
119
|
|
|
] |
|
120
|
|
|
); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Plugin settings |
|
125
|
|
|
* |
|
126
|
|
|
* @param Request $request PSR7 request |
|
127
|
|
|
* @param Response $response PSR7 response |
|
128
|
|
|
*/ |
|
129
|
|
|
public function settings(Request $request, Response $response) : Response |
|
130
|
|
|
{ |
|
131
|
|
|
// Get Plugin ID |
|
132
|
|
|
$id = $request->getQueryParams()['id']; |
|
133
|
|
|
|
|
134
|
|
|
// Set plugin custom setting file |
|
135
|
|
|
$custom_plugin_settings_file = PATH['project'] . '/config/' . '/plugins/' . $id . '/settings.yaml'; |
|
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
// Get plugin custom setting file content |
|
138
|
|
|
$custom_plugin_settings_file_content = Filesystem::read($custom_plugin_settings_file); |
|
139
|
|
|
|
|
140
|
|
|
return flextype('twig')->render( |
|
|
|
|
|
|
141
|
|
|
$response, |
|
142
|
|
|
'plugins/admin/templates/extends/plugins/settings.html', |
|
143
|
|
|
[ |
|
144
|
|
|
'menu_item' => 'plugins', |
|
145
|
|
|
'id' => $id, |
|
146
|
|
|
'plugin_settings' => $custom_plugin_settings_file_content, |
|
147
|
|
|
'links' => [ |
|
148
|
|
|
'plugins' => [ |
|
149
|
|
|
'link' => flextype('router')->pathFor('admin.plugins.index'), |
|
150
|
|
|
'title' => __('admin_plugins'), |
|
|
|
|
|
|
151
|
|
|
], |
|
152
|
|
|
'plugins_settings' => [ |
|
153
|
|
|
'link' => flextype('router')->pathFor('admin.plugins.settings') . '?id=' . $request->getQueryParams()['id'], |
|
154
|
|
|
'title' => __('admin_settings'), |
|
155
|
|
|
'active' => true |
|
156
|
|
|
], |
|
157
|
|
|
], |
|
158
|
|
|
'buttons' => [ |
|
159
|
|
|
'save_plugin_settings' => [ |
|
160
|
|
|
'link' => 'javascript:;', |
|
161
|
|
|
'title' => __('admin_save'), |
|
162
|
|
|
'type' => 'action' |
|
163
|
|
|
], |
|
164
|
|
|
], |
|
165
|
|
|
] |
|
166
|
|
|
); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Plugin settings process |
|
171
|
|
|
* |
|
172
|
|
|
* @param Request $request PSR7 request |
|
173
|
|
|
* @param Response $response PSR7 response |
|
174
|
|
|
*/ |
|
175
|
|
|
public function settingsProcess(Request $request, Response $response) : Response |
|
176
|
|
|
{ |
|
177
|
|
|
$post_data = $request->getParsedBody(); |
|
178
|
|
|
|
|
179
|
|
|
$id = $post_data['id']; |
|
180
|
|
|
$data = $post_data['data']; |
|
181
|
|
|
|
|
182
|
|
|
$custom_plugin_settings_dir = PATH['project'] . '/config/' . '/plugins/' . $id; |
|
|
|
|
|
|
183
|
|
|
$custom_plugin_settings_file = PATH['project'] . '/config/' . '/plugins/' . $id . '/settings.yaml'; |
|
184
|
|
|
|
|
185
|
|
|
if (Filesystem::write($custom_plugin_settings_file, $data)) { |
|
186
|
|
|
flextype('flash')->addMessage('success', __('admin_message_plugin_settings_saved')); |
|
|
|
|
|
|
187
|
|
|
} else { |
|
188
|
|
|
flextype('flash')->addMessage('error', __('admin_message_plugin_settings_not_saved')); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
return $response->withRedirect(flextype('router')->pathFor('admin.plugins.settings') . '?id=' . $id); |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths