[TASK] Activate email validation for pages.author_email
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / FileSystemNavigationFrameController.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\Routing\UriBuilder;
20 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
21 use TYPO3\CMS\Backend\Template\ModuleTemplate;
22 use TYPO3\CMS\Backend\Tree\View\ElementBrowserFolderTreeView;
23 use TYPO3\CMS\Core\Http\HtmlResponse;
24 use TYPO3\CMS\Core\Http\JsonResponse;
25 use TYPO3\CMS\Core\Imaging\Icon;
26 use TYPO3\CMS\Core\Imaging\IconFactory;
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28 use TYPO3\CMS\Filelist\FileListFolderTree;
29 use TYPO3\CMS\Recordlist\Tree\View\DummyLinkParameterProvider;
30
31 /**
32 * Main script class for rendering of the folder tree
33 */
34 class FileSystemNavigationFrameController
35 {
36 /**
37 * Content accumulates in this variable.
38 *
39 * @var string
40 */
41 public $content;
42
43 /**
44 * @var \TYPO3\CMS\Backend\Tree\View\FolderTreeView
45 */
46 public $foldertree;
47
48 /**
49 * @var string
50 */
51 public $currentSubScript;
52
53 /**
54 * @var bool
55 */
56 public $cMR;
57
58 /**
59 * @var array
60 */
61 protected $scopeData;
62
63 /**
64 * ModuleTemplate Container
65 *
66 * @var ModuleTemplate
67 */
68 protected $moduleTemplate;
69
70 /**
71 * Constructor
72 */
73 public function __construct()
74 {
75 $GLOBALS['SOBE'] = $this;
76 $this->init();
77 }
78
79 /**
80 * @param ServerRequestInterface $request the current request
81 * @return ResponseInterface the response with the content
82 */
83 public function mainAction(ServerRequestInterface $request): ResponseInterface
84 {
85 $this->initPage();
86 $this->main();
87 return new HtmlResponse($this->content);
88 }
89
90 /**
91 * Initialiation of the script class
92 */
93 protected function init()
94 {
95 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
96
97 // Setting GPvars:
98 $this->currentSubScript = GeneralUtility::_GP('currentSubScript');
99 $this->cMR = GeneralUtility::_GP('cMR');
100
101 $scopeData = (string)GeneralUtility::_GP('scopeData');
102 $scopeHash = (string)GeneralUtility::_GP('scopeHash');
103
104 if (!empty($scopeData) && hash_equals(GeneralUtility::hmac($scopeData), $scopeHash)) {
105 $this->scopeData = unserialize($scopeData);
106 }
107
108 // Create folder tree object:
109 if (!empty($this->scopeData)) {
110 $this->foldertree = GeneralUtility::makeInstance($this->scopeData['class']);
111 $this->foldertree->thisScript = $this->scopeData['script'];
112 if ($this->foldertree instanceof ElementBrowserFolderTreeView) {
113 // create a fake provider to pass link data along properly
114 $linkParamProvider = GeneralUtility::makeInstance(
115 DummyLinkParameterProvider::class,
116 $this->scopeData['browser'],
117 $this->scopeData['script']
118 );
119 $this->foldertree->setLinkParameterProvider($linkParamProvider);
120 }
121 } else {
122 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
123 $this->foldertree = GeneralUtility::makeInstance(FileListFolderTree::class);
124 $this->foldertree->thisScript = (string)$uriBuilder->buildUriFromRoute('file_navframe');
125 }
126 }
127
128 /**
129 * initialization for the visual parts of the class
130 * Use template rendering only if this is a non-AJAX call
131 */
132 public function initPage()
133 {
134 $this->moduleTemplate->setBodyTag('<body id="ext-backend-Modules-FileSystemNavigationFrame-index-php">');
135
136 // Adding javascript code for drag&drop and the file tree as well as the click menu code
137 $hlClass = $this->getBackendUser()->workspace === 0 ? 'active' : 'active active-ws wsver' . $GLOBALS['BE_USER']->workspace;
138 $dragDropCode = '
139 Tree.highlightClass = "' . $hlClass . '";
140 Tree.highlightActiveItem("", top.fsMod.navFrameHighlightedID["file"]);
141 ';
142
143 // Adding javascript for drag & drop activation and highlighting
144 $pageRenderer = $this->moduleTemplate->getPageRenderer();
145 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
146 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LegacyTree', 'function() {
147 DragDrop.table = "folders";
148 Tree.registerDragDropHandlers();
149 ' . $dragDropCode . '
150 }');
151
152 // Setting JavaScript for menu.
153 $inlineJs = ($this->currentSubScript ? 'top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript) . '");' : '') . '
154 // Function, loading the list frame from navigation tree:
155 function jumpTo(id, linkObj, highlightID, bank) {
156 var theUrl = top.currentSubScript;
157 if (theUrl.indexOf("?") != -1) {
158 theUrl += "&id=" + id
159 } else {
160 theUrl += "?id=" + id
161 }
162 top.fsMod.currentBank = bank;
163 top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
164
165 Tree.highlightActiveItem("file", highlightID + "_" + bank);
166 if (linkObj) { linkObj.blur(); }
167 return false;
168 }
169 ' . ($this->cMR ? ' jumpTo(top.fsMod.recentIds[\'file\'],\'\');' : '');
170
171 $this->moduleTemplate->getPageRenderer()->addJsInlineCode(
172 'FileSystemNavigationFrame',
173 $inlineJs
174 );
175 }
176
177 /**
178 * Main function, rendering the folder tree
179 */
180 public function main()
181 {
182 // Produce browse-tree:
183 $tree = $this->foldertree->getBrowsableTree();
184 // Outputting page tree:
185 $this->moduleTemplate->setContent($tree);
186 // Setting up the buttons
187 $this->getButtons();
188 // Build the <body> for the module
189 $this->moduleTemplate->setTitle('TYPO3 Folder Tree');
190 $this->content = $this->moduleTemplate->renderContent();
191 }
192
193 /**
194 * Register docHeader buttons
195 */
196 protected function getButtons()
197 {
198 /** @var ButtonBar $buttonBar */
199 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
200
201 /** @var IconFactory $iconFactory */
202 $iconFactory = $this->moduleTemplate->getIconFactory();
203
204 // Refresh
205 $refreshButton = $buttonBar->makeLinkButton()
206 ->setHref(GeneralUtility::getIndpEnv('REQUEST_URI'))
207 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.reload'))
208 ->setIcon($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
209 $buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT);
210
211 // CSH
212 $cshButton = $buttonBar->makeHelpButton()
213 ->setModuleName('xMOD_csh_corebe')
214 ->setFieldName('filetree');
215 $buttonBar->addButton($cshButton);
216 }
217
218 /**********************************
219 * AJAX Calls
220 **********************************/
221 /**
222 * Makes the AJAX call to expand or collapse the foldertree.
223 * Called by an AJAX Route, see AjaxRequestHandler
224 *
225 * @param ServerRequestInterface $request
226 * @return ResponseInterface
227 */
228 public function ajaxExpandCollapse(ServerRequestInterface $request): ResponseInterface
229 {
230 $this->init();
231 $tree = $this->foldertree->getBrowsableTree();
232 if ($this->foldertree->getAjaxStatus() === false) {
233 return new JsonResponse(null, 500);
234 }
235 return new JsonResponse([$tree]);
236 }
237
238 /**
239 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
240 */
241 protected function getBackendUser()
242 {
243 return $GLOBALS['BE_USER'];
244 }
245
246 /**
247 * Returns an instance of LanguageService
248 *
249 * @return \TYPO3\CMS\Core\Localization\LanguageService
250 */
251 protected function getLanguageService()
252 {
253 return $GLOBALS['LANG'];
254 }
255 }