[TASK] Use BE Routing / PSR-7 instead of BackendUtility::getModuleUrl
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / Controller / ElementBrowserFramesetController.php
1 <?php
2 namespace TYPO3\CMS\Recordlist\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Template\DocumentTemplate;
20 use TYPO3\CMS\Core\Localization\LanguageService;
21 use TYPO3\CMS\Core\Page\PageRenderer;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24 /**
25 * Script Class, putting the frameset together.
26 */
27 class ElementBrowserFramesetController
28 {
29 /**
30 * Internal, dynamic
31 *
32 * @var string
33 */
34 public $content;
35
36 /**
37 * @var PageRenderer
38 */
39 protected $pageRenderer = null;
40
41 /**
42 * Constructor
43 */
44 public function __construct()
45 {
46 $GLOBALS['SOBE'] = $this;
47 }
48
49 /**
50 * Injects the request object for the current request or subrequest
51 * As this controller goes only through the main() method, it is rather simple for now
52 *
53 * @param ServerRequestInterface $request the current request
54 * @param ResponseInterface $response the prepared response
55 * @return ResponseInterface the response with the content
56 */
57 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
58 {
59 $this->main();
60
61 $response->getBody()->write($this->content);
62 return $response;
63 }
64
65 /**
66 * Main function.
67 * Creates the header code in XHTML, the JavaScript, then the frameset for the two frames.
68 */
69 public function main()
70 {
71 // Setting GPvars:
72 $mode = GeneralUtility::_GP('mode');
73 $bparams = GeneralUtility::_GP('bparams');
74 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
75 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
76 $moduleUrl = (string)$uriBuilder->buildUriFromRoute('wizard_element_browser') . '&mode=';
77 $documentTemplate = $this->getDocumentTemplate();
78 $documentTemplate->JScode = GeneralUtility::wrapJS('
79 function closing() { //
80 close();
81 }
82 function setParams(mode,params) { //
83 parent.content.location.href = ' . GeneralUtility::quoteJSvalue($moduleUrl) . '+mode+"&bparams="+params;
84 }
85 if (!window.opener) {
86 alert("ERROR: Sorry, no link to main window... Closing");
87 close();
88 }
89 ');
90
91 // build the header part
92 $documentTemplate->startPage($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:TYPO3_Element_Browser'));
93
94 // URL for the inner main frame:
95 $url = $moduleUrl . rawurlencode($mode) . '&bparams=' . rawurlencode($bparams);
96
97 // Create the frameset for the window
98 // Formerly there were a ' onunload="closing();"' in the <frameset> tag - but it failed on Safari browser on Mac unless the handler was "onUnload"
99 $this->content = $this->getPageRenderer()->render(PageRenderer::PART_HEADER) .
100 '<frameset rows="*,1" framespacing="0" frameborder="0" border="0">
101 <frame name="content" src="' . htmlspecialchars($url) . '" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto" noresize="noresize" />
102 <frame name="menu" src="' . htmlspecialchars((string)$uriBuilder->buildUriFromRoute('dummy')) . '" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />
103 </frameset>
104 </html>
105 ';
106 }
107
108 /**
109 * @return DocumentTemplate
110 */
111 protected function getDocumentTemplate()
112 {
113 return $GLOBALS['TBE_TEMPLATE'];
114 }
115
116 /**
117 * @return LanguageService
118 */
119 protected function getLanguageService()
120 {
121 return $GLOBALS['LANG'];
122 }
123
124 /**
125 * @return PageRenderer
126 */
127 protected function getPageRenderer()
128 {
129 if ($this->pageRenderer === null) {
130 $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
131 }
132
133 return $this->pageRenderer;
134 }
135 }