[TASK] file_list: use t3-table & semantic HTML in localization
[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 text file 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 $storage = $fileFactory->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
149 $identifier = substr($combinedIdentifier, strpos($combinedIdentifier, ':') + 1);
150 if (!$storage->hasFolder($identifier)) {
151 $identifier = $storage->getFolderIdentifierFromFileIdentifier($identifier);
152 }
153
154 $this->folderObject = $fileFactory->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier);
155 // Disallow the rendering of the processing folder (e.g. could be called manually)
156 // and all folders without any defined storage
157 if ($this->folderObject && ($this->folderObject->getStorage()->getUid() == 0 || trim($this->folderObject->getStorage()->getProcessingFolder()->getIdentifier(), '/') === trim($this->folderObject->getIdentifier(), '/'))) {
158 $storage = $fileFactory->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
159 $this->folderObject = $storage->getRootLevelFolder();
160 }
161 } else {
162 // Take the first object of the first storage
163 $fileStorages = $GLOBALS['BE_USER']->getFileStorages();
164 $fileStorage = reset($fileStorages);
165 if ($fileStorage) {
166 // Validating the input "id" (the path, directory!) and
167 // checking it against the mounts of the user. - now done in the controller
168 $this->folderObject = $fileStorage->getRootLevelFolder();
169 } else {
170 throw new \RuntimeException('Could not find any folder to be displayed.', 1349276894);
171 }
172 }
173 } catch (\TYPO3\CMS\Core\Resource\Exception $fileException) {
174 // Take the first object of the first storage
175 $fileStorages = $GLOBALS['BE_USER']->getFileStorages();
176 $fileStorage = reset($fileStorages);
177 if ($fileStorage) {
178 // Set folder object to null and throw a message later on
179 $this->folderObject = $fileStorage->getRootLevelFolder();
180 } else {
181 $this->folderObject = NULL;
182 }
183 $this->errorMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
184 sprintf($GLOBALS['LANG']->getLL('folderNotFoundMessage', TRUE),
185 htmlspecialchars($this->id)
186 ),
187 $GLOBALS['LANG']->getLL('folderNotFoundTitle', TRUE),
188 \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE
189 );
190 }
191 // Configure the "menu" - which is used internally to save the values of sorting, displayThumbs etc.
192 $this->menuConfig();
193 }
194
195 /**
196 * Setting the menu/session variables
197 *
198 * @return void
199 * @todo Define visibility
200 */
201 public function menuConfig() {
202 // MENU-ITEMS:
203 // If array, then it's a selector box menu
204 // If empty string it's just a variable, that'll be saved.
205 // Values NOT in this array will not be saved in the settings-array for the module.
206 $this->MOD_MENU = array(
207 'sort' => '',
208 'reverse' => '',
209 'displayThumbs' => '',
210 'clipBoard' => '',
211 'bigControlPanel' => ''
212 );
213 // CLEANSE SETTINGS
214 $this->MOD_SETTINGS = BackendUtility::getModuleData(
215 $this->MOD_MENU,
216 GeneralUtility::_GP('SET'),
217 $this->MCONF['name']
218 );
219 }
220
221 /**
222 * Main function, creating the listing
223 *
224 * @return void
225 * @todo Define visibility
226 */
227 public function main() {
228 // Initialize the template object
229 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
230 $this->doc->backPath = $GLOBALS['BACK_PATH'];
231 $this->doc->setModuleTemplate('EXT:filelist/Resources/Private/Templates/file_list.html');
232
233 /** @var $pageRenderer \TYPO3\CMS\Core\Page\PageRenderer */
234 $pageRenderer = $this->doc->getPageRenderer();
235 $pageRenderer->loadPrototype();
236 $pageRenderer->loadJQuery();
237 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DragUploader');
238 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileListLocalisation');
239 $pageRenderer->addInlineLanguagelabelFile(
240 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('lang') . 'locallang_core.xlf',
241 'file_upload'
242 );
243
244 // There there was access to this file path, continue, make the list
245 if ($this->folderObject) {
246
247 // Create filelisting object
248 $this->filelist = GeneralUtility::makeInstance('TYPO3\\CMS\\Filelist\\FileList');
249 $this->filelist->backPath = $GLOBALS['BACK_PATH'];
250 // Apply predefined values for hidden checkboxes
251 // Set predefined value for DisplayBigControlPanel:
252 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'activated') {
253 $this->MOD_SETTINGS['bigControlPanel'] = TRUE;
254 } elseif ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'deactivated') {
255 $this->MOD_SETTINGS['bigControlPanel'] = FALSE;
256 }
257 // Set predefined value for DisplayThumbnails:
258 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'activated') {
259 $this->MOD_SETTINGS['displayThumbs'] = TRUE;
260 } elseif ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'deactivated') {
261 $this->MOD_SETTINGS['displayThumbs'] = FALSE;
262 }
263 // Set predefined value for Clipboard:
264 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableClipBoard') === 'activated') {
265 $this->MOD_SETTINGS['clipBoard'] = TRUE;
266 } elseif ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableClipBoard') === 'deactivated') {
267 $this->MOD_SETTINGS['clipBoard'] = FALSE;
268 }
269 // If user never opened the list module, set the value for displayThumbs
270 if (!isset($this->MOD_SETTINGS['displayThumbs'])) {
271 $this->MOD_SETTINGS['displayThumbs'] = $GLOBALS['BE_USER']->uc['thumbnailsByDefault'];
272 }
273 $this->filelist->thumbs = $this->MOD_SETTINGS['displayThumbs'];
274 // Create clipboard object and initialize that
275 $this->filelist->clipObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
276 $this->filelist->clipObj->fileMode = 1;
277 $this->filelist->clipObj->initializeClipboard();
278 $CB = GeneralUtility::_GET('CB');
279 if ($this->cmd == 'setCB') {
280 $CB['el'] = $this->filelist->clipObj->cleanUpCBC(array_merge(GeneralUtility::_POST('CBH'), GeneralUtility::_POST('CBC')), '_FILE');
281 }
282 if (!$this->MOD_SETTINGS['clipBoard']) {
283 $CB['setP'] = 'normal';
284 }
285 $this->filelist->clipObj->setCmd($CB);
286 $this->filelist->clipObj->cleanCurrent();
287 // Saves
288 $this->filelist->clipObj->endClipboard();
289 // If the "cmd" was to delete files from the list (clipboard thing), do that:
290 if ($this->cmd == 'delete') {
291 $items = $this->filelist->clipObj->cleanUpCBC(GeneralUtility::_POST('CBC'), '_FILE', 1);
292 if (count($items)) {
293 // Make command array:
294 $FILE = array();
295 foreach ($items as $v) {
296 $FILE['delete'][] = array('data' => $v);
297 }
298 // Init file processing object for deleting and pass the cmd array.
299 $fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility');
300 $fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
301 $fileProcessor->setActionPermissions();
302 $fileProcessor->dontCheckForUnique = $this->overwriteExistingFiles ? 1 : 0;
303 $fileProcessor->start($FILE);
304 $fileProcessor->processData();
305 $fileProcessor->pushErrorMessagesToFlashMessageQueue();
306 }
307 }
308 if (!isset($this->MOD_SETTINGS['sort'])) {
309 // Set default sorting
310 $this->MOD_SETTINGS['sort'] = 'file';
311 $this->MOD_SETTINGS['reverse'] = 0;
312 }
313 // Start up filelisting object, include settings.
314 $this->pointer = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
315 $this->filelist->start($this->folderObject, $this->pointer, $this->MOD_SETTINGS['sort'], $this->MOD_SETTINGS['reverse'], $this->MOD_SETTINGS['clipBoard'], $this->MOD_SETTINGS['bigControlPanel']);
316 // Generate the list
317 $this->filelist->generateList();
318 // Set top JavaScript:
319 $this->doc->JScode = $this->doc->wrapScriptTags('
320
321 if (top.fsMod) top.fsMod.recentIds["file"] = "' . rawurlencode($this->id) . '";
322 function jumpToUrl(URL) { //
323 window.location.href = URL;
324 }
325
326 ' . $this->filelist->CBfunctions());
327 // This will return content necessary for the context sensitive clickmenus to work: bodytag events, JavaScript functions and DIV-layers.
328 $this->doc->getContextMenuCode();
329 // Setting up the buttons and markers for docheader
330 list($buttons, $otherMarkers) = $this->filelist->getButtonsAndOtherMarkers($this->folderObject);
331 // add the folder info to the marker array
332 $otherMarkers['FOLDER_INFO'] = $this->filelist->getFolderInfo();
333 $docHeaderButtons = array_merge($this->getButtons(), $buttons);
334
335 // Build the <body> for the module
336 $moduleHeadline = $this->getModuleHeadline();
337 // Create output
338 $pageContent = $moduleHeadline !== '' ? '<h1>' . $moduleHeadline . '</h1>' : '';
339
340 $pageContent .= '<form action="' . htmlspecialchars($this->filelist->listURL()) . '" method="post" name="dblistForm">';
341 $pageContent .= $this->filelist->HTMLcode;
342 $pageContent .= '<input type="hidden" name="cmd" /></form>';
343
344 // Making listing options:
345 if ($this->filelist->HTMLcode) {
346 $pageContent .= '
347
348 <!--
349 Listing options for extended view, clipboard and thumbnails
350 -->
351 <div id="typo3-listOptions">
352 ';
353 // Add "display bigControlPanel" checkbox:
354 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'selectable') {
355 $pageContent .= BackendUtility::getFuncCheck($this->id, 'SET[bigControlPanel]', $this->MOD_SETTINGS['bigControlPanel'], '', '', 'id="bigControlPanel"') . '<label for="bigControlPanel"> ' . $GLOBALS['LANG']->getLL('bigControlPanel', TRUE) . '</label><br />';
356 }
357 // Add "display thumbnails" checkbox:
358 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'selectable') {
359 $pageContent .= BackendUtility::getFuncCheck($this->id, 'SET[displayThumbs]', $this->MOD_SETTINGS['displayThumbs'], '', '', 'id="checkDisplayThumbs"') . ' <label for="checkDisplayThumbs">' . $GLOBALS['LANG']->getLL('displayThumbs', TRUE) . '</label><br />';
360 }
361 // Add "clipboard" checkbox:
362 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableClipBoard') === 'selectable') {
363 $pageContent .= BackendUtility::getFuncCheck($this->id, 'SET[clipBoard]', $this->MOD_SETTINGS['clipBoard'], '', '', 'id="checkClipBoard"') . ' <label for="checkClipBoard">' . $GLOBALS['LANG']->getLL('clipBoard', TRUE) . '</label>';
364 }
365 $pageContent .= '
366 </div>
367 ';
368 // Set clipboard:
369 if ($this->MOD_SETTINGS['clipBoard']) {
370 $pageContent .= $this->filelist->clipObj->printClipboard();
371 $pageContent .= BackendUtility::cshItem('xMOD_csh_corebe', 'filelist_clipboard', $GLOBALS['BACK_PATH']);
372 }
373 }
374 $markerArray = array(
375 'CSH' => $docHeaderButtons['csh'],
376 'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
377 'CONTENT' => ($this->errorMessage ? $this->errorMessage->render() : '') . $pageContent,
378 'FOLDER_IDENTIFIER' => $this->folderObject->getCombinedIdentifier(),
379 'FILEDENYPATERN' => $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'],
380 'MAXFILESIZE' => GeneralUtility::getMaxUploadFileSize() * 1024,
381 );
382 $this->content = $this->doc->moduleBody(array(), $docHeaderButtons, array_merge($markerArray, $otherMarkers));
383 // Renders the module page
384 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('files'), $this->content);
385 } else {
386 $content = '';
387 if ($this->errorMessage) {
388 $this->errorMessage->setSeverity(\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
389 $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()));
390 }
391 // Create output - no access (no warning though)
392 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('files'), $content);
393 }
394 }
395
396 /**
397 * Get main headline based on active folder or storage for backend module
398 *
399 * Folder names are resolved to their special names like done in the tree view.
400 *
401 * @return string
402 */
403 protected function getModuleHeadline() {
404 $name = $this->folderObject->getName();
405 if ($name === '') {
406 // Show storage name on storage root
407 if ($this->folderObject->getIdentifier() === '/') {
408 $name = $this->folderObject->getStorage()->getName();
409 }
410 } else {
411 $name = key(\TYPO3\CMS\Core\Resource\Utility\ListUtility::resolveSpecialFolderNames(
412 array($name => $this->folderObject)
413 ));
414 }
415 return $name;
416 }
417
418 /**
419 * Outputting the accumulated content to screen
420 *
421 * @return void
422 * @todo Define visibility
423 */
424 public function printContent() {
425 echo $this->content;
426 }
427
428 /**
429 * Create the panel of buttons for submitting the form or otherwise perform operations.
430 *
431 * @return array All available buttons as an assoc. array
432 * @todo Define visibility
433 */
434 public function getButtons() {
435 $buttons = array(
436 'csh' => '',
437 'shortcut' => '',
438 'upload' => '',
439 'new' => ''
440 );
441 // Add shortcut
442 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
443 $buttons['shortcut'] = $this->doc->makeShortcutIcon('pointer,id,target,table', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']);
444 }
445 // FileList Module CSH:
446 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'filelist_module', $GLOBALS['BACK_PATH'], '', TRUE);
447 // Upload button (only if upload to this directory is allowed)
448 if ($this->folderObject && $this->folderObject->getStorage()->checkUserActionPermission('add', 'File') && $this->folderObject->checkActionPermission('write')) {
449 $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>';
450 }
451 // New folder button
452 if ($this->folderObject && ($this->folderObject->checkActionPermission('add') || $this->folderObject->getStorage()->checkUserActionPermission('add', 'File'))) {
453 $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>';
454 }
455 return $buttons;
456 }
457
458 }