1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace TYPO3\CMS\Adminpanel\Middleware; |
5
|
|
|
|
6
|
|
|
/* |
7
|
|
|
* This file is part of the TYPO3 CMS project. |
8
|
|
|
* |
9
|
|
|
* It is free software; you can redistribute it and/or modify it under |
10
|
|
|
* the terms of the GNU General Public License, either version 2 |
11
|
|
|
* of the License, or any later version. |
12
|
|
|
* |
13
|
|
|
* For the full copyright and license information, please read the |
14
|
|
|
* LICENSE.txt file that was distributed with this source code. |
15
|
|
|
* |
16
|
|
|
* The TYPO3 project - inspiring people to share! |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
use Psr\Http\Message\ResponseInterface; |
20
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
21
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
22
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
23
|
|
|
use TYPO3\CMS\Adminpanel\Controller\MainController; |
24
|
|
|
use TYPO3\CMS\Adminpanel\Utility\StateUtility; |
25
|
|
|
use TYPO3\CMS\Adminpanel\View\AdminPanelView; |
26
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* PSR-15 Middleware to initialize the admin panel |
30
|
|
|
* |
31
|
|
|
* @internal |
32
|
|
|
*/ |
33
|
|
|
class AdminPanelInitiator implements MiddlewareInterface |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* Initialize the adminPanel if |
37
|
|
|
* - backend user is logged in |
38
|
|
|
* - at least one adminpanel functionality is enabled |
39
|
|
|
* - admin panel is open |
40
|
|
|
* |
41
|
|
|
* @param ServerRequestInterface $request |
42
|
|
|
* @param RequestHandlerInterface $handler |
43
|
|
|
* @return ResponseInterface |
44
|
|
|
*/ |
45
|
|
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
46
|
|
|
{ |
47
|
|
|
if (StateUtility::isActivatedForUser() && StateUtility::isOpen()) { |
48
|
|
|
$request = $request->withAttribute('adminPanelRequestId', substr(md5(uniqid('', true)), 0, 13)); |
49
|
|
|
$adminPanelController = GeneralUtility::makeInstance( |
50
|
|
|
MainController::class |
51
|
|
|
); |
52
|
|
|
$adminPanelController->initialize($request); |
53
|
|
|
// legacy handling |
54
|
|
|
$beUser = $GLOBALS['BE_USER']; |
55
|
|
|
$beUser->adminPanel = GeneralUtility::makeInstance(AdminPanelView::class); |
56
|
|
|
$beUser->extAdmEnabled = true; |
57
|
|
|
} |
58
|
|
|
return $handler->handle($request); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|