FileSystemNavigationFrameController.php 7.95 KB
Newer Older
1
2
3
<?php
namespace TYPO3\CMS\Backend\Controller;

4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
16

17
use Psr\Http\Message\ResponseInterface;
18
use Psr\Http\Message\ServerRequestInterface;
19
use TYPO3\CMS\Backend\Tree\View\ElementBrowserFolderTreeView;
20
21
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
Nicole Cordes's avatar
Nicole Cordes committed
22
use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24
25
use TYPO3\CMS\Filelist\FileListFolderTree;
use TYPO3\CMS\Backend\Template\DocumentTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
26
use TYPO3\CMS\Recordlist\Browser\ElementBrowser;
Nicole Cordes's avatar
Nicole Cordes committed
27

28
29
30
/**
 * Main script class for rendering of the folder tree
 */
31
class FileSystemNavigationFrameController {
32
33

	/**
34
35
	 * Content accumulates in this variable.
	 *
36
	 * @var string
37
38
39
40
	 */
	public $content;

	/**
41
	 * @var \TYPO3\CMS\Backend\Tree\View\FolderTreeView
42
43
44
45
46
47
48
49
50
51
52
	 */
	public $foldertree;

	/**
	 * document template object
	 *
	 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
	 */
	public $doc;

	/**
53
	 * @var string
54
55
56
57
	 */
	public $currentSubScript;

	/**
58
	 * @var bool
59
60
61
	 */
	public $cMR;

62
63
64
65
66
	/**
	 * @var array
	 */
	protected $scopeData;

67
68
69
70
71
	/**
	 * @var bool
	 */
	public $doHighlight;

72
73
74
75
76
77
78
79
	/**
	 * Constructor
	 */
	public function __construct() {
		$GLOBALS['SOBE'] = $this;
		$this->init();
	}

80
	/**
81
82
83
	 * @param ServerRequestInterface $request the current request
	 * @param ResponseInterface $response
	 * @return ResponseInterface the response with the content
84
	 */
85
	public function mainAction(ServerRequestInterface $request, ResponseInterface $response) {
86
87
		$this->initPage();
		$this->main();
88

89
90
91
92
		$response->getBody()->write($this->content);
		return $response;
	}

93
94
95
	/**
	 * Initialiation of the script class
	 *
96
	 * @return void
97
	 */
98
	protected function init() {
99
		// Setting GPvars:
Nicole Cordes's avatar
Nicole Cordes committed
100
101
		$this->currentSubScript = GeneralUtility::_GP('currentSubScript');
		$this->cMR = GeneralUtility::_GP('cMR');
102

103
104
		$scopeData = (string)GeneralUtility::_GP('scopeData');
		$scopeHash = (string)GeneralUtility::_GP('scopeHash');
105
106
107
108
109

		if (!empty($scopeData) && GeneralUtility::hmac($scopeData) === $scopeHash) {
			$this->scopeData = unserialize($scopeData);
		}

110
		// Create folder tree object:
111
		if (!empty($this->scopeData)) {
112
			$this->foldertree = GeneralUtility::makeInstance($this->scopeData['class']);
113
114
			$this->foldertree->thisScript = $this->scopeData['script'];
			$this->foldertree->ext_noTempRecyclerDirs = $this->scopeData['ext_noTempRecyclerDirs'];
115
116
117
118
119
120
			if ($this->foldertree instanceof ElementBrowserFolderTreeView) {
				$browser = GeneralUtility::makeInstance(ElementBrowser::class);
				$browser->mode = $this->scopeData['browser']['mode'];
				$browser->act = $this->scopeData['browser']['act'];
				$this->foldertree->setElementBrowser($browser);
			}
121
		} else {
122
			$this->foldertree = GeneralUtility::makeInstance(FileListFolderTree::class);
123
			$this->foldertree->thisScript = BackendUtility::getModuleUrl('file_navframe');
124
		}
125
126
		// Only set ext_IconMode if we are not running an ajax request from the ElementBrowser,
		// which has this property hardcoded to 1.
127
		if (!$this->foldertree instanceof ElementBrowserFolderTreeView) {
128
129
			$this->foldertree->ext_IconMode = $this->getBackendUser()->getTSConfigVal('options.folderTree.disableIconLinkToContextmenu');
		}
130
131
132
133
134
135
136
137
138
139
	}

	/**
	 * initialization for the visual parts of the class
	 * Use template rendering only if this is a non-AJAX call
	 *
	 * @return void
	 */
	public function initPage() {
		// 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
147
		// Adding javascript code for drag&drop and the filetree as well as the click menu code
		$dragDropCode = '
148
			Tree.ajaxID = "sc_alt_file_navframe_expandtoggle";
149
150
			Tree.registerDragDropHandlers()';
		if ($this->doHighlight) {
151
			$hlClass = $this->getBackendUser()->workspace === 0 ? 'active' : 'active active-ws wsver' . $GLOBALS['BE_USER']->workspace;
152
153
154
155
156
157
158
			$dragDropCode .= '
			Tree.highlightClass = "' . $hlClass . '";
			Tree.highlightActiveItem("", top.fsMod.navFrameHighlightedID["file"]);
			';
		}
		// Adding javascript for drag & drop activation and highlighting
		$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
164
		// Function, loading the list frame from navigation tree:
		function jumpTo(id, linkObj, highlightID, bank) {
165
			var theUrl = top.currentSubScript;
166
167
168
169
170
171
172
173
			if (theUrl.indexOf("?") != -1) {
				theUrl += "&id=" + id
			} else {
				theUrl += "?id=" + id
			}
			top.fsMod.currentBank = bank;
			top.TYPO3.Backend.ContentContainer.setUrl(theUrl);

174
			' . ($this->doHighlight ? 'Tree.highlightActiveItem("file", highlightID + "_" + bank);' : '') . '
175
			if (linkObj) { linkObj.blur(); }
176
177
			return false;
		}
178
		' . ($this->cMR ? ' jumpTo(top.fsMod.recentIds[\'file\'],\'\');' : ''));
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
	}

	/**
	 * Main function, rendering the folder tree
	 *
	 * @return void
	 */
	public function main() {
		// Produce browse-tree:
		$tree = $this->foldertree->getBrowsableTree();
		// Outputting page tree:
		$this->content .= $tree;
		// Setting up the buttons and markers for docheader
		$docHeaderButtons = $this->getButtons();
		$markers = array(
			'CONTENT' => $this->content
		);
		$subparts = array();
		// Build the <body> for the module
		$this->content = $this->doc->startPage('TYPO3 Folder Tree');
199
		$this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markers, $subparts);
200
201
202
203
204
205
206
207
		$this->content .= $this->doc->endPage();
		$this->content = $this->doc->insertStylesAndJS($this->content);
	}

	/**
	 * Outputting the accumulated content to screen
	 *
	 * @return void
208
	 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
209
210
	 */
	public function printContent() {
211
		GeneralUtility::logDeprecatedFunction();
212
213
214
215
216
217
218
219
220
221
222
223
224
		echo $this->content;
	}

	/**
	 * Create the panel of buttons for submitting the form or otherwise perform operations.
	 *
	 * @return array All available buttons as an assoc. array
	 */
	protected function getButtons() {
		$buttons = array(
			'csh' => '',
			'refresh' => ''
		);
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
231
232
233
234
235
236
237
238
239
240
241
		return $buttons;
	}

	/**********************************
	 *
	 * AJAX Calls
	 *
	 **********************************/
	/**
	 * Makes the AJAX call to expand or collapse the foldertree.
	 * Called by typo3/ajax.php
	 *
242
243
244
	 * @param ServerRequestInterface $request
	 * @param ResponseInterface $response
	 * @return ResponseInterface
245
	 */
246
247
	public function ajaxExpandCollapse(ServerRequestInterface $request, ResponseInterface $response) {
		$this->init();
248
249
		$tree = $this->foldertree->getBrowsableTree();
		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
260
261
262
263
264
	/**
	 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
	 */
	protected function getBackendUser() {
		return $GLOBALS['BE_USER'];
	}

265
}