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