[TASK] Call explicit render() on icon objects
[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\Tree\View\ElementBrowserFolderTreeView;
20 use TYPO3\CMS\Core\Imaging\Icon;
21 use TYPO3\CMS\Core\Imaging\IconFactory;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23 use TYPO3\CMS\Filelist\FileListFolderTree;
24 use TYPO3\CMS\Backend\Template\DocumentTemplate;
25 use TYPO3\CMS\Backend\Utility\BackendUtility;
26 use TYPO3\CMS\Recordlist\Browser\ElementBrowser;
27
28 /**
29 * Main script class for rendering of the folder tree
30 */
31 class FileSystemNavigationFrameController {
32
33 /**
34 * Content accumulates in this variable.
35 *
36 * @var string
37 */
38 public $content;
39
40 /**
41 * @var \TYPO3\CMS\Backend\Tree\View\FolderTreeView
42 */
43 public $foldertree;
44
45 /**
46 * document template object
47 *
48 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
49 */
50 public $doc;
51
52 /**
53 * @var string
54 */
55 public $currentSubScript;
56
57 /**
58 * @var bool
59 */
60 public $cMR;
61
62 /**
63 * @var array
64 */
65 protected $scopeData;
66
67 /**
68 * @var bool
69 */
70 public $doHighlight;
71
72 /**
73 * Constructor
74 */
75 public function __construct() {
76 $GLOBALS['SOBE'] = $this;
77 $this->init();
78 }
79
80 /**
81 * @param ServerRequestInterface $request the current request
82 * @param ResponseInterface $response
83 * @return ResponseInterface the response with the content
84 */
85 public function mainAction(ServerRequestInterface $request, ResponseInterface $response) {
86 $this->initPage();
87 $this->main();
88
89 $response->getBody()->write($this->content);
90 return $response;
91 }
92
93 /**
94 * Initialiation of the script class
95 *
96 * @return void
97 */
98 protected function init() {
99 // Setting GPvars:
100 $this->currentSubScript = GeneralUtility::_GP('currentSubScript');
101 $this->cMR = GeneralUtility::_GP('cMR');
102
103 $scopeData = (string)GeneralUtility::_GP('scopeData');
104 $scopeHash = (string)GeneralUtility::_GP('scopeHash');
105
106 if (!empty($scopeData) && GeneralUtility::hmac($scopeData) === $scopeHash) {
107 $this->scopeData = unserialize($scopeData);
108 }
109
110 // Create folder tree object:
111 if (!empty($this->scopeData)) {
112 $this->foldertree = GeneralUtility::makeInstance($this->scopeData['class']);
113 $this->foldertree->thisScript = $this->scopeData['script'];
114 $this->foldertree->ext_noTempRecyclerDirs = $this->scopeData['ext_noTempRecyclerDirs'];
115 if ($this->foldertree instanceof ElementBrowserFolderTreeView) {
116 $browser = GeneralUtility::makeInstance(ElementBrowser::class);
117 $browser->mode = $this->scopeData['browser']['mode'];
118 $browser->act = $this->scopeData['browser']['act'];
119 $this->foldertree->setElementBrowser($browser);
120 }
121 } else {
122 $this->foldertree = GeneralUtility::makeInstance(FileListFolderTree::class);
123 $this->foldertree->thisScript = BackendUtility::getModuleUrl('file_navframe');
124 }
125 // Only set ext_IconMode if we are not running an ajax request from the ElementBrowser,
126 // which has this property hardcoded to 1.
127 if (!$this->foldertree instanceof ElementBrowserFolderTreeView) {
128 $this->foldertree->ext_IconMode = $this->getBackendUser()->getTSConfigVal('options.folderTree.disableIconLinkToContextmenu');
129 }
130 }
131
132 /**
133 * initialization for the visual parts of the class
134 * Use template rendering only if this is a non-AJAX call
135 *
136 * @return void
137 */
138 public function initPage() {
139 // Setting highlight mode:
140 $this->doHighlight = !$this->getBackendUser()->getTSConfigVal('options.pageTree.disableTitleHighlight');
141 // Create template object:
142 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
143 $this->doc->bodyTagId = 'ext-backend-Modules-FileSystemNavigationFrame-index-php';
144 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/alt_file_navframe.html');
145 $this->doc->showFlashMessages = FALSE;
146 // Adding javascript code for drag&drop and the filetree as well as the click menu code
147 $dragDropCode = '
148 Tree.ajaxID = "sc_alt_file_navframe_expandtoggle";
149 Tree.registerDragDropHandlers()';
150 if ($this->doHighlight) {
151 $hlClass = $this->getBackendUser()->workspace === 0 ? 'active' : 'active active-ws wsver' . $GLOBALS['BE_USER']->workspace;
152 $dragDropCode .= '
153 Tree.highlightClass = "' . $hlClass . '";
154 Tree.highlightActiveItem("", top.fsMod.navFrameHighlightedID["file"]);
155 ';
156 }
157 // Adding javascript for drag & drop activation and highlighting
158 $this->doc->getDragDropCode('folders', $dragDropCode);
159 $this->doc->getContextMenuCode();
160
161 // Setting JavaScript for menu.
162 $this->doc->JScode .= $this->doc->wrapScriptTags(($this->currentSubScript ? 'top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript) . '");' : '') . '
163 // Function, loading the list frame from navigation tree:
164 function jumpTo(id, linkObj, highlightID, bank) {
165 var theUrl = top.currentSubScript;
166 if (theUrl.indexOf("?") != -1) {
167 theUrl += "&id=" + id
168 } else {
169 theUrl += "?id=" + id
170 }
171 top.fsMod.currentBank = bank;
172 top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
173
174 ' . ($this->doHighlight ? 'Tree.highlightActiveItem("file", highlightID + "_" + bank);' : '') . '
175 if (linkObj) { linkObj.blur(); }
176 return false;
177 }
178 ' . ($this->cMR ? ' jumpTo(top.fsMod.recentIds[\'file\'],\'\');' : ''));
179 }
180
181 /**
182 * Main function, rendering the folder tree
183 *
184 * @return void
185 */
186 public function main() {
187 // Produce browse-tree:
188 $tree = $this->foldertree->getBrowsableTree();
189 // Outputting page tree:
190 $this->content .= $tree;
191 // Setting up the buttons and markers for docheader
192 $docHeaderButtons = $this->getButtons();
193 $markers = array(
194 'CONTENT' => $this->content
195 );
196 $subparts = array();
197 // Build the <body> for the module
198 $this->content = $this->doc->startPage('TYPO3 Folder Tree');
199 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markers, $subparts);
200 $this->content .= $this->doc->endPage();
201 $this->content = $this->doc->insertStylesAndJS($this->content);
202 }
203
204 /**
205 * Outputting the accumulated content to screen
206 *
207 * @return void
208 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
209 */
210 public function printContent() {
211 GeneralUtility::logDeprecatedFunction();
212 echo $this->content;
213 }
214
215 /**
216 * Create the panel of buttons for submitting the form or otherwise perform operations.
217 *
218 * @return array All available buttons as an assoc. array
219 */
220 protected function getButtons() {
221 $buttons = array(
222 'csh' => '',
223 'refresh' => ''
224 );
225 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
226 // Refresh
227 $buttons['refresh'] = '<a href="' . htmlspecialchars(GeneralUtility::getIndpEnv('REQUEST_URI')) . '">' . $iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render() . '</a>';
228 // CSH
229 $buttons['csh'] = str_replace('typo3-csh-inline', 'typo3-csh-inline show-right', BackendUtility::cshItem('xMOD_csh_corebe', 'filetree'));
230 return $buttons;
231 }
232
233 /**********************************
234 *
235 * AJAX Calls
236 *
237 **********************************/
238 /**
239 * Makes the AJAX call to expand or collapse the foldertree.
240 * Called by typo3/ajax.php
241 *
242 * @param ServerRequestInterface $request
243 * @param ResponseInterface $response
244 * @return ResponseInterface
245 */
246 public function ajaxExpandCollapse(ServerRequestInterface $request, ResponseInterface $response) {
247 $this->init();
248 $tree = $this->foldertree->getBrowsableTree();
249 if ($this->foldertree->getAjaxStatus() === FALSE) {
250 $response->withStatus(500);
251 } else {
252 $response->getBody()->write(json_encode($tree));
253 }
254
255 return $response;
256 }
257
258 /**
259 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
260 */
261 protected function getBackendUser() {
262 return $GLOBALS['BE_USER'];
263 }
264
265 }