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