[TASK] oncontextmenu: Avoid duplicating onclick-functionality
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Utility / File / ExtendedFileUtility.php
1 <?php
2 namespace TYPO3\CMS\Core\Utility\File;
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\Resource\File;
32 use TYPO3\CMS\Core\Utility\GeneralUtility;
33
34 /**
35 * Contains functions for performing file operations like copying, pasting, uploading, moving,
36 * deleting etc. through the TCE
37 *
38 * See document "TYPO3 Core API" for syntax
39 *
40 * This class contains functions primarily used by tce_file.php (TYPO3 Core Engine for file manipulation)
41 * Functions include copying, moving, deleting, uploading and so on...
42 *
43 * Important internal variables:
44 *
45 * $filemounts (see basicFileFunctions)
46 * $f_ext (see basicFileFunctions)
47 *
48 * All fileoperations must be within the filemount-paths. Further the fileextension
49 * MUST validate TRUE with the f_ext array
50 *
51 * The unzip-function allows unzip only if the destination path has it's f_ext[]['allow'] set to '*'!!
52 * You are allowed to copy/move folders within the same 'space' (web/ftp).
53 * You are allowed to copy/move folders between spaces (web/ftp) IF the destination has it's f_ext[]['allow'] set to '*'!
54 *
55 * Advice:
56 * You should always exclude php-files from the webspace. This will keep people from uploading, copy/moving and renaming files to become executable php scripts.
57 * You should never mount a ftp_space 'below' the webspace so that it reaches into the webspace. This is because if somebody unzips a zip-file in the ftp-space so that it reaches out into the webspace this will be a violation of the safety
58 * For example this is a bad idea: you have an ftp-space that is '/www/' and a web-space that is '/www/htdocs/'
59 *
60 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
61 */
62 class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility {
63
64 // External static variables:
65 // Notice; some of these are overridden in the start() method with values from $GLOBALS['TYPO3_CONF_VARS']['BE']
66 // Path to unzip-program (with trailing '/')
67 /**
68 * @todo Define visibility
69 */
70 public $unzipPath = '';
71
72 // If set, the uploaded files will overwrite existing files.
73 /**
74 * @todo Define visibility
75 */
76 public $dontCheckForUnique = 0;
77
78 /**
79 * This array is self-explaining (look in the class below).
80 * It grants access to the functions. This could be set from outside in order to enabled functions to users.
81 * See also the function setActionPermissions() which takes input directly from the user-record
82 */
83 public $actionPerms = array(
84 // File permissions
85 'addFile' => FALSE,
86 'readFile' => FALSE,
87 'writeFile' => FALSE,
88 'copyFile' => FALSE,
89 'moveFile' => FALSE,
90 'renameFile' => FALSE,
91 'unzipFile' => FALSE,
92 'deleteFile' => FALSE,
93 // Folder permissions
94 'addFolder' => FALSE,
95 'readFolder' => FALSE,
96 'writeFolder' => FALSE,
97 'copyFolder' => FALSE,
98 'moveFolder' => FALSE,
99 'renameFolder' => FALSE,
100 'deleteFolder' => FALSE,
101 'recursivedeleteFolder' => FALSE
102 );
103
104 // This is regarded to be the recycler folder
105 /**
106 * @todo Define visibility
107 */
108 public $recyclerFN = '_recycler_';
109
110 /**
111 * Whether to use recycler (0 = no, 1 = if available, 2 = always)
112 *
113 * @var integer
114 * @deprecated since TYPO3 6.0
115 * @todo Define visibility
116 */
117 public $useRecycler = 1;
118
119 // Internal, dynamic
120 // Will contain map between upload ID and the final filename
121 /**
122 * @todo Define visibility
123 */
124 public $internalUploadMap = array();
125
126 /**
127 * @todo Define visibility
128 */
129 public $lastError = '';
130
131 /**
132 * @var array
133 */
134 protected $fileCmdMap;
135
136 /**
137 * The File Factory
138 *
139 * @var \TYPO3\CMS\Core\Resource\ResourceFactory
140 */
141 protected $fileFactory;
142
143
144 /**
145 * @var \TYPO3\CMS\Core\Resource\FileRepository
146 */
147 protected $fileRepository;
148
149 /**
150 * Initialization of the class
151 *
152 * @param array $fileCmds Array with the commands to execute. See "TYPO3 Core API" document
153 * @return void
154 * @todo Define visibility
155 */
156 public function start($fileCmds) {
157 $unzipPath = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path']);
158 if (substr($unzipPath, -1) !== '/' && is_dir($unzipPath)) {
159 // Make sure the path ends with a slash
160 $unzipPath .= '/';
161 }
162 $this->unzipPath = $unzipPath;
163 // Initialize Object Factory
164 $this->fileFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
165 // Initialize Object Factory
166 $this->fileRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
167 // Initializing file processing commands:
168 $this->fileCmdMap = $fileCmds;
169 }
170
171 /**
172 * Sets up permission to perform file/directory operations.
173 * See below or the be_user-table for the significance of the various bits in $setup.
174 *
175 * @return void
176 * @deprecated since 6.2 will be removed two versions later. Use ExtendedFileUtility::setActionPermissions() instead
177 */
178 public function init_actionPerms() {
179 GeneralUtility::logDeprecatedFunction();
180 $this->setActionPermissions();
181 }
182
183 /**
184 * Sets the file action permissions.
185 * If no argument is given, permissions of the currently logged in backend user are taken into account.
186 *
187 * @param array $permissions File Permissions.
188 */
189 public function setActionPermissions(array $permissions = array()) {
190 if (empty($permissions)) {
191 $permissions = $GLOBALS['BE_USER']->getFilePermissions();
192 }
193 $this->actionPerms = $permissions;
194 }
195
196 /**
197 * Processing the command array in $this->fileCmdMap
198 *
199 * @return mixed FALSE, if the file functions were not initialized
200 * @throws \UnexpectedValueException
201 * @todo Define visibility
202 */
203 public function processData() {
204 $result = array();
205 if (!$this->isInit) {
206 return FALSE;
207 }
208 if (is_array($this->fileCmdMap)) {
209 // Check if there were uploads expected, but no one made
210 if ($this->fileCmdMap['upload']) {
211 $uploads = $this->fileCmdMap['upload'];
212 foreach ($uploads as $upload) {
213 if (!$_FILES[('upload_' . $upload['data'])]['name']) {
214 unset($this->fileCmdMap['upload'][$upload['data']]);
215 }
216 }
217 if (count($this->fileCmdMap['upload']) == 0) {
218 $this->writelog(1, 1, 108, 'No file was uploaded!', '');
219 }
220 }
221 // Traverse each set of actions
222 foreach ($this->fileCmdMap as $action => $actionData) {
223 // Traverse all action data. More than one file might be affected at the same time.
224 if (is_array($actionData)) {
225 $result[$action] = array();
226 foreach ($actionData as $cmdArr) {
227 // Clear file stats
228 clearstatcache();
229 // Branch out based on command:
230 switch ($action) {
231 case 'delete':
232 $result[$action][] = $this->func_delete($cmdArr);
233 break;
234 case 'copy':
235 $result[$action][] = $this->func_copy($cmdArr);
236 break;
237 case 'move':
238 $result[$action][] = $this->func_move($cmdArr);
239 break;
240 case 'rename':
241 $result[$action][] = $this->func_rename($cmdArr);
242 break;
243 case 'newfolder':
244 $result[$action][] = $this->func_newfolder($cmdArr);
245 break;
246 case 'newfile':
247 $result[$action][] = $this->func_newfile($cmdArr);
248 break;
249 case 'editfile':
250 $result[$action][] = $this->func_edit($cmdArr);
251 break;
252 case 'upload':
253 $result[$action][] = $this->func_upload($cmdArr);
254 break;
255 case 'unzip':
256 $result[$action][] = $this->func_unzip($cmdArr);
257 break;
258 }
259 // Hook for post-processing the action
260 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_extfilefunc.php']['processData'])) {
261 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_extfilefunc.php']['processData'] as $classRef) {
262 $hookObject = GeneralUtility::getUserObj($classRef);
263 if (!$hookObject instanceof \TYPO3\CMS\Core\Utility\File\ExtendedFileUtilityProcessDataHookInterface) {
264 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtilityProcessDataHookInterface', 1279719168);
265 }
266 $hookObject->processData_postProcessAction($action, $cmdArr, $result[$action], $this);
267 }
268 }
269 }
270 }
271 }
272 }
273 return $result;
274 }
275
276 /**
277 * Adds log error messages from the operations of this script instance to the FlashMessageQueue
278 *
279 * @param string $redirect Redirect URL (for creating link in message)
280 * @return void
281 * @todo Define visibility
282 * @deprecated since TYPO3 6.1, will be removed two versions later, use ->getErrorMessages directly instead
283 */
284 public function printLogErrorMessages($redirect = '') {
285 GeneralUtility::logDeprecatedFunction();
286 $this->getErrorMessages();
287 }
288
289 /**
290 * Adds log error messages from the previous file operations of this script instance
291 * to the FlashMessageQueue
292 *
293 * @return void
294 * @todo Define visibility
295 */
296 public function getErrorMessages() {
297 $res = $this->getDatabaseConnection()->exec_SELECTquery(
298 '*',
299 'sys_log',
300 'type = 2 AND userid = ' . intval($this->getBackendUser()->user['uid']) . ' AND tstamp=' . intval($GLOBALS['EXEC_TIME']) . ' AND error<>0'
301 );
302 while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
303 $logData = unserialize($row['log_data']);
304 $msg = $row['error'] . ': ' . sprintf($row['details'], $logData[0], $logData[1], $logData[2], $logData[3], $logData[4]);
305 $flashMessage = GeneralUtility::makeInstance(
306 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
307 $msg,
308 '',
309 \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
310 TRUE
311 );
312 $this->addFlashMessage($flashMessage);
313 }
314 $this->getDatabaseConnection()->sql_free_result($res);
315 }
316
317 /**
318 * Goes back in the path and checks in each directory if a folder named $this->recyclerFN (usually '_recycler_') is present.
319 * If a folder in the tree happens to be a _recycler_-folder (which means that we're deleting something inside a _recycler_-folder) this is ignored
320 *
321 * @param string $theFile Takes a valid Path ($theFile)
322 * @return string Returns the path (without trailing slash) of the closest recycle-folder if found. Else FALSE.
323 * @todo To be put in Storage with a better concept
324 * @todo Define visibility
325 * @deprecated since TYPO3 6.0, use \TYPO3\CMS\Core\Resource\ResourceStorage method instead
326 */
327 public function findRecycler($theFile) {
328 GeneralUtility::logDeprecatedFunction();
329 if ($this->isPathValid($theFile)) {
330 $theFile = $this->cleanDirectoryName($theFile);
331 $fI = GeneralUtility::split_fileref($theFile);
332 $c = 0;
333 // !!! Method has been put in the storage, can be saftely removed
334 $rDir = $fI['path'] . $this->recyclerFN;
335 while ($this->checkPathAgainstMounts($fI['path']) && $c < 20) {
336 if (@is_dir($rDir) && $this->recyclerFN != $fI['file']) {
337 return $rDir;
338 }
339 $theFile = $fI['path'];
340 $theFile = $this->cleanDirectoryName($theFile);
341 $fI = GeneralUtility::split_fileref($theFile);
342 $c++;
343 }
344 }
345 }
346
347 /**
348 * Logging file operations
349 *
350 * @param integer $action The action number. See the functions in the class for a hint. Eg. edit is '9', upload is '1' ...
351 * @param integer $error The severity: 0 = message, 1 = error, 2 = System Error, 3 = security notice (admin)
352 * @param integer $details_nr This number is unique for every combination of $type and $action. This is the error-message number, which can later be used to translate error messages.
353 * @param string $details This is the default, raw error message in english
354 * @param array $data Array with special information that may go into $details by "%s" marks / sprintf() when the log is shown
355 * @return void
356 * @todo Define visibility
357 */
358 public function writeLog($action, $error, $details_nr, $details, $data) {
359 // Type value for tce_file.php
360 $type = 2;
361 if (is_object($this->getBackendUser())) {
362 $this->getBackendUser()->writelog($type, $action, $error, $details_nr, $details, $data);
363 }
364 $this->lastError = vsprintf($details, $data);
365 }
366
367 /*************************************
368 *
369 * File operation functions
370 *
371 **************************************/
372 /**
373 * Deleting files and folders (action=4)
374 *
375 * @param array $cmds $cmds['data'] is the file/folder to delete
376 * @return boolean Returns TRUE upon success
377 * @todo Define visibility
378 */
379 public function func_delete($cmds) {
380 $result = FALSE;
381 if (!$this->isInit) {
382 return $result;
383 }
384 // Example indentifier for $cmds['data'] => "4:mypath/tomyfolder/myfile.jpg"
385 // for backwards compatibility: the combined file identifier was the path+filename
386 $fileObject = $this->getFileObject($cmds['data']);
387 // @todo implement the recycler feature which has been removed from the original implementation
388 // checks to delete the file
389 if ($fileObject instanceof File) {
390 // check if the file still has references
391 // Exclude sys_file_metadata records as these are no use references
392 $refIndexRecords = $this->getDatabaseConnection()->exec_SELECTgetRows(
393 '*',
394 'sys_refindex',
395 'deleted=0 AND ref_table="sys_file" AND ref_uid=' . intval($fileObject->getUid())
396 . ' AND tablename != "sys_file_metadata"'
397 );
398 if (count($refIndexRecords) > 0) {
399 $shortcutContent = array();
400 foreach ($refIndexRecords as $fileReferenceRow) {
401 if ($fileReferenceRow['tablename'] === 'sys_file_reference') {
402 $row = $this->transformFileReferenceToRecordReference($fileReferenceRow);
403 $shortcutRecord = BackendUtility::getRecord($row['tablename'], $row['recuid']);
404 $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord($row['tablename'], $shortcutRecord);
405 $onClick = 'Clickmenu.show("' . $row['tablename'] . '", "' . $row['recuid'] . '", "1", "+info,history,edit", "|", "");return false;';
406 $shortcutContent[] = '<a href="#" oncontextmenu="this.click();return false;" onclick="' . htmlspecialchars($onClick) . '">' . $icon . '</a>' . htmlspecialchars((BackendUtility::getRecordTitle($row['tablename'], $shortcutRecord) . ' [' . BackendUtility::getRecordPath($shortcutRecord['pid'], '', 80) . ']'));
407 }
408 }
409
410 // render a message that the file could not be deleted
411 $flashMessage = GeneralUtility::makeInstance(
412 '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
413 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileNotDeletedHasReferences'), $fileObject->getName()) . '<br />' . implode('<br />', $shortcutContent),
414 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileNotDeletedHasReferences'),
415 \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
416 TRUE
417 );
418 $this->addFlashMessage($flashMessage);
419 } else {
420 try {
421 $result = $fileObject->delete();
422
423 // show the user that the file was deleted
424 $flashMessage = GeneralUtility::makeInstance(
425 '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
426 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileDeleted'), $fileObject->getName()),
427 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileDeleted'),
428 \TYPO3\CMS\Core\Messaging\FlashMessage::OK,
429 TRUE
430 );
431 $this->addFlashMessage($flashMessage);
432 // Log success
433 $this->writelog(4, 0, 1, 'File "%s" deleted', array($fileObject->getIdentifier()));
434 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
435 $this->writelog(4, 1, 112, 'You are not allowed to access the file', array($fileObject->getIdentifier()));
436 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
437 $this->writelog(4, 1, 111, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
438 } catch (\RuntimeException $e) {
439 $this->writelog(4, 1, 110, 'Could not delete file "%s". Write-permission problem?', array($fileObject->getIdentifier()));
440 }
441 }
442 } else {
443 try {
444 /** @var $fileObject \TYPO3\CMS\Core\Resource\FolderInterface */
445 if ($fileObject->getFileCount() > 0) {
446 // render a message that the folder could not be deleted because it still contains files
447 $flashMessage = GeneralUtility::makeInstance(
448 '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
449 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderNotDeletedHasFiles'), $fileObject->getName()),
450 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderNotDeletedHasFiles'),
451 \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
452 TRUE
453 );
454 $this->addFlashMessage($flashMessage);
455 } else {
456 $result = $fileObject->delete(TRUE);
457
458 // notify the user that the folder was deleted
459 $flashMessage = GeneralUtility::makeInstance(
460 '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
461 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderDeleted'), $fileObject->getName()),
462 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderDeleted'),
463 \TYPO3\CMS\Core\Messaging\FlashMessage::OK,
464 TRUE
465 );
466 $this->addFlashMessage($flashMessage);
467 // Log success
468 $this->writelog(4, 0, 3, 'Directory "%s" deleted', array($fileObject->getIdentifier()));
469 }
470
471 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
472 $this->writelog(4, 1, 123, 'You are not allowed to access the directory', array($fileObject->getIdentifier()));
473 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
474 $this->writelog(4, 1, 121, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
475 } catch (\RuntimeException $e) {
476 $this->writelog(4, 1, 120, 'Could not delete directory! Write-permission problem? Is directory "%s" empty? (You are not allowed to delete directories recursively).', array($fileObject->getIdentifier()));
477 }
478 }
479 return $result;
480 }
481
482 /**
483 * Maps results from the fal file reference table on the
484 * structure of the normal reference index table.
485 *
486 * @param array $referenceRecord
487 * @return array
488 */
489 protected function transformFileReferenceToRecordReference(array $referenceRecord) {
490 $fileReference = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
491 '*',
492 'sys_file_reference',
493 'uid=' . (int)$referenceRecord['recuid']
494 );
495 return array(
496 'recuid' => $fileReference['uid_foreign'],
497 'tablename' => $fileReference['tablenames'],
498 'field' => $fileReference['fieldname'],
499 'flexpointer' => '',
500 'softref_key' => '',
501 'sorting' => $fileReference['sorting_foreign']
502 );
503 }
504
505 /**
506 * Gets a File or a Folder object from an identifier [storage]:[fileId]
507 *
508 * @param string $identifier
509 * @return \TYPO3\CMS\Core\Resource\Folder|\TYPO3\CMS\Core\Resource\File
510 * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidFileException
511 */
512 protected function getFileObject($identifier) {
513 $object = $this->fileFactory->retrieveFileOrFolderObject($identifier);
514 if (!is_object($object)) {
515 throw new \TYPO3\CMS\Core\Resource\Exception\InvalidFileException('The item ' . $identifier . ' was not a file or directory!!', 1320122453);
516 }
517 if ($object->getStorage()->getUid() === 0) {
518 throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889830);
519 }
520 return $object;
521 }
522
523 /**
524 * Copying files and folders (action=2)
525 *
526 * $cmds['data'] (string): The file/folder to copy
527 * + example "4:mypath/tomyfolder/myfile.jpg")
528 * + for backwards compatibility: the identifier was the path+filename
529 * $cmds['target'] (string): The path where to copy to.
530 * + example "2:targetpath/targetfolder/"
531 * $cmds['altName'] (string): Use an alternative name if the target already exists
532 *
533 * @param array $cmds Command details as described above
534 * @return \TYPO3\CMS\Core\Resource\File
535 */
536 protected function func_copy($cmds) {
537 if (!$this->isInit) {
538 return FALSE;
539 }
540 $sourceFileObject = $this->getFileObject($cmds['data']);
541 /** @var $targetFolderObject \TYPO3\CMS\Core\Resource\Folder */
542 $targetFolderObject = $this->getFileObject($cmds['target']);
543 // Basic check
544 if (!$targetFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
545 $this->writelog(2, 2, 100, 'Destination "%s" was not a directory', array($cmds['target']));
546 return FALSE;
547 }
548 // If this is TRUE, we append _XX to the file name if
549 $appendSuffixOnConflict = (string) $cmds['altName'];
550 $resultObject = NULL;
551 // Copying the file
552 if ($sourceFileObject instanceof File) {
553 try {
554 $conflictMode = $appendSuffixOnConflict !== '' ? 'renameNewFile' : 'cancel';
555 $resultObject = $sourceFileObject->copyTo($targetFolderObject, NULL, $conflictMode);
556 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
557 $this->writelog(2, 1, 114, 'You are not allowed to copy files', '');
558 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
559 $this->writelog(2, 1, 110, 'Could not access all necessary resources. Source file or destination maybe was not within your mountpoints? T="%s", D="%s"', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
560 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
561 $this->writelog(2, 1, 111, 'Extension of file name "%s" is not allowed in "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
562 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
563 $this->writelog(2, 1, 112, 'File "%s" already exists in folder "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
564 } catch (\BadMethodCallException $e) {
565 $this->writelog(3, 1, 128, 'The function to copy a file between storages is not yet implemented', array());
566 } catch (\RuntimeException $e) {
567 $this->writelog(2, 2, 109, 'File "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
568 }
569 if ($resultObject) {
570 $this->writelog(2, 0, 1, 'File "%s" copied to "%s"', array($sourceFileObject->getIdentifier(), $resultObject->getIdentifier()));
571 }
572 } else {
573 // Else means this is a Folder
574 $sourceFolderObject = $sourceFileObject;
575 try {
576 $conflictMode = $appendSuffixOnConflict !== '' ? 'renameNewFile' : 'cancel';
577 $resultObject = $sourceFolderObject->copyTo($targetFolderObject, NULL, $conflictMode);
578 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
579 $this->writelog(2, 1, 125, 'You are not allowed to copy directories', '');
580 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
581 $this->writelog(2, 1, 110, 'Could not access all necessary resources. Source file or destination maybe was not within your mountpoints? T="%s", D="%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
582 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException $e) {
583 $this->writelog(2, 1, 121, 'You don\'t have full access to the destination directory "%s"!', array($targetFolderObject->getIdentifier()));
584 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException $e) {
585 $this->writelog(2, 1, 122, 'Destination cannot be inside the target! D="%s", T="%s"', array($targetFolderObject->getIdentifier(), $sourceFolderObject->getIdentifier()));
586 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException $e) {
587 $this->writelog(2, 1, 123, 'Target "%s" already exists!', array($targetFolderObject->getIdentifier()));
588 } catch (\BadMethodCallException $e) {
589 $this->writelog(3, 1, 129, 'The function to copy a folder between storages is not yet implemented', array());
590 } catch (\RuntimeException $e) {
591 $this->writelog(2, 2, 119, 'Directory "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
592 }
593 if ($resultObject) {
594 $this->writelog(2, 0, 2, 'Directory "%s" copied to "%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
595 }
596 }
597 return $resultObject;
598 }
599
600 /**
601 * Moving files and folders (action=3)
602 *
603 * $cmds['data'] (string): The file/folder to move
604 * + example "4:mypath/tomyfolder/myfile.jpg")
605 * + for backwards compatibility: the identifier was the path+filename
606 * $cmds['target'] (string): The path where to move to.
607 * + example "2:targetpath/targetfolder/"
608 * $cmds['altName'] (string): Use an alternative name if the target already exists
609 *
610 * @param array $cmds Command details as described above
611 * @return \TYPO3\CMS\Core\Resource\File
612 */
613 protected function func_move($cmds) {
614 if (!$this->isInit) {
615 return FALSE;
616 }
617 $sourceFileObject = $this->getFileObject($cmds['data']);
618 $targetFolderObject = $this->getFileObject($cmds['target']);
619 // Basic check
620 if (!$targetFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
621 $this->writelog(3, 2, 100, 'Destination "%s" was not a directory', array($cmds['target']));
622 return FALSE;
623 }
624 $alternativeName = (string) $cmds['altName'];
625 $resultObject = NULL;
626 // Moving the file
627 if ($sourceFileObject instanceof File) {
628 try {
629 if ($alternativeName !== '') {
630 // Don't allow overwriting existing files, but find a new name
631 $resultObject = $sourceFileObject->moveTo($targetFolderObject, $alternativeName, 'renameNewFile');
632 } else {
633 // Don't allow overwriting existing files
634 $resultObject = $sourceFileObject->moveTo($targetFolderObject, NULL, 'cancel');
635 }
636 $this->writelog(3, 0, 1, 'File "%s" moved to "%s"', array($sourceFileObject->getIdentifier(), $resultObject->getIdentifier()));
637 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
638 $this->writelog(3, 1, 114, 'You are not allowed to move files', '');
639 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
640 $this->writelog(3, 1, 110, 'Could not access all necessary resources. Source file or destination maybe was not within your mountpoints? T="%s", D="%s"', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
641 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
642 $this->writelog(3, 1, 111, 'Extension of file name "%s" is not allowed in "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
643 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
644 $this->writelog(3, 1, 112, 'File "%s" already exists in folder "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
645 } catch (\BadMethodCallException $e) {
646 $this->writelog(3, 1, 126, 'The function to move a file between storages is not yet implemented', array());
647 } catch (\RuntimeException $e) {
648 $this->writelog(3, 2, 109, 'File "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
649 }
650 } else {
651 // Else means this is a Folder
652 $sourceFolderObject = $sourceFileObject;
653 try {
654 if ($alternativeName !== '') {
655 // Don't allow overwriting existing files, but find a new name
656 $resultObject = $sourceFolderObject->moveTo($targetFolderObject, $alternativeName, 'renameNewFile');
657 } else {
658 // Don't allow overwriting existing files
659 $resultObject = $sourceFolderObject->moveTo($targetFolderObject, NULL, 'renameNewFile');
660 }
661 $this->writelog(3, 0, 2, 'Directory "%s" moved to "%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
662 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
663 $this->writelog(3, 1, 125, 'You are not allowed to move directories', '');
664 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
665 $this->writelog(3, 1, 110, 'Could not access all necessary resources. Source file or destination maybe was not within your mountpoints? T="%s", D="%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
666 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException $e) {
667 $this->writelog(3, 1, 121, 'You don\'t have full access to the destination directory "%s"!', array($targetFolderObject->getIdentifier()));
668 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException $e) {
669 $this->writelog(3, 1, 122, 'Destination cannot be inside the target! D="%s", T="%s"', array($targetFolderObject->getIdentifier(), $sourceFolderObject->getIdentifier()));
670 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException $e) {
671 $this->writelog(3, 1, 123, 'Target "%s" already exists!', array($targetFolderObject->getIdentifier()));
672 } catch (\BadMethodCallException $e) {
673 $this->writelog(3, 1, 127, 'The function to move a folder between storages is not yet implemented', array());
674 } catch (\RuntimeException $e) {
675 $this->writelog(3, 2, 119, 'Directory "%s" WAS NOT moved to "%s"! Write-permission problem?', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
676 }
677 }
678 return $resultObject;
679 }
680
681 /**
682 * Renaming files or foldes (action=5)
683 *
684 * $cmds['data'] (string): The file/folder to copy
685 * + example "4:mypath/tomyfolder/myfile.jpg")
686 * + for backwards compatibility: the identifier was the path+filename
687 * $cmds['target'] (string): New name of the file/folder
688 *
689 * @param array $cmds Command details as described above
690 * @return \TYPO3\CMS\Core\Resource\File Returns the new file upon success
691 * @todo Define visibility
692 */
693 public function func_rename($cmds) {
694 if (!$this->isInit) {
695 return FALSE;
696 }
697 $sourceFileObject = $this->getFileObject($cmds['data']);
698 $targetFile = $cmds['target'];
699 $resultObject = NULL;
700 if ($sourceFileObject instanceof File) {
701 try {
702 // Try to rename the File
703 $resultObject = $sourceFileObject->rename($targetFile);
704 $this->writelog(5, 0, 1, 'File renamed from "%s" to "%s"', array($sourceFileObject->getName(), $targetFile));
705 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
706 $this->writelog(5, 1, 102, 'You are not allowed to rename files!', '');
707 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
708 $this->writelog(5, 1, 101, 'Extension of file name "%s" or "%s" was not allowed!', array($sourceFileObject->getName(), $targetFile));
709 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
710 $this->writelog(5, 1, 120, 'Destination "%s" existed already!', array($targetFile));
711 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
712 $this->writelog(5, 1, 121, 'Destination path "%s" was not within your mountpoints!', array($targetFile));
713 } catch (\RuntimeException $e) {
714 $this->writelog(5, 1, 100, 'File "%s" was not renamed! Write-permission problem in "%s"?', array($sourceFileObject->getName(), $targetFile));
715 }
716 } else {
717 // Else means this is a Folder
718 try {
719 // Try to rename the Folder
720 $resultObject = $sourceFileObject->rename($targetFile);
721 $this->writelog(5, 0, 2, 'Directory renamed from "%s" to "%s"', array($sourceFileObject->getName(), $targetFile));
722 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
723 $this->writelog(5, 1, 111, 'You are not allowed to rename directories!', '');
724 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
725 $this->writelog(5, 1, 120, 'Destination "%s" existed already!', array($targetFile));
726 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
727 $this->writelog(5, 1, 121, 'Destination path "%s" was not within your mountpoints!', array($targetFile));
728 } catch (\RuntimeException $e) {
729 $this->writelog(5, 1, 110, 'Directory "%s" was not renamed! Write-permission problem in "%s"?', array($sourceFileObject->getName(), $targetFile));
730 }
731 }
732 return $resultObject;
733 }
734
735 /**
736 * This creates a new folder. (action=6)
737 *
738 * $cmds['data'] (string): The new folder name
739 * $cmds['target'] (string): The path where to copy to.
740 * + example "2:targetpath/targetfolder/"
741 *
742 * @param array $cmds Command details as described above
743 * @return \TYPO3\CMS\Core\Resource\Folder Returns the new foldername upon success
744 * @todo Define visibility
745 */
746 public function func_newfolder($cmds) {
747 if (!$this->isInit) {
748 return FALSE;
749 }
750 $targetFolderObject = $this->getFileObject($cmds['target']);
751 if (!$targetFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
752 $this->writelog(6, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
753 return FALSE;
754 }
755 $resultObject = NULL;
756 try {
757 $folderName = $cmds['data'];
758 $resultObject = $targetFolderObject->createFolder($folderName);
759 $this->writelog(6, 0, 1, 'Directory "%s" created in "%s"', array($folderName, $targetFolderObject->getIdentifier() . '/'));
760 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException $e) {
761 $this->writelog(6, 1, 103, 'You are not allowed to create directories!', '');
762 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
763 $this->writelog(6, 1, 102, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier() . '/'));
764 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException $e) {
765 $this->writelog(6, 1, 101, 'File or directory "%s" existed already!', array($folderName));
766 } catch (\RuntimeException $e) {
767 $this->writelog(6, 1, 100, 'Directory "%s" not created. Write-permission problem in "%s"?', array($folderName, $targetFolderObject->getIdentifier() . '/'));
768 }
769 return $resultObject;
770 }
771
772 /**
773 * This creates a new file. (action=8)
774 * $cmds['data'] (string): The new file name
775 * $cmds['target'] (string): The path where to create it.
776 * + example "2:targetpath/targetfolder/"
777 *
778 * @param array $cmds Command details as described above
779 * @return string Returns the new filename upon success
780 * @todo Define visibility
781 */
782 public function func_newfile($cmds) {
783 if (!$this->isInit) {
784 return FALSE;
785 }
786 $targetFolderObject = $this->getFileObject($cmds['target']);
787 if (!$targetFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
788 $this->writelog(8, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
789 return FALSE;
790 }
791 $resultObject = NULL;
792 try {
793 $fileName = $cmds['data'];
794 $resultObject = $targetFolderObject->createFile($fileName);
795 $this->writelog(8, 0, 1, 'File created: "%s"', array($fileName));
796 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
797 $this->writeLog(8, 1, 106, 'Extension of file "%s" was not allowed!', array($fileName));
798 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException $e) {
799 $this->writelog(8, 1, 103, 'You are not allowed to create files!', '');
800 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
801 $this->writelog(8, 1, 102, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier()));
802 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
803 $this->writelog(8, 1, 101, 'File existed already in "%s"!', array($targetFolderObject->getIdentifier()));
804 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException $e) {
805 $this->writelog(8, 1, 106, 'File name "%s" was not allowed!', $fileName);
806 } catch (\RuntimeException $e) {
807 $this->writelog(8, 1, 100, 'File "%s" was not created! Write-permission problem in "%s"?', array($fileName, $targetFolderObject->getIdentifier()));
808 }
809 return $resultObject;
810 }
811
812 /**
813 * Editing textfiles or folders (action=9)
814 *
815 * @param array $cmds $cmds['data'] is the new content. $cmds['target'] is the target (file or dir)
816 * @return boolean Returns TRUE on success
817 * @todo Define visibility
818 */
819 public function func_edit($cmds) {
820 if (!$this->isInit) {
821 return FALSE;
822 }
823 // Example indentifier for $cmds['target'] => "4:mypath/tomyfolder/myfile.jpg"
824 // for backwards compatibility: the combined file identifier was the path+filename
825 $fileIdentifier = $cmds['target'];
826 $fileObject = $this->getFileObject($fileIdentifier);
827 // Example indentifier for $cmds['target'] => "2:targetpath/targetfolder/"
828 $content = $cmds['data'];
829 if (!$fileObject instanceof File) {
830 $this->writelog(9, 2, 123, 'Target "%s" was not a file!', array($fileIdentifier));
831 return FALSE;
832 }
833 $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
834 if (!GeneralUtility::inList($extList, $fileObject->getExtension())) {
835 $this->writelog(9, 1, 102, 'File extension "%s" is not a textfile format! (%s)', array($fileObject->getExtension(), $extList));
836 return FALSE;
837 }
838 try {
839 $fileObject->setContents($content);
840 clearstatcache();
841 $this->writelog(9, 0, 1, 'File saved to "%s", bytes: %s, MD5: %s ', array($fileObject->getIdentifier(), $fileObject->getSize(), md5($content)));
842 return TRUE;
843 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
844 $this->writelog(9, 1, 104, 'You are not allowed to edit files!', '');
845 return FALSE;
846 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileWritePermissionsException $e) {
847 $this->writelog(9, 1, 100, 'File "%s" was not saved! Write-permission problem?', array($fileObject->getIdentifier()));
848 return FALSE;
849 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
850 $this->writelog(9, 1, 100, 'File "%s" was not saved! File extension rejected!', array($fileObject->getIdentifier()));
851 return FALSE;
852 }
853 }
854
855 /**
856 * Upload of files (action=1)
857 * when having multiple uploads (HTML5-style), the array $_FILES looks like this:
858 * Array(
859 * [upload_1] => Array(
860 * [name] => Array(
861 * [0] => GData - Content-Elements and Media-Gallery.pdf
862 * [1] => CMS Expo 2011.txt
863 * )
864 * [type] => Array(
865 * [0] => application/pdf
866 * [1] => text/plain
867 * )
868 * [tmp_name] => Array(
869 * [0] => /Applications/MAMP/tmp/php/phpNrOB43
870 * [1] => /Applications/MAMP/tmp/php/phpD2HQAK
871 * )
872 * [size] => Array(
873 * [0] => 373079
874 * [1] => 1291
875 * )
876 * )
877 * )
878 * in HTML you'd need sth like this: <input type="file" name="upload_1[]" multiple="true" />
879 *
880 * @param array $cmds $cmds['data'] is the ID-number (points to the global var that holds the filename-ref ($_FILES['upload_' . $id]['name']) . $cmds['target'] is the target directory, $cmds['charset'] is the the character set of the file name (utf-8 is needed for JS-interaction)
881 * @return string Returns the new filename upon success
882 * @todo Define visibility
883 */
884 public function func_upload($cmds) {
885 if (!$this->isInit) {
886 return FALSE;
887 }
888 $uploadPosition = $cmds['data'];
889 $uploadedFileData = $_FILES['upload_' . $uploadPosition];
890 if (empty($uploadedFileData['name']) || is_array($uploadedFileData['name']) && empty($uploadedFileData['name'][0])) {
891 $this->writelog(1, 2, 108, 'No file was uploaded!', '');
892 return FALSE;
893 }
894 // Example indentifier for $cmds['target'] => "2:targetpath/targetfolder/"
895 $targetFolderObject = $this->getFileObject($cmds['target']);
896 // Uploading with non HTML-5-style, thus, make an array out of it, so we can loop over it
897 if (!is_array($uploadedFileData['name'])) {
898 $uploadedFileData = array(
899 'name' => array($uploadedFileData['name']),
900 'type' => array($uploadedFileData['type']),
901 'tmp_name' => array($uploadedFileData['tmp_name']),
902 'size' => array($uploadedFileData['size'])
903 );
904 }
905 $resultObjects = array();
906 $numberOfUploadedFilesForPosition = count($uploadedFileData['name']);
907 // Loop through all uploaded files
908 for ($i = 0; $i < $numberOfUploadedFilesForPosition; $i++) {
909 $fileInfo = array(
910 'name' => $uploadedFileData['name'][$i],
911 'type' => $uploadedFileData['type'][$i],
912 'tmp_name' => $uploadedFileData['tmp_name'][$i],
913 'size' => $uploadedFileData['size'][$i]
914 );
915 try {
916 // @todo can be improved towards conflict mode naming
917 if ($this->dontCheckForUnique) {
918 $conflictMode = 'replace';
919 } else {
920 $conflictMode = 'cancel';
921 }
922 /** @var $fileObject File */
923 $fileObject = $targetFolderObject->addUploadedFile($fileInfo, $conflictMode);
924 $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObjectByStorageAndIdentifier($targetFolderObject->getStorage()->getUid(), $fileObject->getIdentifier());
925 if ($conflictMode === 'replace') {
926 $this->getIndexer($fileObject->getStorage())->updateIndexEntry($fileObject);
927 }
928 $resultObjects[] = $fileObject;
929 $this->writelog(1, 0, 1, 'Uploading file "%s" to "%s"', array($fileInfo['name'], $targetFolderObject->getIdentifier()));
930 } catch (\TYPO3\CMS\Core\Resource\Exception\UploadException $e) {
931 $this->writelog(1, 2, 106, 'The upload has failed, no uploaded file found!', '');
932 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
933 $this->writelog(1, 1, 105, 'You are not allowed to upload files!', '');
934 } catch (\TYPO3\CMS\Core\Resource\Exception\UploadSizeException $e) {
935 $this->writelog(1, 1, 104, 'The uploaded file "%s" exceeds the size-limit', array($fileInfo['name']));
936 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException $e) {
937 $this->writelog(1, 1, 103, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier()));
938 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
939 $this->writelog(1, 1, 102, 'Extension of file name "%s" is not allowed in "%s"!', array($fileInfo['name'], $targetFolderObject->getIdentifier()));
940 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
941 $this->writelog(1, 1, 101, 'No unique filename available in "%s"!', array($targetFolderObject->getIdentifier()));
942 } catch (\RuntimeException $e) {
943 $this->writelog(1, 1, 100, 'Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolderObject->getIdentifier()));
944 }
945 }
946
947 return $resultObjects;
948 }
949
950 /**
951 * Unzipping file (action=7)
952 * This is permitted only if the user has fullAccess or if the file resides
953 *
954 * @param array $cmds $cmds['data'] is the zip-file. $cmds['target'] is the target directory. If not set we'll default to the same directory as the file is in.
955 * @return boolean Returns TRUE on success
956 * @todo Define visibility
957 */
958 public function func_unzip($cmds) {
959 if (!$this->isInit || $this->dont_use_exec_commands) {
960 return FALSE;
961 }
962 $theFile = $cmds['data'];
963 if (!@is_file($theFile)) {
964 $this->writelog(7, 2, 105, 'The file "%s" did not exist!', array($theFile));
965 return FALSE;
966 }
967 $fI = GeneralUtility::split_fileref($theFile);
968 if (!isset($cmds['target'])) {
969 $cmds['target'] = $fI['path'];
970 }
971 // Clean up destination directory
972 // !!! Method has been put in the local driver, can be saftely removed
973 $theDest = $this->is_directory($cmds['target']);
974 if (!$theDest) {
975 $this->writelog(7, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
976 return FALSE;
977 }
978 if (!$this->actionPerms['unzipFile']) {
979 $this->writelog(7, 1, 103, 'You are not allowed to unzip files', '');
980 return FALSE;
981 }
982 if ($fI['fileext'] != 'zip') {
983 $this->writelog(7, 1, 102, 'File extension is not "zip"', '');
984 return FALSE;
985 }
986 if (!$this->checkIfFullAccess($theDest)) {
987 $this->writelog(7, 1, 101, 'You don\'t have full access to the destination directory "%s"!', array($theDest));
988 return FALSE;
989 }
990 // !!! Method has been put in the sotrage driver, can be saftely removed
991 if ($this->checkPathAgainstMounts($theFile) && $this->checkPathAgainstMounts($theDest . '/')) {
992 // No way to do this under windows.
993 $cmd = $this->unzipPath . 'unzip -qq ' . escapeshellarg($theFile) . ' -d ' . escapeshellarg($theDest);
994 \TYPO3\CMS\Core\Utility\CommandUtility::exec($cmd);
995 $this->writelog(7, 0, 1, 'Unzipping file "%s" in "%s"', array($theFile, $theDest));
996 return TRUE;
997 } else {
998 $this->writelog(7, 1, 100, 'File "%s" or destination "%s" was not within your mountpoints!', array($theFile, $theDest));
999 return FALSE;
1000 }
1001 }
1002
1003 /**
1004 * Add flash message to message queue
1005 *
1006 * @param \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage
1007 * @return void
1008 */
1009 protected function addFlashMessage(\TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage) {
1010 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
1011 $flashMessageService = GeneralUtility::makeInstance(
1012 'TYPO3\\CMS\\Core\\Messaging\\FlashMessageService'
1013 );
1014 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
1015 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
1016 $defaultFlashMessageQueue->enqueue($flashMessage);
1017 }
1018
1019 /**
1020 * Gets Indexer
1021 *
1022 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
1023 * @return \TYPO3\CMS\Core\Resource\Index\Indexer
1024 */
1025 protected function getIndexer(\TYPO3\CMS\Core\Resource\ResourceStorage $storage) {
1026 return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Index\\Indexer', $storage);
1027 }
1028
1029 /**
1030 * Get database connection
1031 *
1032 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
1033 */
1034 protected function getDatabaseConnection() {
1035 return $GLOBALS['TYPO3_DB'];
1036 }
1037
1038 /**
1039 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1040 */
1041 protected function getBackendUser() {
1042 return $GLOBALS['BE_USER'];
1043 }
1044
1045 }