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