[TASK] Remove go-up button in filelist
[Packages/TYPO3.CMS.git] / typo3 / sysext / filelist / Classes / Controller / FileListController.php
1 <?php
2 namespace TYPO3\CMS\Filelist\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33 /**
34 * Script Class for creating the list of files in the File > Filelist module
35 *
36 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
37 */
38 class FileListController {
39
40 /**
41 * Module configuration
42 *
43 * @todo Define visibility
44 */
45 public $MCONF = array();
46
47 /**
48 * @todo Define visibility
49 */
50 public $MOD_MENU = array();
51
52 /**
53 * @todo Define visibility
54 */
55 public $MOD_SETTINGS = array();
56
57 /**
58 * Accumulated HTML output
59 *
60 * @todo Define visibility
61 */
62 public $content;
63
64 /**
65 * Document template object
66 *
67 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
68 * @todo Define visibility
69 */
70 public $doc;
71
72 /**
73 * "id" -> the path to list.
74 *
75 * @todo Define visibility
76 */
77 public $id;
78
79 /**
80 * @var \TYPO3\CMS\Core\Resource\Folder
81 */
82 protected $folderObject;
83
84 /**
85 * @var \TYPO3\CMS\Core\Messaging\FlashMessage
86 */
87 protected $errorMessage;
88
89 /**
90 * Pointer to listing
91 *
92 * @todo Define visibility
93 */
94 public $pointer;
95
96 /**
97 * "Table"
98 *
99 * @todo Define visibility
100 */
101 public $table;
102
103 /**
104 * Thumbnail mode.
105 *
106 * @todo Define visibility
107 */
108 public $imagemode;
109
110 /**
111 * @todo Define visibility
112 */
113 public $cmd;
114
115 /**
116 * @todo Define visibility
117 */
118 public $overwriteExistingFiles;
119
120 /**
121 * The file list object
122 *
123 * @var \TYPO3\CMS\Filelist\FileList
124 */
125 public $filelist = NULL;
126
127 /**
128 * Initialize variables, file object
129 * Incoming GET vars include id, pointer, table, imagemode
130 *
131 * @return void
132 * @todo Define visibility
133 */
134 public function init() {
135 // Setting GPvars:
136 $this->id = ($combinedIdentifier = GeneralUtility::_GP('id'));
137 $this->pointer = GeneralUtility::_GP('pointer');
138 $this->table = GeneralUtility::_GP('table');
139 $this->imagemode = GeneralUtility::_GP('imagemode');
140 $this->cmd = GeneralUtility::_GP('cmd');
141 $this->overwriteExistingFiles = GeneralUtility::_GP('overwriteExistingFiles');
142 // Setting module name:
143 $this->MCONF = $GLOBALS['MCONF'];
144 try {
145 if ($combinedIdentifier) {
146 /** @var $fileFactory \TYPO3\CMS\Core\Resource\ResourceFactory */
147 $fileFactory = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
148 $this->folderObject = $fileFactory->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
149 // Disallow the rendering of the processing folder (e.g. could be called manually)
150 // and all folders without any defined storage
151 if ($this->folderObject && ($this->folderObject->getStorage()->getUid() == 0 || trim($this->folderObject->getStorage()->getProcessingFolder()->getIdentifier(), '/') === trim($this->folderObject->getIdentifier(), '/'))) {
152 $storage = $fileFactory->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
153 $this->folderObject = $storage->getRootLevelFolder();
154 }
155 } else {
156 // Take the first object of the first storage
157 $fileStorages = $GLOBALS['BE_USER']->getFileStorages();
158 $fileStorage = reset($fileStorages);
159 if ($fileStorage) {
160 // Validating the input "id" (the path, directory!) and
161 // checking it against the mounts of the user. - now done in the controller
162 $this->folderObject = $fileStorage->getRootLevelFolder();
163 } else {
164 throw new \RuntimeException('Could not find any folder to be displayed.', 1349276894);
165 }
166 }
167 } catch (\TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException $fileException) {
168 // Set folder object to null and throw a message later on
169 $this->folderObject = NULL;
170 $this->errorMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
171 sprintf($GLOBALS['LANG']->getLL('folderNotFoundMessage', TRUE),
172 htmlspecialchars($this->id)
173 ),
174 $GLOBALS['LANG']->getLL('folderNotFoundTitle', TRUE),
175 \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE
176 );
177 }
178 // Configure the "menu" - which is used internally to save the values of sorting, displayThumbs etc.
179 $this->menuConfig();
180 }
181
182 /**
183 * Setting the menu/session variables
184 *
185 * @return void
186 * @todo Define visibility
187 */
188 public function menuConfig() {
189 // MENU-ITEMS:
190 // If array, then it's a selector box menu
191 // If empty string it's just a variable, that'll be saved.
192 // Values NOT in this array will not be saved in the settings-array for the module.
193 $this->MOD_MENU = array(
194 'sort' => '',
195 'reverse' => '',
196 'displayThumbs' => '',
197 'clipBoard' => '',
198 'bigControlPanel' => ''
199 );
200 // CLEANSE SETTINGS
201 $this->MOD_SETTINGS = BackendUtility::getModuleData(
202 $this->MOD_MENU,
203 GeneralUtility::_GP('SET'),
204 $this->MCONF['name']
205 );
206 }
207
208 /**
209 * Main function, creating the listing
210 *
211 * @return void
212 * @todo Define visibility
213 */
214 public function main() {
215 // Initialize the template object
216 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
217 $this->doc->backPath = $GLOBALS['BACK_PATH'];
218 $this->doc->setModuleTemplate('EXT:filelist/Resources/Private/Templates/file_list.html');
219 $this->doc->getPageRenderer()->loadPrototype();
220 $this->doc->getPageRenderer()->loadJQuery();
221 $this->doc->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/DragUploader');
222 $this->doc->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/FileListLocalisation');
223 $this->doc->getPageRenderer()->addInlineLanguagelabelFile(
224 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('lang') . 'locallang_core.xlf',
225 'file_upload'
226 );
227 // There there was access to this file path, continue, make the list
228 if ($this->folderObject) {
229
230 // Create filelisting object
231 $this->filelist = GeneralUtility::makeInstance('TYPO3\\CMS\\Filelist\\FileList');
232 $this->filelist->backPath = $GLOBALS['BACK_PATH'];
233 // Apply predefined values for hidden checkboxes
234 // Set predefined value for DisplayBigControlPanel:
235 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'activated') {
236 $this->MOD_SETTINGS['bigControlPanel'] = TRUE;
237 } elseif ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'deactivated') {
238 $this->MOD_SETTINGS['bigControlPanel'] = FALSE;
239 }
240 // Set predefined value for DisplayThumbnails:
241 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'activated') {
242 $this->MOD_SETTINGS['displayThumbs'] = TRUE;
243 } elseif ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'deactivated') {
244 $this->MOD_SETTINGS['displayThumbs'] = FALSE;
245 }
246 // Set predefined value for Clipboard:
247 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableClipBoard') === 'activated') {
248 $this->MOD_SETTINGS['clipBoard'] = TRUE;
249 } elseif ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableClipBoard') === 'deactivated') {
250 $this->MOD_SETTINGS['clipBoard'] = FALSE;
251 }
252 // If user never opened the list module, set the value for displayThumbs
253 if (!isset($this->MOD_SETTINGS['displayThumbs'])) {
254 $this->MOD_SETTINGS['displayThumbs'] = $GLOBALS['BE_USER']->uc['thumbnailsByDefault'];
255 }
256 $this->filelist->thumbs = $this->MOD_SETTINGS['displayThumbs'];
257 // Create clipboard object and initialize that
258 $this->filelist->clipObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
259 $this->filelist->clipObj->fileMode = 1;
260 $this->filelist->clipObj->initializeClipboard();
261 $CB = GeneralUtility::_GET('CB');
262 if ($this->cmd == 'setCB') {
263 $CB['el'] = $this->filelist->clipObj->cleanUpCBC(array_merge(GeneralUtility::_POST('CBH'), GeneralUtility::_POST('CBC')), '_FILE');
264 }
265 if (!$this->MOD_SETTINGS['clipBoard']) {
266 $CB['setP'] = 'normal';
267 }
268 $this->filelist->clipObj->setCmd($CB);
269 $this->filelist->clipObj->cleanCurrent();
270 // Saves
271 $this->filelist->clipObj->endClipboard();
272 // If the "cmd" was to delete files from the list (clipboard thing), do that:
273 if ($this->cmd == 'delete') {
274 $items = $this->filelist->clipObj->cleanUpCBC(GeneralUtility::_POST('CBC'), '_FILE', 1);
275 if (count($items)) {
276 // Make command array:
277 $FILE = array();
278 foreach ($items as $v) {
279 $FILE['delete'][] = array('data' => $v);
280 }
281 // Init file processing object for deleting and pass the cmd array.
282 $fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility');
283 $fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
284 $fileProcessor->setActionPermissions();
285 $fileProcessor->dontCheckForUnique = $this->overwriteExistingFiles ? 1 : 0;
286 $fileProcessor->start($FILE);
287 $fileProcessor->processData();
288 $fileProcessor->printLogErrorMessages();
289 }
290 }
291 if (!isset($this->MOD_SETTINGS['sort'])) {
292 // Set default sorting
293 $this->MOD_SETTINGS['sort'] = 'file';
294 $this->MOD_SETTINGS['reverse'] = 0;
295 }
296 // Start up filelisting object, include settings.
297 $this->pointer = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
298 $this->filelist->start($this->folderObject, $this->pointer, $this->MOD_SETTINGS['sort'], $this->MOD_SETTINGS['reverse'], $this->MOD_SETTINGS['clipBoard'], $this->MOD_SETTINGS['bigControlPanel']);
299 // Generate the list
300 $this->filelist->generateList();
301 // Set top JavaScript:
302 $this->doc->JScode = $this->doc->wrapScriptTags('
303
304 if (top.fsMod) top.fsMod.recentIds["file"] = "' . rawurlencode($this->id) . '";
305 function jumpToUrl(URL) { //
306 window.location.href = URL;
307 }
308
309 ' . $this->filelist->CBfunctions());
310 // This will return content necessary for the context sensitive clickmenus to work: bodytag events, JavaScript functions and DIV-layers.
311 $this->doc->getContextMenuCode();
312 // Setting up the buttons and markers for docheader
313 list($buttons, $otherMarkers) = $this->filelist->getButtonsAndOtherMarkers($this->folderObject);
314 // add the folder info to the marker array
315 $otherMarkers['FOLDER_INFO'] = $this->filelist->getFolderInfo();
316 $docHeaderButtons = array_merge($this->getButtons(), $buttons);
317
318 // Build the <body> for the module
319 $moduleHeadline = $this->getModuleHeadline();
320 // Create output
321 $pageContent = $moduleHeadline !== '' ? '<h1>' . $moduleHeadline . '</h1>' : '';
322
323 $pageContent .= '<form action="' . htmlspecialchars($this->filelist->listURL()) . '" method="post" name="dblistForm">';
324 $pageContent .= $this->filelist->HTMLcode;
325 $pageContent .= '<input type="hidden" name="cmd" /></form>';
326
327 // Making listing options:
328 if ($this->filelist->HTMLcode) {
329 $pageContent .= '
330
331 <!--
332 Listing options for extended view, clipboard and thumbnails
333 -->
334 <div id="typo3-listOptions">
335 ';
336 // Add "display bigControlPanel" checkbox:
337 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'selectable') {
338 $pageContent .= BackendUtility::getFuncCheck($this->id, 'SET[bigControlPanel]', $this->MOD_SETTINGS['bigControlPanel'], '', '', 'id="bigControlPanel"') . '<label for="bigControlPanel"> ' . $GLOBALS['LANG']->getLL('bigControlPanel', TRUE) . '</label><br />';
339 }
340 // Add "display thumbnails" checkbox:
341 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'selectable') {
342 $pageContent .= BackendUtility::getFuncCheck($this->id, 'SET[displayThumbs]', $this->MOD_SETTINGS['displayThumbs'], '', '', 'id="checkDisplayThumbs"') . ' <label for="checkDisplayThumbs">' . $GLOBALS['LANG']->getLL('displayThumbs', TRUE) . '</label><br />';
343 }
344 // Add "clipboard" checkbox:
345 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableClipBoard') === 'selectable') {
346 $pageContent .= BackendUtility::getFuncCheck($this->id, 'SET[clipBoard]', $this->MOD_SETTINGS['clipBoard'], '', '', 'id="checkClipBoard"') . ' <label for="checkClipBoard">' . $GLOBALS['LANG']->getLL('clipBoard', TRUE) . '</label>';
347 }
348 $pageContent .= '
349 </div>
350 ';
351 // Set clipboard:
352 if ($this->MOD_SETTINGS['clipBoard']) {
353 $pageContent .= $this->filelist->clipObj->printClipboard();
354 $pageContent .= BackendUtility::cshItem('xMOD_csh_corebe', 'filelist_clipboard', $GLOBALS['BACK_PATH']);
355 }
356 }
357 $markerArray = array(
358 'CSH' => $docHeaderButtons['csh'],
359 'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
360 'CONTENT' => ($this->errorMessage ? $this->errorMessage->render() : '') . $pageContent,
361 'FOLDER_IDENTIFIER' => $this->folderObject->getCombinedIdentifier(),
362 'FILEDENYPATERN' => $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'],
363 'MAXFILESIZE' => GeneralUtility::getMaxUploadFileSize() * 1024,
364 );
365 $this->content = $this->doc->moduleBody(array(), $docHeaderButtons, array_merge($markerArray, $otherMarkers));
366 // Renders the module page
367 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('files'), $this->content);
368 } else {
369 $content = '';
370 if ($this->errorMessage) {
371 $this->errorMessage->setSeverity(\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
372 $content = $this->doc->moduleBody(array(), array_merge(array('REFRESH' => ''), $this->getButtons()), array('CSH' => '', 'TITLE' => '', 'FOLDER_INFO' => '', 'PAGE_ICON' => '', 'FUNC_MENU' => '', 'CONTENT' => $this->errorMessage->render()));
373 }
374 // Create output - no access (no warning though)
375 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('files'), $content);
376 }
377 }
378
379 /**
380 * Get main headline based on active folder or storage for backend module
381 *
382 * Folder names are resolved to their special names like done in the tree view.
383 *
384 * @return string
385 */
386 protected function getModuleHeadline() {
387 $name = $this->folderObject->getName();
388 if ($name === '') {
389 // Show storage name on storage root
390 if ($this->folderObject->getIdentifier() === '/') {
391 $name = $this->folderObject->getStorage()->getName();
392 }
393 } else {
394 $name = key(\TYPO3\CMS\Core\Resource\Utility\ListUtility::resolveSpecialFolderNames(
395 array($name => $this->folderObject)
396 ));
397 }
398 return $name;
399 }
400
401 /**
402 * Outputting the accumulated content to screen
403 *
404 * @return void
405 * @todo Define visibility
406 */
407 public function printContent() {
408 echo $this->content;
409 }
410
411 /**
412 * Create the panel of buttons for submitting the form or otherwise perform operations.
413 *
414 * @return array All available buttons as an assoc. array
415 * @todo Define visibility
416 */
417 public function getButtons() {
418 $buttons = array(
419 'csh' => '',
420 'shortcut' => '',
421 'upload' => '',
422 'new' => ''
423 );
424 // Add shortcut
425 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
426 $buttons['shortcut'] = $this->doc->makeShortcutIcon('pointer,id,target,table', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']);
427 }
428 // FileList Module CSH:
429 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'filelist_module', $GLOBALS['BACK_PATH'], '', TRUE);
430 // Upload button (only if upload to this directory is allowed)
431 if ($this->folderObject && $this->folderObject->getStorage()->checkUserActionPermission('add', 'File') && $this->folderObject->checkActionPermission('write')) {
432 $buttons['upload'] = '<a href="' . $GLOBALS['BACK_PATH'] . 'file_upload.php?target=' . rawurlencode($this->folderObject->getCombinedIdentifier()) . '&amp;returnUrl=' . rawurlencode($this->filelist->listURL()) . '" id="button-upload" title="' . $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.upload', TRUE)) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-upload') . '</a>';
433 }
434 // New folder button
435 if ($this->folderObject && ($this->folderObject->checkActionPermission('add') || $this->folderObject->getStorage()->checkUserActionPermission('add', 'File'))) {
436 $buttons['new'] = '<a href="' . $GLOBALS['BACK_PATH'] . 'file_newfolder.php?target=' . rawurlencode($this->folderObject->getCombinedIdentifier()) . '&amp;returnUrl=' . rawurlencode($this->filelist->listURL()) . '" title="' . $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.new', TRUE)) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-new') . '</a>';
437 }
438 return $buttons;
439 }
440
441 }