[!!!][FEATURE] Introduce PSR-7-based Routing for Backend AJAX Requests
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / ClickMenuController.php
1 <?php
2 namespace TYPO3\CMS\Backend\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\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Backend\Template\DocumentTemplate;
21 use TYPO3\CMS\Backend\Clipboard\Clipboard;
22 use TYPO3\CMS\Backend\ClickMenu\ClickMenu;
23
24 /**
25 * Script Class for the Context Sensitive Menu in TYPO3 (rendered in top frame, normally writing content dynamically to list frames).
26 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate::getContextMenuCode()
27 */
28 class ClickMenuController {
29
30 /**
31 * Defines the name of the document object for which to reload the URL.
32 *
33 * @var int
34 */
35 public $reloadListFrame;
36
37 /**
38 * Content accumulation
39 *
40 * @var string
41 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
42 */
43 public $content = '';
44
45 /**
46 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
47 */
48 public $doc;
49
50 /**
51 * Internal array of classes for extending the clickmenu
52 *
53 * @var array
54 */
55 public $extClassArray = array();
56
57 /**
58 * Constructor
59 */
60 public function __construct() {
61 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_misc.xlf');
62 $GLOBALS['SOBE'] = $this;
63
64 // Setting GPvars:
65 $this->reloadListFrame = GeneralUtility::_GP('reloadListFrame');
66 // Setting pseudo module name
67 $this->MCONF['name'] = 'xMOD_alt_clickmenu.php';
68
69 // Setting internal array of classes for extending the clickmenu:
70 $this->extClassArray = $GLOBALS['TBE_MODULES_EXT']['xMOD_alt_clickmenu']['extendCMclasses'];
71
72 // Initialize template object
73 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
74 }
75
76 /**
77 * Constructor function for script class.
78 *
79 * @return void
80 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, all done in the constructor now
81 */
82 protected function init() {
83 GeneralUtility::logDeprecatedFunction();
84 }
85
86 /**
87 * Main function - generating the click menu in whatever form it has.
88 *
89 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, as ajax.php is now the main entry point
90 * @return void
91 */
92 public function main() {
93 GeneralUtility::logDeprecatedFunction();
94 // Initialize Clipboard object:
95 $clipObj = GeneralUtility::makeInstance(Clipboard::class);
96 $clipObj->initializeClipboard();
97 // This locks the clipboard to the Normal for this request.
98 $clipObj->lockToNormal();
99 // Update clipboard if some actions are sent.
100 $CB = GeneralUtility::_GET('CB');
101 $clipObj->setCmd($CB);
102 $clipObj->cleanCurrent();
103 // Saves
104 $clipObj->endClipboard();
105 // Create clickmenu object
106 $clickMenu = GeneralUtility::makeInstance(ClickMenu::class);
107 // Set internal vars in clickmenu object:
108 $clickMenu->clipObj = $clipObj;
109 $clickMenu->extClassArray = $this->extClassArray;
110 // Set content of the clickmenu with the incoming var, "item"
111 $this->content .= $clickMenu->init();
112 }
113
114 /**
115 * End page and output content.
116 *
117 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, as ajax.php is now the main entry point
118 * @return void
119 */
120 public function printContent() {
121 GeneralUtility::logDeprecatedFunction();
122 header('Content-Type: text/xml');
123 echo '<?xml version="1.0"?>' . LF . '<t3ajax>' . $this->content . '</t3ajax>';
124 }
125
126 /**
127 * this is an intermediate clickmenu handler
128 *
129 * @param ServerRequestInterface $request
130 * @param ResponseInterface $response
131 * @return ResponseInterface
132 */
133 public function getContextMenuAction(ServerRequestInterface $request, ResponseInterface $response) {
134
135 // XML has to be parsed, no parse errors allowed
136 @ini_set('display_errors', 0);
137
138 $clipObj = GeneralUtility::makeInstance(Clipboard::class);
139 $clipObj->initializeClipboard();
140 // This locks the clipboard to the Normal for this request.
141 $clipObj->lockToNormal();
142 // Update clipboard if some actions are sent.
143 $CB = GeneralUtility::_GET('CB');
144 $clipObj->setCmd($CB);
145 $clipObj->cleanCurrent();
146 // Saves
147 $clipObj->endClipboard();
148 // Create clickmenu object
149 $clickMenu = GeneralUtility::makeInstance(ClickMenu::class);
150 // Set internal vars in clickmenu object:
151 $clickMenu->clipObj = $clipObj;
152 $clickMenu->extClassArray = $this->extClassArray;
153
154 // Set content of the clickmenu with the incoming var, "item"
155 $ajaxContent = $clickMenu->init();
156
157 // send the data
158 $ajaxContent = '<?xml version="1.0"?><t3ajax>' . $ajaxContent . '</t3ajax>';
159 $response->getBody()->write($ajaxContent);
160 $response = $response->withHeader('Content-Type', 'text/xml; charset=utf-8');
161 return $response;
162 }
163
164 /**
165 * Returns LanguageService
166 *
167 * @return \TYPO3\CMS\Lang\LanguageService
168 */
169 protected function getLanguageService() {
170 return $GLOBALS['LANG'];
171 }
172
173 }