[!!!][TASK] Remove deprecated code from backend controllers
[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\Backend\ClickMenu\ClickMenu;
20 use TYPO3\CMS\Backend\Clipboard\Clipboard;
21 use TYPO3\CMS\Backend\Template\DocumentTemplate;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
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 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
39 */
40 public $doc;
41
42 /**
43 * Internal array of classes for extending the clickmenu
44 *
45 * @var array
46 */
47 public $extClassArray = array();
48
49 /**
50 * Constructor
51 */
52 public function __construct()
53 {
54 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_misc.xlf');
55 $GLOBALS['SOBE'] = $this;
56
57 // Setting GPvars:
58 $this->reloadListFrame = GeneralUtility::_GP('reloadListFrame');
59 // Setting pseudo module name
60 $this->MCONF['name'] = 'xMOD_alt_clickmenu.php';
61
62 // Setting internal array of classes for extending the clickmenu:
63 $this->extClassArray = $GLOBALS['TBE_MODULES_EXT']['xMOD_alt_clickmenu']['extendCMclasses'];
64
65 // Initialize template object
66 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
67 }
68
69 /**
70 * this is an intermediate clickmenu handler
71 *
72 * @param ServerRequestInterface $request
73 * @param ResponseInterface $response
74 * @return ResponseInterface
75 */
76 public function getContextMenuAction(ServerRequestInterface $request, ResponseInterface $response)
77 {
78
79 // XML has to be parsed, no parse errors allowed
80 @ini_set('display_errors', 0);
81
82 $clipObj = GeneralUtility::makeInstance(Clipboard::class);
83 $clipObj->initializeClipboard();
84 // This locks the clipboard to the Normal for this request.
85 $clipObj->lockToNormal();
86 // Update clipboard if some actions are sent.
87 $CB = GeneralUtility::_GET('CB');
88 $clipObj->setCmd($CB);
89 $clipObj->cleanCurrent();
90 // Saves
91 $clipObj->endClipboard();
92 // Create clickmenu object
93 $clickMenu = GeneralUtility::makeInstance(ClickMenu::class);
94 // Set internal vars in clickmenu object:
95 $clickMenu->clipObj = $clipObj;
96 $clickMenu->extClassArray = $this->extClassArray;
97
98 // Set content of the clickmenu with the incoming var, "item"
99 $ajaxContent = $clickMenu->init();
100
101 // send the data
102 $ajaxContent = '<?xml version="1.0"?><t3ajax>' . $ajaxContent . '</t3ajax>';
103 $response->getBody()->write($ajaxContent);
104 $response = $response->withHeader('Content-Type', 'text/xml; charset=utf-8');
105 return $response;
106 }
107
108 /**
109 * Returns LanguageService
110 *
111 * @return \TYPO3\CMS\Lang\LanguageService
112 */
113 protected function getLanguageService()
114 {
115 return $GLOBALS['LANG'];
116 }
117 }