[TASK] Make alt_file_navframe.php dispatched
[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\Backend\Utility\IconUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Main script class for rendering of the folder tree
22 *
23 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
24 */
25 class FileSystemNavigationFrameController {
26
27 // Internal, dynamic:
28 // Content accumulates in this variable.
29 /**
30 * @var string
31 */
32 public $content;
33
34 /**
35 * @var \TYPO3\CMS\Filelist\FileListFolderTree $foldertree the folder tree object
36 */
37 public $foldertree;
38
39 /**
40 * document template object
41 *
42 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
43 */
44 public $doc;
45
46 /**
47 * @var string
48 */
49 public $backPath;
50
51 // Internal, static: GPvar:
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 * Constructor
69 */
70 public function __construct() {
71 $GLOBALS['SOBE'] = $this;
72 $GLOBALS['BACK_PATH'] = '';
73 $this->init();
74 }
75
76 /**
77 * Initialiation of the script class
78 *
79 * @return void
80 */
81 protected function init() {
82 // Setting backPath
83 $this->backPath = $GLOBALS['BACK_PATH'];
84 // Setting GPvars:
85 $this->currentSubScript = GeneralUtility::_GP('currentSubScript');
86 $this->cMR = GeneralUtility::_GP('cMR');
87
88 $scopeData = (string)GeneralUtility::_GP('scopeData');
89 $scopeHash = (string)GeneralUtility::_GP('scopeHash');
90
91 if (!empty($scopeData) && GeneralUtility::hmac($scopeData) === $scopeHash) {
92 $this->scopeData = unserialize($scopeData);
93 }
94
95 // Create folder tree object:
96 if (!empty($this->scopeData)) {
97 $this->foldertree = GeneralUtility::makeInstance($this->scopeData['class']);
98 $this->foldertree->thisScript = $this->scopeData['script'];
99 $this->foldertree->ext_noTempRecyclerDirs = $this->scopeData['ext_noTempRecyclerDirs'];
100 $GLOBALS['SOBE']->browser = new \stdClass();
101 $GLOBALS['SOBE']->browser->mode = $this->scopeData['browser']['mode'];
102 $GLOBALS['SOBE']->browser->act = $this->scopeData['browser']['act'];
103 } else {
104 $this->foldertree = GeneralUtility::makeInstance(\TYPO3\CMS\Filelist\FileListFolderTree::class);
105 $this->foldertree->thisScript = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('file_navframe');
106 }
107
108 $this->foldertree->ext_IconMode = $GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.disableIconLinkToContextmenu');
109 }
110
111 /**
112 * initialization for the visual parts of the class
113 * Use template rendering only if this is a non-AJAX call
114 *
115 * @return void
116 */
117 public function initPage() {
118 // Setting highlight mode:
119 $this->doHighlight = !$GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.disableTitleHighlight');
120 // Create template object:
121 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
122 $this->doc->backPath = $GLOBALS['BACK_PATH'];
123 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/alt_file_navframe.html');
124 $this->doc->showFlashMessages = FALSE;
125 // Adding javascript code for drag&drop and the filetree as well as the click menu code
126 $dragDropCode = '
127 Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
128 Tree.registerDragDropHandlers()';
129 if ($this->doHighlight) {
130 $hlClass = $GLOBALS['BE_USER']->workspace === 0 ? 'active' : 'active active-ws wsver' . $GLOBALS['BE_USER']->workspace;
131 $dragDropCode .= '
132 Tree.highlightClass = "' . $hlClass . '";
133 Tree.highlightActiveItem("", top.fsMod.navFrameHighlightedID["file"]);
134 ';
135 }
136 // Adding javascript for drag & drop activation and highlighting
137 $this->doc->getDragDropCode('folders', $dragDropCode);
138 $this->doc->getContextMenuCode();
139
140 // Setting JavaScript for menu.
141 $this->doc->JScode .= $this->doc->wrapScriptTags(($this->currentSubScript ? 'top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript) . '");' : '') . '
142 // Function, loading the list frame from navigation tree:
143 function jumpTo(id, linkObj, highlightID, bank) {
144 var theUrl = top.TS.PATH_typo3 + top.currentSubScript ;
145 if (theUrl.indexOf("?") != -1) {
146 theUrl += "&id=" + id
147 } else {
148 theUrl += "?id=" + id
149 }
150 top.fsMod.currentBank = bank;
151 top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
152
153 ' . ($this->doHighlight ? 'Tree.highlightActiveItem("file", highlightID + "_" + bank);' : '') . '
154 if (linkObj) { linkObj.blur(); }
155 return false;
156 }
157 ' . ($this->cMR ? ' jumpTo(top.fsMod.recentIds[\'file\'],\'\');' : ''));
158 }
159
160 /**
161 * Main function, rendering the folder tree
162 *
163 * @return void
164 */
165 public function main() {
166 // Produce browse-tree:
167 $tree = $this->foldertree->getBrowsableTree();
168 // Outputting page tree:
169 $this->content .= $tree;
170 // Setting up the buttons and markers for docheader
171 $docHeaderButtons = $this->getButtons();
172 $markers = array(
173 'CONTENT' => $this->content
174 );
175 $subparts = array();
176 // Build the <body> for the module
177 $this->content = $this->doc->startPage('TYPO3 Folder Tree');
178 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, $subparts);
179 $this->content .= $this->doc->endPage();
180 $this->content = $this->doc->insertStylesAndJS($this->content);
181 }
182
183 /**
184 * Outputting the accumulated content to screen
185 *
186 * @return void
187 */
188 public function printContent() {
189 echo $this->content;
190 }
191
192 /**
193 * Create the panel of buttons for submitting the form or otherwise perform operations.
194 *
195 * @return array All available buttons as an assoc. array
196 */
197 protected function getButtons() {
198 $buttons = array(
199 'csh' => '',
200 'refresh' => ''
201 );
202 // Refresh
203 $buttons['refresh'] = '<a href="' . htmlspecialchars(GeneralUtility::getIndpEnv('REQUEST_URI')) . '">' . IconUtility::getSpriteIcon('actions-system-refresh') . '</a>';
204 // CSH
205 $buttons['csh'] = str_replace('typo3-csh-inline', 'typo3-csh-inline show-right', \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_csh_corebe', 'filetree'));
206 return $buttons;
207 }
208
209 /**********************************
210 *
211 * AJAX Calls
212 *
213 **********************************/
214 /**
215 * Makes the AJAX call to expand or collapse the foldertree.
216 * Called by typo3/ajax.php
217 *
218 * @param array $params Additional parameters (not used here)
219 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj The AjaxRequestHandler object of this request
220 * @return void
221 */
222 public function ajaxExpandCollapse($params, $ajaxObj) {
223 $this->init();
224 $tree = $this->foldertree->getBrowsableTree();
225 if ($this->foldertree->getAjaxStatus() === FALSE) {
226 $ajaxObj->setError($tree);
227 } else {
228 $ajaxObj->addContent('tree', $tree);
229 }
230 }
231
232 }