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