1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Zikula package. |
7
|
|
|
* |
8
|
|
|
* Copyright Zikula - https://ziku.la/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Zikula\AdminModule\Controller; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
17
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
18
|
|
|
use Symfony\Component\HttpFoundation\Response; |
19
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
20
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
21
|
|
|
use Symfony\Component\Routing\Exception\RouteNotFoundException; |
22
|
|
|
use Symfony\Component\Routing\RouterInterface; |
23
|
|
|
use Zikula\AdminModule\Entity\AdminCategoryEntity; |
24
|
|
|
use Zikula\AdminModule\Entity\RepositoryInterface\AdminCategoryRepositoryInterface; |
25
|
|
|
use Zikula\AdminModule\Entity\RepositoryInterface\AdminModuleRepositoryInterface; |
26
|
|
|
use Zikula\AdminModule\Helper\UpdateCheckHelper; |
27
|
|
|
use Zikula\Bundle\CoreBundle\Controller\AbstractController; |
28
|
|
|
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface; |
29
|
|
|
use Zikula\ExtensionsModule\Api\ApiInterface\CapabilityApiInterface; |
30
|
|
|
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface; |
31
|
|
|
use Zikula\ExtensionsModule\Entity\RepositoryInterface\ExtensionRepositoryInterface; |
32
|
|
|
use Zikula\MenuModule\ExtensionMenu\ExtensionMenuCollector; |
33
|
|
|
use Zikula\MenuModule\ExtensionMenu\ExtensionMenuInterface; |
34
|
|
|
use Zikula\PermissionsModule\Annotation\PermissionCheck; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @Route("/admininterface") |
38
|
|
|
*/ |
39
|
|
|
class AdminInterfaceController extends AbstractController |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* @Route("/header") |
43
|
|
|
* |
44
|
|
|
* Open the admin container |
45
|
|
|
*/ |
46
|
|
|
public function header(RequestStack $requestStack): Response |
47
|
|
|
{ |
48
|
|
|
return $this->render('@ZikulaAdminModule/AdminInterface/header.html.twig', [ |
49
|
|
|
'caller' => $requestStack->getMasterRequest()->attributes->all() |
50
|
|
|
]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @Route("/footer") |
55
|
|
|
* |
56
|
|
|
* Close the admin container |
57
|
|
|
*/ |
58
|
|
|
public function footer( |
59
|
|
|
RequestStack $requestStack, |
60
|
|
|
ExtensionRepositoryInterface $extensionRepository |
61
|
|
|
): Response { |
62
|
|
|
$caller = $requestStack->getMasterRequest()->attributes->all(); |
63
|
|
|
$caller['info'] = !empty($caller['_zkModule']) ? $extensionRepository->get($caller['_zkModule']) : []; |
64
|
|
|
|
65
|
|
|
return $this->render('@ZikulaAdminModule/AdminInterface/footer.html.twig', [ |
66
|
|
|
'caller' => $caller, |
67
|
|
|
'symfonyVersion' => Kernel::VERSION, |
68
|
|
|
'phpVersion' => PHP_VERSION |
69
|
|
|
]); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @Route("/breadcrumbs", methods = {"GET"}) |
74
|
|
|
* @PermissionCheck("admin") |
75
|
|
|
* |
76
|
|
|
* Admin breadcrumbs |
77
|
|
|
*/ |
78
|
|
|
public function breadcrumbs( |
79
|
|
|
RequestStack $requestStack, |
80
|
|
|
ExtensionRepositoryInterface $extensionRepository, |
81
|
|
|
AdminModuleRepositoryInterface $adminModuleRepository, |
82
|
|
|
AdminCategoryRepositoryInterface $adminCategoryRepository |
83
|
|
|
): Response { |
84
|
|
|
$masterRequest = $requestStack->getMasterRequest(); |
85
|
|
|
$caller = $masterRequest->attributes->all(); |
86
|
|
|
$caller['info'] = !empty($caller['_zkModule']) ? $extensionRepository->get($caller['_zkModule']) : []; |
87
|
|
|
|
88
|
|
|
$requestedCid = $masterRequest->attributes->get('acid'); |
89
|
|
|
$defaultCid = empty($requestedCid) ? $this->getVar('startcategory') : $requestedCid; |
90
|
|
|
|
91
|
|
|
$categoryId = $defaultCid; |
92
|
|
|
if (!empty($caller['_zkModule']) && 'ZikulaAdminModule' !== $caller['_zkModule']) { |
93
|
|
|
$moduleRelation = $adminModuleRepository->findOneBy(['mid' => $caller['info']['id']]); |
94
|
|
|
if (null !== $moduleRelation) { |
95
|
|
|
$categoryId = $moduleRelation->getCid(); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
$caller['category'] = $adminCategoryRepository->find($categoryId); |
99
|
|
|
|
100
|
|
|
return $this->render('@ZikulaAdminModule/AdminInterface/breadCrumbs.html.twig', [ |
101
|
|
|
'caller' => $caller |
102
|
|
|
]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @Route("/securityanalyzer") |
107
|
|
|
* @PermissionCheck("admin") |
108
|
|
|
* |
109
|
|
|
* Display security analyzer |
110
|
|
|
*/ |
111
|
|
|
public function securityanalyzer( |
112
|
|
|
Request $request, |
113
|
|
|
ZikulaHttpKernelInterface $kernel, |
114
|
|
|
VariableApiInterface $variableApi |
115
|
|
|
): Response { |
116
|
|
|
$hasSecurityCenter = $kernel->isBundle('ZikulaSecurityCenterModule'); |
117
|
|
|
|
118
|
|
|
return $this->render('@ZikulaAdminModule/AdminInterface/securityAnalyzer.html.twig', [ |
119
|
|
|
'security' => [ |
120
|
|
|
'updatecheck' => $variableApi->getSystemVar('updatecheck'), |
121
|
|
|
'scactive' => $hasSecurityCenter, |
122
|
|
|
// check for outputfilter |
123
|
|
|
'useids' => $hasSecurityCenter && 1 === $variableApi->getSystemVar('useids'), |
124
|
|
|
'idssoftblock' => $variableApi->getSystemVar('idssoftblock') |
125
|
|
|
] |
126
|
|
|
]); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @Route("/updatecheck") |
131
|
|
|
* @PermissionCheck("admin") |
132
|
|
|
* |
133
|
|
|
* Display update check |
134
|
|
|
*/ |
135
|
|
|
public function updatecheck( |
136
|
|
|
RequestStack $requestStack, |
137
|
|
|
ZikulaHttpKernelInterface $kernel, |
138
|
|
|
UpdateCheckHelper $updateCheckHelper |
139
|
|
|
): Response { |
140
|
|
|
$masterRequest = $requestStack->getMasterRequest(); |
141
|
|
|
|
142
|
|
|
return $this->render('@ZikulaAdminModule/AdminInterface/updateCheck.html.twig', [ |
143
|
|
|
'mode' => $kernel->getEnvironment(), |
144
|
|
|
'caller' => [ |
145
|
|
|
'_route' => $masterRequest->attributes->get('_route'), |
146
|
|
|
'_route_params' => $masterRequest->attributes->get('_route_params') |
147
|
|
|
], |
148
|
|
|
'updateCheckHelper' => $updateCheckHelper |
149
|
|
|
]); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @Route("/menu") |
154
|
|
|
* @PermissionCheck("admin") |
155
|
|
|
* |
156
|
|
|
* Display admin menu |
157
|
|
|
*/ |
158
|
|
|
public function menu( |
159
|
|
|
RequestStack $requestStack, |
160
|
|
|
RouterInterface $router, |
161
|
|
|
ExtensionRepositoryInterface $extensionRepository, |
162
|
|
|
ExtensionMenuCollector $extensionMenuCollector, |
163
|
|
|
CapabilityApiInterface $capabilityApi, |
164
|
|
|
AdminModuleRepositoryInterface $adminModuleRepository, |
165
|
|
|
AdminCategoryRepositoryInterface $adminCategoryRepository |
166
|
|
|
): Response { |
167
|
|
|
$masterRequest = $requestStack->getMasterRequest(); |
168
|
|
|
$currentRequest = $requestStack->getCurrentRequest(); |
169
|
|
|
|
170
|
|
|
// get caller info |
171
|
|
|
$caller = []; |
172
|
|
|
$caller['_zkModule'] = $masterRequest->attributes->get('_zkModule'); |
173
|
|
|
$caller['_zkType'] = $masterRequest->attributes->get('_zkType'); |
174
|
|
|
$caller['_zkFunc'] = $masterRequest->attributes->get('_zkFunc'); |
175
|
|
|
$caller['path'] = $masterRequest->getPathInfo(); |
176
|
|
|
$caller['info'] = !empty($caller['_zkModule']) ? $extensionRepository->get($caller['_zkModule']) : []; |
177
|
|
|
|
178
|
|
|
// category we are in |
179
|
|
|
$requestedCid = $masterRequest->attributes->get('acid'); |
180
|
|
|
$defaultCid = empty($requestedCid) ? $this->getVar('startcategory') : $requestedCid; |
181
|
|
|
|
182
|
|
|
$categoryId = $defaultCid; |
183
|
|
|
if (!empty($caller['_zkModule']) && 'ZikulaAdminModule' !== $caller['_zkModule']) { |
184
|
|
|
$moduleRelation = $adminModuleRepository->findOneBy(['mid' => $caller['info']['id']]); |
185
|
|
|
if (null !== $moduleRelation) { |
186
|
|
|
$categoryId = $moduleRelation->getCid(); |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
$caller['category'] = $adminCategoryRepository->find($categoryId); |
190
|
|
|
|
191
|
|
|
// mode requested |
192
|
|
|
$mode = $currentRequest->attributes->has('mode') ? $currentRequest->attributes->get('mode') : 'categories'; |
193
|
|
|
$mode = in_array($mode, ['categories', 'modules']) ? $mode : 'categories'; |
194
|
|
|
// template requested |
195
|
|
|
$template = $currentRequest->attributes->has('template') ? $currentRequest->attributes->get('template') : 'tabs'; |
196
|
|
|
$template = in_array($template, ['tabs', 'panel']) ? $template : 'tabs'; |
197
|
|
|
|
198
|
|
|
// get admin capable modules |
199
|
|
|
$adminModules = $capabilityApi->getExtensionsCapableOf('admin'); |
200
|
|
|
|
201
|
|
|
// sort modules by displayname |
202
|
|
|
$moduleNames = []; |
203
|
|
|
foreach ($adminModules as $key => $module) { |
204
|
|
|
$moduleNames[$key] = $module['displayname']; |
205
|
|
|
} |
206
|
|
|
array_multisort($moduleNames, SORT_ASC, $adminModules); |
207
|
|
|
|
208
|
|
|
$moduleCategories = $adminCategoryRepository->getIndexedCollection('cid'); |
209
|
|
|
$menuModules = []; |
210
|
|
|
$menuCategories = []; |
211
|
|
|
foreach ($adminModules as $adminModule) { |
212
|
|
|
if (!$this->hasPermission($adminModule['name'] . '::', '::', ACCESS_EDIT)) { |
213
|
|
|
continue; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
$categoryAssignment = $adminModuleRepository->findOneBy(['mid' => $adminModule['id']]); |
217
|
|
|
if (null !== $categoryAssignment) { |
218
|
|
|
$catid = $categoryAssignment->getCid(); |
219
|
|
|
$order = $categoryAssignment->getSortorder(); |
220
|
|
|
} else { |
221
|
|
|
$catid = $this->getVar('startcategory'); |
222
|
|
|
$order = 999; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
$menuText = $adminModule['displayname']; |
226
|
|
|
|
227
|
|
|
// url |
228
|
|
|
try { |
229
|
|
|
$menuTextUrl = isset($adminModule['capabilities']['admin']['route']) |
230
|
|
|
? $router->generate($adminModule['capabilities']['admin']['route']) |
231
|
|
|
: ''; |
232
|
|
|
} catch (RouteNotFoundException $routeNotFoundException) { |
233
|
|
|
$menuTextUrl = 'javascript:void(0)'; |
234
|
|
|
$menuText .= ' (<i class="fas fa-exclamation-triangle"></i> ' . $this->trans('invalid route') . ')'; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
$moduleName = (string)$adminModule['name']; |
238
|
|
|
$extensionMenu = $extensionMenuCollector->get($moduleName, ExtensionMenuInterface::TYPE_ADMIN); |
239
|
|
|
if (isset($extensionMenu) && 'modules' === $mode && 'tabs' === $template) { |
240
|
|
|
$extensionMenu->setChildrenAttribute('class', 'dropdown-menu'); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
$module = [ |
244
|
|
|
'menutexturl' => $menuTextUrl, |
245
|
|
|
'menutext' => $menuText, |
246
|
|
|
'menutexttitle' => $adminModule['description'], |
247
|
|
|
'modname' => $adminModule['name'], |
248
|
|
|
'order' => $order, |
249
|
|
|
'id' => $adminModule['id'], |
250
|
|
|
'extensionMenu' => $extensionMenu, |
251
|
|
|
'icon' => $adminModule['icon'] |
252
|
|
|
]; |
253
|
|
|
|
254
|
|
|
$menuModules[$adminModule['name']] = $module; |
255
|
|
|
|
256
|
|
|
// category menu |
257
|
|
|
if (!$this->hasPermission('ZikulaAdminModule:Category:', $moduleCategories[$catid]['name'] . '::' . $moduleCategories[$catid]['cid'], ACCESS_ADMIN)) { |
258
|
|
|
continue; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
$categorySortOrder = $moduleCategories[$catid]['sortorder']; |
262
|
|
|
$menuCategories[$categorySortOrder]['title'] = $moduleCategories[$catid]['name']; |
263
|
|
|
$menuCategories[$categorySortOrder]['url'] = $router->generate('zikulaadminmodule_admin_adminpanel', [ |
264
|
|
|
'acid' => $moduleCategories[$catid]['cid'] |
265
|
|
|
]); |
266
|
|
|
$menuCategories[$categorySortOrder]['description'] = $moduleCategories[$catid]['description']; |
267
|
|
|
$menuCategories[$categorySortOrder]['icon'] = $moduleCategories[$catid]['icon']; |
268
|
|
|
$menuCategories[$categorySortOrder]['cid'] = $moduleCategories[$catid]['cid']; |
269
|
|
|
$menuCategories[$categorySortOrder]['modules'][$adminModule['name']] = $module; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
// add empty categories |
273
|
|
|
/** @var AdminCategoryEntity[] $moduleCategories */ |
274
|
|
|
foreach ($moduleCategories as $moduleCategory) { |
275
|
|
|
if (array_key_exists($moduleCategory->getSortorder(), $menuCategories)) { |
276
|
|
|
continue; |
277
|
|
|
} |
278
|
|
|
if (!$this->hasPermission('ZikulaAdminModule:Category:', $moduleCategory->getName() . '::' . $moduleCategory->getCid(), ACCESS_ADMIN)) { |
279
|
|
|
continue; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
$menuCategories[$moduleCategory->getSortOrder()] = [ |
283
|
|
|
'title' => $moduleCategory->getName(), |
284
|
|
|
'url' => $router->generate('zikulaadminmodule_admin_adminpanel', [ |
285
|
|
|
'acid' => $moduleCategory->getCid() |
286
|
|
|
]), |
287
|
|
|
'description' => $moduleCategory->getDescription(), |
288
|
|
|
'cid' => $moduleCategory->getCid(), |
289
|
|
|
'modules' => [] |
290
|
|
|
]; |
291
|
|
|
} |
292
|
|
|
ksort($menuCategories); |
293
|
|
|
$fullTemplateName = $mode . '.' . $template; |
294
|
|
|
|
295
|
|
|
return $this->render("@ZikulaAdminModule/AdminInterface/${fullTemplateName}.html.twig", [ |
296
|
|
|
'adminMenu' => ('categories' === $mode) ? $menuCategories : $menuModules, |
297
|
|
|
'mode' => $mode, |
298
|
|
|
'caller' => $caller |
299
|
|
|
]); |
300
|
|
|
} |
301
|
|
|
} |
302
|
|
|
|