[TASK] Create own response instance in controller actions
[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\Http\HtmlResponse;
21 use TYPO3\CMS\Core\Localization\LanguageService;
22 use TYPO3\CMS\Core\Page\PageRenderer;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24
25 /**
26 * Script Class, putting the frameset together.
27 */
28 class ElementBrowserFramesetController
29 {
30 /**
31 * Internal, dynamic
32 *
33 * @var string
34 */
35 public $content;
36
37 /**
38 * @var PageRenderer
39 */
40 protected $pageRenderer = null;
41
42 /**
43 * Constructor
44 */
45 public function __construct()
46 {
47 $GLOBALS['SOBE'] = $this;
48 }
49
50 /**
51 * Injects the request object for the current request or subrequest
52 * As this controller goes only through the main() method, it is rather simple for now
53 *
54 * @param ServerRequestInterface $request the current request
55 * @return ResponseInterface the response with the content
56 */
57 public function mainAction(ServerRequestInterface $request): ResponseInterface
58 {
59 $this->main();
60 return new HtmlResponse($this->content);
61 }
62
63 /**
64 * Main function.
65 * Creates the header code in XHTML, the JavaScript, then the frameset for the two frames.
66 */
67 public function main()
68 {
69 // Setting GPvars:
70 $mode = GeneralUtility::_GP('mode');
71 $bparams = GeneralUtility::_GP('bparams');
72 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
73 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
74 $moduleUrl = (string)$uriBuilder->buildUriFromRoute('wizard_element_browser') . '&mode=';
75 $documentTemplate = $this->getDocumentTemplate();
76 $documentTemplate->JScode = GeneralUtility::wrapJS('
77 function closing() { //
78 close();
79 }
80 function setParams(mode,params) { //
81 parent.content.location.href = ' . GeneralUtility::quoteJSvalue($moduleUrl) . '+mode+"&bparams="+params;
82 }
83 if (!window.opener) {
84 alert("ERROR: Sorry, no link to main window... Closing");
85 close();
86 }
87 ');
88
89 // build the header part
90 $documentTemplate->startPage($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:TYPO3_Element_Browser'));
91
92 // URL for the inner main frame:
93 $url = $moduleUrl . rawurlencode($mode) . '&bparams=' . rawurlencode($bparams);
94
95 // Create the frameset for the window
96 // Formerly there were a ' onunload="closing();"' in the <frameset> tag - but it failed on Safari browser on Mac unless the handler was "onUnload"
97 $this->content = $this->getPageRenderer()->render(PageRenderer::PART_HEADER) .
98 '<frameset rows="*,1" framespacing="0" frameborder="0" border="0">
99 <frame name="content" src="' . htmlspecialchars($url) . '" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto" noresize="noresize" />
100 <frame name="menu" src="' . htmlspecialchars((string)$uriBuilder->buildUriFromRoute('dummy')) . '" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />
101 </frameset>
102 </html>
103 ';
104 }
105
106 /**
107 * @return DocumentTemplate
108 */
109 protected function getDocumentTemplate()
110 {
111 return $GLOBALS['TBE_TEMPLATE'];
112 }
113
114 /**
115 * @return LanguageService
116 */
117 protected function getLanguageService()
118 {
119 return $GLOBALS['LANG'];
120 }
121
122 /**
123 * @return PageRenderer
124 */
125 protected function getPageRenderer()
126 {
127 if ($this->pageRenderer === null) {
128 $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
129 }
130
131 return $this->pageRenderer;
132 }
133 }