aa56281242f6c8394bd9c617abc116c14e8063a7
[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 text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
31 use TYPO3\CMS\Core\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 * All error messages from the file operations of this script instance
133 *
134 * @var array
135 */
136 protected $errorMessages = array();
137
138 /**
139 * @var array
140 */
141 protected $fileCmdMap;
142
143 /**
144 * The File Factory
145 *
146 * @var \TYPO3\CMS\Core\Resource\ResourceFactory
147 */
148 protected $fileFactory;
149
150
151 /**
152 * Initialization of the class
153 *
154 * @param array $fileCmds Array with the commands to execute. See "TYPO3 Core API" document
155 * @return void
156 * @todo Define visibility
157 */
158 public function start($fileCmds) {
159 $unzipPath = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path']);
160 if (substr($unzipPath, -1) !== '/' && is_dir($unzipPath)) {
161 // Make sure the path ends with a slash
162 $unzipPath .= '/';
163 }
164 $this->unzipPath = $unzipPath;
165 // Initialize Object Factory
166 $this->fileFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
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 * @deprecated since TYPO3 6.1, will be removed two versions later, use ->pushErrorMessagesToFlashMessageQueue directly instead
282 */
283 public function printLogErrorMessages($redirect = '') {
284 GeneralUtility::logDeprecatedFunction();
285 $this->pushErrorMessagesToFlashMessageQueue();
286 }
287
288 /**
289 * Adds all log error messages from the operations of this script instance to the FlashMessageQueue
290 *
291 * @return void
292 */
293 public function pushErrorMessagesToFlashMessageQueue() {
294 foreach ($this->getErrorMessages() as $msg) {
295 $flashMessage = GeneralUtility::makeInstance(
296 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
297 $msg,
298 '',
299 \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
300 TRUE
301 );
302 $this->addFlashMessage($flashMessage);
303 }
304 }
305
306 /**
307 * Return all error messages from the file operations of this script instance
308 *
309 * @return array all errorMessages as a numerical array
310 */
311 public function getErrorMessages() {
312 return $this->errorMessages;
313 }
314
315 /**
316 * Goes back in the path and checks in each directory if a folder named $this->recyclerFN (usually '_recycler_') is present.
317 * 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
318 *
319 * @param string $theFile Takes a valid Path ($theFile)
320 * @return string Returns the path (without trailing slash) of the closest recycle-folder if found. Else FALSE.
321 * @todo To be put in Storage with a better concept
322 * @todo Define visibility
323 * @deprecated since TYPO3 6.0, use \TYPO3\CMS\Core\Resource\ResourceStorage method instead
324 */
325 public function findRecycler($theFile) {
326 GeneralUtility::logDeprecatedFunction();
327 if ($this->isPathValid($theFile)) {
328 $theFile = $this->cleanDirectoryName($theFile);
329 $fI = GeneralUtility::split_fileref($theFile);
330 $c = 0;
331 // !!! Method has been put in the storage, can be saftely removed
332 $rDir = $fI['path'] . $this->recyclerFN;
333 while ($this->checkPathAgainstMounts($fI['path']) && $c < 20) {
334 if (@is_dir($rDir) && $this->recyclerFN != $fI['file']) {
335 return $rDir;
336 }
337 $theFile = $fI['path'];
338 $theFile = $this->cleanDirectoryName($theFile);
339 $fI = GeneralUtility::split_fileref($theFile);
340 $c++;
341 }
342 }
343 }
344
345 /**
346 * Logging file operations
347 *
348 * @param integer $action The action number. See the functions in the class for a hint. Eg. edit is '9', upload is '1' ...
349 * @param integer $error The severity: 0 = message, 1 = error, 2 = System Error, 3 = security notice (admin)
350 * @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.
351 * @param string $details This is the default, raw error message in english
352 * @param array $data Array with special information that may go into $details by "%s" marks / sprintf() when the log is shown
353 * @return void
354 * @todo Define visibility
355 */
356 public function writeLog($action, $error, $details_nr, $details, $data) {
357 // Type value for tce_file.php
358 $type = 2;
359 if (is_object($this->getBackendUser())) {
360 $this->getBackendUser()->writelog($type, $action, $error, $details_nr, $details, $data);
361 }
362 if ($error > 0) {
363 $this->lastError = vsprintf($details, $data);
364 $this->errorMessages[] = $this->lastError;
365 }
366 }
367
368 /*************************************
369 *
370 * File operation functions
371 *
372 **************************************/
373 /**
374 * Deleting files and folders (action=4)
375 *
376 * @param array $cmds $cmds['data'] is the file/folder to delete
377 * @return boolean Returns TRUE upon success
378 * @todo Define visibility
379 */
380 public function func_delete($cmds) {
381 $result = FALSE;
382 if (!$this->isInit) {
383 return $result;
384 }
385 // Example indentifier for $cmds['data'] => "4:mypath/tomyfolder/myfile.jpg"
386 // for backwards compatibility: the combined file identifier was the path+filename
387 $fileObject = $this->getFileObject($cmds['data']);
388 // @todo implement the recycler feature which has been removed from the original implementation
389 // checks to delete the file
390 if ($fileObject instanceof File) {
391 // check if the file still has references
392 // Exclude sys_file_metadata records as these are no use references
393 $refIndexRecords = $this->getDatabaseConnection()->exec_SELECTgetRows(
394 '*',
395 'sys_refindex',
396 'deleted=0 AND ref_table="sys_file" AND ref_uid=' . intval($fileObject->getUid())
397 . ' AND tablename != "sys_file_metadata"'
398 );
399 if (count($refIndexRecords) > 0) {
400 $shortcutContent = array();
401 foreach ($refIndexRecords as $fileReferenceRow) {
402 if ($fileReferenceRow['tablename'] === 'sys_file_reference') {
403 $row = $this->transformFileReferenceToRecordReference($fileReferenceRow);
404 $shortcutRecord = BackendUtility::getRecord($row['tablename'], $row['recuid']);
405 $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord($row['tablename'], $shortcutRecord);
406 $onClick = 'Clickmenu.show("' . $row['tablename'] . '", "' . $row['recuid'] . '", "1", "+info,history,edit", "|", "");return false;';
407 $shortcutContent[] = '<a href="#" oncontextmenu="this.click();return false;" onclick="' . htmlspecialchars($onClick) . '">' . $icon . '</a>' . htmlspecialchars((BackendUtility::getRecordTitle($row['tablename'], $shortcutRecord) . ' [' . BackendUtility::getRecordPath($shortcutRecord['pid'], '', 80) . ']'));
408 }
409 }
410
411 // render a message that the file could not be deleted
412 $flashMessage = GeneralUtility::makeInstance(
413 '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
414 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileNotDeletedHasReferences'), $fileObject->getName()) . '<br />' . implode('<br />', $shortcutContent),
415 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileNotDeletedHasReferences'),
416 \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
417 TRUE
418 );
419 $this->addFlashMessage($flashMessage);
420 } else {
421 try {
422 $result = $fileObject->delete();
423
424 // show the user that the file was deleted
425 $flashMessage = GeneralUtility::makeInstance(
426 '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
427 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileDeleted'), $fileObject->getName()),
428 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileDeleted'),
429 \TYPO3\CMS\Core\Messaging\FlashMessage::OK,
430 TRUE
431 );
432 $this->addFlashMessage($flashMessage);
433 // Log success
434 $this->writelog(4, 0, 1, 'File "%s" deleted', array($fileObject->getIdentifier()));
435 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
436 $this->writelog(4, 1, 112, 'You are not allowed to access the file', array($fileObject->getIdentifier()));
437 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
438 $this->writelog(4, 1, 111, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
439 } catch (\RuntimeException $e) {
440 $this->writelog(4, 1, 110, 'Could not delete file "%s". Write-permission problem?', array($fileObject->getIdentifier()));
441 }
442 }
443 } else {
444 try {
445 /** @var $fileObject \TYPO3\CMS\Core\Resource\FolderInterface */
446 if ($fileObject->getFileCount() > 0) {
447 // render a message that the folder could not be deleted because it still contains files
448 $flashMessage = GeneralUtility::makeInstance(
449 '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
450 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderNotDeletedHasFiles'), $fileObject->getName()),
451 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderNotDeletedHasFiles'),
452 \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
453 TRUE
454 );
455 $this->addFlashMessage($flashMessage);
456 } else {
457 $result = $fileObject->delete(TRUE);
458
459 // notify the user that the folder was deleted
460 $flashMessage = GeneralUtility::makeInstance(
461 '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
462 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderDeleted'), $fileObject->getName()),
463 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderDeleted'),
464 \TYPO3\CMS\Core\Messaging\FlashMessage::OK,
465 TRUE
466 );
467 $this->addFlashMessage($flashMessage);
468 // Log success
469 $this->writelog(4, 0, 3, 'Directory "%s" deleted', array($fileObject->getIdentifier()));
470 }
471
472 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
473 $this->writelog(4, 1, 123, 'You are not allowed to access the directory', array($fileObject->getIdentifier()));
474 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
475 $this->writelog(4, 1, 121, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
476 } catch (\RuntimeException $e) {
477 $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()));
478 }
479 }
480 return $result;
481 }
482
483 /**
484 * Maps results from the fal file reference table on the
485 * structure of the normal reference index table.
486 *
487 * @param array $referenceRecord
488 * @return array
489 */
490 protected function transformFileReferenceToRecordReference(array $referenceRecord) {
491 $fileReference = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
492 '*',
493 'sys_file_reference',
494 'uid=' . (int)$referenceRecord['recuid']
495 );
496 return array(
497 'recuid' => $fileReference['uid_foreign'],
498 'tablename' => $fileReference['tablenames'],
499 'field' => $fileReference['fieldname'],
500 'flexpointer' => '',
501 'softref_key' => '',
502 'sorting' => $fileReference['sorting_foreign']
503 );
504 }
505
506 /**
507 * Gets a File or a Folder object from an identifier [storage]:[fileId]
508 *
509 * @param string $identifier
510 * @return \TYPO3\CMS\Core\Resource\Folder|\TYPO3\CMS\Core\Resource\File
511 * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidFileException
512 */
513 protected function getFileObject($identifier) {
514 $object = $this->fileFactory->retrieveFileOrFolderObject($identifier);
515 if (!is_object($object)) {
516 throw new \TYPO3\CMS\Core\Resource\Exception\InvalidFileException('The item ' . $identifier . ' was not a file or directory!!', 1320122453);
517 }
518 if ($object->getStorage()->getUid() === 0) {
519 throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889830);
520 }
521 return $object;
522 }
523
524 /**
525 * Copying files and folders (action=2)
526 *
527 * $cmds['data'] (string): The file/folder to copy
528 * + example "4:mypath/tomyfolder/myfile.jpg")
529 * + for backwards compatibility: the identifier was the path+filename
530 * $cmds['target'] (string): The path where to copy to.
531 * + example "2:targetpath/targetfolder/"
532 * $cmds['altName'] (string): Use an alternative name if the target already exists
533 *
534 * @param array $cmds Command details as described above
535 * @return \TYPO3\CMS\Core\Resource\File
536 */
537 protected function func_copy($cmds) {
538 if (!$this->isInit) {
539 return FALSE;
540 }
541 $sourceFileObject = $this->getFileObject($cmds['data']);
542 /** @var $targetFolderObject \TYPO3\CMS\Core\Resource\Folder */
543 $targetFolderObject = $this->getFileObject($cmds['target']);
544 // Basic check
545 if (!$targetFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
546 $this->writelog(2, 2, 100, 'Destination "%s" was not a directory', array($cmds['target']));
547 return FALSE;
548 }
549 // If this is TRUE, we append _XX to the file name if
550 $appendSuffixOnConflict = (string) $cmds['altName'];
551 $resultObject = NULL;
552 // Copying the file
553 if ($sourceFileObject instanceof File) {
554 try {
555 $conflictMode = $appendSuffixOnConflict !== '' ? 'renameNewFile' : 'cancel';
556 $resultObject = $sourceFileObject->copyTo($targetFolderObject, NULL, $conflictMode);
557 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
558 $this->writelog(2, 1, 114, 'You are not allowed to copy files', '');
559 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
560 $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()));
561 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
562 $this->writelog(2, 1, 111, 'Extension of file name "%s" is not allowed in "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
563 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
564 $this->writelog(2, 1, 112, 'File "%s" already exists in folder "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
565 } catch (\BadMethodCallException $e) {
566 $this->writelog(3, 1, 128, 'The function to copy a file between storages is not yet implemented', array());
567 } catch (\RuntimeException $e) {
568 $this->writelog(2, 2, 109, 'File "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
569 }
570 if ($resultObject) {
571 $this->writelog(2, 0, 1, 'File "%s" copied to "%s"', array($sourceFileObject->getIdentifier(), $resultObject->getIdentifier()));
572 }
573 } else {
574 // Else means this is a Folder
575 $sourceFolderObject = $sourceFileObject;
576 try {
577 $conflictMode = $appendSuffixOnConflict !== '' ? 'renameNewFile' : 'cancel';
578 $resultObject = $sourceFolderObject->copyTo($targetFolderObject, NULL, $conflictMode);
579 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
580 $this->writelog(2, 1, 125, 'You are not allowed to copy directories', '');
581 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
582 $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()));
583 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException $e) {
584 $this->writelog(2, 1, 121, 'You don\'t have full access to the destination directory "%s"!', array($targetFolderObject->getIdentifier()));
585 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException $e) {
586 $this->writelog(2, 1, 122, 'Destination cannot be inside the target! D="%s", T="%s"', array($targetFolderObject->getIdentifier(), $sourceFolderObject->getIdentifier()));
587 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException $e) {
588 $this->writelog(2, 1, 123, 'Target "%s" already exists!', array($targetFolderObject->getIdentifier()));
589 } catch (\BadMethodCallException $e) {
590 $this->writelog(3, 1, 129, 'The function to copy a folder between storages is not yet implemented', array());
591 } catch (\RuntimeException $e) {
592 $this->writelog(2, 2, 119, 'Directory "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
593 }
594 if ($resultObject) {
595 $this->writelog(2, 0, 2, 'Directory "%s" copied to "%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
596 }
597 }
598 return $resultObject;
599 }
600
601 /**
602 * Moving files and folders (action=3)
603 *
604 * $cmds['data'] (string): The file/folder to move
605 * + example "4:mypath/tomyfolder/myfile.jpg")
606 * + for backwards compatibility: the identifier was the path+filename
607 * $cmds['target'] (string): The path where to move to.
608 * + example "2:targetpath/targetfolder/"
609 * $cmds['altName'] (string): Use an alternative name if the target already exists
610 *
611 * @param array $cmds Command details as described above
612 * @return \TYPO3\CMS\Core\Resource\File
613 */
614 protected function func_move($cmds) {
615 if (!$this->isInit) {
616 return FALSE;
617 }
618 $sourceFileObject = $this->getFileObject($cmds['data']);
619 $targetFolderObject = $this->getFileObject($cmds['target']);
620 // Basic check
621 if (!$targetFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
622 $this->writelog(3, 2, 100, 'Destination "%s" was not a directory', array($cmds['target']));
623 return FALSE;
624 }
625 $alternativeName = (string) $cmds['altName'];
626 $resultObject = NULL;
627 // Moving the file
628 if ($sourceFileObject instanceof File) {
629 try {
630 if ($alternativeName !== '') {
631 // Don't allow overwriting existing files, but find a new name
632 $resultObject = $sourceFileObject->moveTo($targetFolderObject, $alternativeName, 'renameNewFile');
633 } else {
634 // Don't allow overwriting existing files
635 $resultObject = $sourceFileObject->moveTo($targetFolderObject, NULL, 'cancel');
636 }
637 $this->writelog(3, 0, 1, 'File "%s" moved to "%s"', array($sourceFileObject->getIdentifier(), $resultObject->getIdentifier()));
638 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
639 $this->writelog(3, 1, 114, 'You are not allowed to move files', '');
640 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
641 $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()));
642 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
643 $this->writelog(3, 1, 111, 'Extension of file name "%s" is not allowed in "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
644 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
645 $this->writelog(3, 1, 112, 'File "%s" already exists in folder "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
646 } catch (\BadMethodCallException $e) {
647 $this->writelog(3, 1, 126, 'The function to move a file between storages is not yet implemented', array());
648 } catch (\RuntimeException $e) {
649 $this->writelog(3, 2, 109, 'File "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
650 }
651 } else {
652 // Else means this is a Folder
653 $sourceFolderObject = $sourceFileObject;
654 try {
655 if ($alternativeName !== '') {
656 // Don't allow overwriting existing files, but find a new name
657 $resultObject = $sourceFolderObject->moveTo($targetFolderObject, $alternativeName, 'renameNewFile');
658 } else {
659 // Don't allow overwriting existing files
660 $resultObject = $sourceFolderObject->moveTo($targetFolderObject, NULL, 'renameNewFile');
661 }
662 $this->writelog(3, 0, 2, 'Directory "%s" moved to "%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
663 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
664 $this->writelog(3, 1, 125, 'You are not allowed to move directories', '');
665 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
666 $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()));
667 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException $e) {
668 $this->writelog(3, 1, 121, 'You don\'t have full access to the destination directory "%s"!', array($targetFolderObject->getIdentifier()));
669 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException $e) {
670 $this->writelog(3, 1, 122, 'Destination cannot be inside the target! D="%s", T="%s"', array($targetFolderObject->getIdentifier(), $sourceFolderObject->getIdentifier()));
671 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException $e) {
672 $this->writelog(3, 1, 123, 'Target "%s" already exists!', array($targetFolderObject->getIdentifier()));
673 } catch (\BadMethodCallException $e) {
674 $this->writelog(3, 1, 127, 'The function to move a folder between storages is not yet implemented', array());
675 } catch (\RuntimeException $e) {
676 $this->writelog(3, 2, 119, 'Directory "%s" WAS NOT moved to "%s"! Write-permission problem?', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
677 }
678 }
679 return $resultObject;
680 }
681
682 /**
683 * Renaming files or foldes (action=5)
684 *
685 * $cmds['data'] (string): The file/folder to copy
686 * + example "4:mypath/tomyfolder/myfile.jpg")
687 * + for backwards compatibility: the identifier was the path+filename
688 * $cmds['target'] (string): New name of the file/folder
689 *
690 * @param array $cmds Command details as described above
691 * @return \TYPO3\CMS\Core\Resource\File Returns the new file upon success
692 * @todo Define visibility
693 */
694 public function func_rename($cmds) {
695 if (!$this->isInit) {
696 return FALSE;
697 }
698 $sourceFileObject = $this->getFileObject($cmds['data']);
699 $targetFile = $cmds['target'];
700 $resultObject = NULL;
701 if ($sourceFileObject instanceof File) {
702 try {
703 // Try to rename the File
704 $resultObject = $sourceFileObject->rename($targetFile);
705 $this->writelog(5, 0, 1, 'File renamed from "%s" to "%s"', array($sourceFileObject->getName(), $targetFile));
706 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
707 $this->writelog(5, 1, 102, 'You are not allowed to rename files!', '');
708 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
709 $this->writelog(5, 1, 101, 'Extension of file name "%s" or "%s" was not allowed!', array($sourceFileObject->getName(), $targetFile));
710 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
711 $this->writelog(5, 1, 120, 'Destination "%s" existed already!', array($targetFile));
712 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
713 $this->writelog(5, 1, 121, 'Destination path "%s" was not within your mountpoints!', array($targetFile));
714 } catch (\RuntimeException $e) {
715 $this->writelog(5, 1, 100, 'File "%s" was not renamed! Write-permission problem in "%s"?', array($sourceFileObject->getName(), $targetFile));
716 }
717 } else {
718 // Else means this is a Folder
719 try {
720 // Try to rename the Folder
721 $resultObject = $sourceFileObject->rename($targetFile);
722 $this->writelog(5, 0, 2, 'Directory renamed from "%s" to "%s"', array($sourceFileObject->getName(), $targetFile));
723 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
724 $this->writelog(5, 1, 111, 'You are not allowed to rename directories!', '');
725 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
726 $this->writelog(5, 1, 120, 'Destination "%s" existed already!', array($targetFile));
727 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
728 $this->writelog(5, 1, 121, 'Destination path "%s" was not within your mountpoints!', array($targetFile));
729 } catch (\RuntimeException $e) {
730 $this->writelog(5, 1, 110, 'Directory "%s" was not renamed! Write-permission problem in "%s"?', array($sourceFileObject->getName(), $targetFile));
731 }
732 }
733 return $resultObject;
734 }
735
736 /**
737 * This creates a new folder. (action=6)
738 *
739 * $cmds['data'] (string): The new folder name
740 * $cmds['target'] (string): The path where to copy to.
741 * + example "2:targetpath/targetfolder/"
742 *
743 * @param array $cmds Command details as described above
744 * @return \TYPO3\CMS\Core\Resource\Folder Returns the new foldername upon success
745 * @todo Define visibility
746 */
747 public function func_newfolder($cmds) {
748 if (!$this->isInit) {
749 return FALSE;
750 }
751 $targetFolderObject = $this->getFileObject($cmds['target']);
752 if (!$targetFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
753 $this->writelog(6, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
754 return FALSE;
755 }
756 $resultObject = NULL;
757 try {
758 $folderName = $cmds['data'];
759 $resultObject = $targetFolderObject->createFolder($folderName);
760 $this->writelog(6, 0, 1, 'Directory "%s" created in "%s"', array($folderName, $targetFolderObject->getIdentifier() . '/'));
761 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException $e) {
762 $this->writelog(6, 1, 103, 'You are not allowed to create directories!', '');
763 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
764 $this->writelog(6, 1, 102, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier() . '/'));
765 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException $e) {
766 $this->writelog(6, 1, 101, 'File or directory "%s" existed already!', array($folderName));
767 } catch (\RuntimeException $e) {
768 $this->writelog(6, 1, 100, 'Directory "%s" not created. Write-permission problem in "%s"?', array($folderName, $targetFolderObject->getIdentifier() . '/'));
769 }
770 return $resultObject;
771 }
772
773 /**
774 * This creates a new file. (action=8)
775 * $cmds['data'] (string): The new file name
776 * $cmds['target'] (string): The path where to create it.
777 * + example "2:targetpath/targetfolder/"
778 *
779 * @param array $cmds Command details as described above
780 * @return string Returns the new filename upon success
781 * @todo Define visibility
782 */
783 public function func_newfile($cmds) {
784 if (!$this->isInit) {
785 return FALSE;
786 }
787 $targetFolderObject = $this->getFileObject($cmds['target']);
788 if (!$targetFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
789 $this->writelog(8, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
790 return FALSE;
791 }
792 $resultObject = NULL;
793 try {
794 $fileName = $cmds['data'];
795 $resultObject = $targetFolderObject->createFile($fileName);
796 $this->writelog(8, 0, 1, 'File created: "%s"', array($fileName));
797 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
798 $this->writeLog(8, 1, 106, 'Extension of file "%s" was not allowed!', array($fileName));
799 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException $e) {
800 $this->writelog(8, 1, 103, 'You are not allowed to create files!', '');
801 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
802 $this->writelog(8, 1, 102, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier()));
803 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
804 $this->writelog(8, 1, 101, 'File existed already in "%s"!', array($targetFolderObject->getIdentifier()));
805 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException $e) {
806 $this->writelog(8, 1, 106, 'File name "%s" was not allowed!', $fileName);
807 } catch (\RuntimeException $e) {
808 $this->writelog(8, 1, 100, 'File "%s" was not created! Write-permission problem in "%s"?', array($fileName, $targetFolderObject->getIdentifier()));
809 }
810 return $resultObject;
811 }
812
813 /**
814 * Editing textfiles or folders (action=9)
815 *
816 * @param array $cmds $cmds['data'] is the new content. $cmds['target'] is the target (file or dir)
817 * @return boolean Returns TRUE on success
818 * @todo Define visibility
819 */
820 public function func_edit($cmds) {
821 if (!$this->isInit) {
822 return FALSE;
823 }
824 // Example indentifier for $cmds['target'] => "4:mypath/tomyfolder/myfile.jpg"
825 // for backwards compatibility: the combined file identifier was the path+filename
826 $fileIdentifier = $cmds['target'];
827 $fileObject = $this->getFileObject($fileIdentifier);
828 // Example indentifier for $cmds['target'] => "2:targetpath/targetfolder/"
829 $content = $cmds['data'];
830 if (!$fileObject instanceof File) {
831 $this->writelog(9, 2, 123, 'Target "%s" was not a file!', array($fileIdentifier));
832 return FALSE;
833 }
834 $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
835 if (!GeneralUtility::inList($extList, $fileObject->getExtension())) {
836 $this->writelog(9, 1, 102, 'File extension "%s" is not a textfile format! (%s)', array($fileObject->getExtension(), $extList));
837 return FALSE;
838 }
839 try {
840 $fileObject->setContents($content);
841 clearstatcache();
842 $this->writelog(9, 0, 1, 'File saved to "%s", bytes: %s, MD5: %s ', array($fileObject->getIdentifier(), $fileObject->getSize(), md5($content)));
843 return TRUE;
844 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
845 $this->writelog(9, 1, 104, 'You are not allowed to edit files!', '');
846 return FALSE;
847 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileWritePermissionsException $e) {
848 $this->writelog(9, 1, 100, 'File "%s" was not saved! Write-permission problem?', array($fileObject->getIdentifier()));
849 return FALSE;
850 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
851 $this->writelog(9, 1, 100, 'File "%s" was not saved! File extension rejected!', array($fileObject->getIdentifier()));
852 return FALSE;
853 }
854 }
855
856 /**
857 * Upload of files (action=1)
858 * when having multiple uploads (HTML5-style), the array $_FILES looks like this:
859 * Array(
860 * [upload_1] => Array(
861 * [name] => Array(
862 * [0] => GData - Content-Elements and Media-Gallery.pdf
863 * [1] => CMS Expo 2011.txt
864 * )
865 * [type] => Array(
866 * [0] => application/pdf
867 * [1] => text/plain
868 * )
869 * [tmp_name] => Array(
870 * [0] => /Applications/MAMP/tmp/php/phpNrOB43
871 * [1] => /Applications/MAMP/tmp/php/phpD2HQAK
872 * )
873 * [size] => Array(
874 * [0] => 373079
875 * [1] => 1291
876 * )
877 * )
878 * )
879 * in HTML you'd need sth like this: <input type="file" name="upload_1[]" multiple="true" />
880 *
881 * @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)
882 * @return File[] | FALSE Returns an array of new file objects upon success. False otherwise
883 * @todo Define visibility
884 */
885 public function func_upload($cmds) {
886 if (!$this->isInit) {
887 return FALSE;
888 }
889 $uploadPosition = $cmds['data'];
890 $uploadedFileData = $_FILES['upload_' . $uploadPosition];
891 if (empty($uploadedFileData['name']) || is_array($uploadedFileData['name']) && empty($uploadedFileData['name'][0])) {
892 $this->writelog(1, 2, 108, 'No file was uploaded!', '');
893 return FALSE;
894 }
895 // Example indentifier for $cmds['target'] => "2:targetpath/targetfolder/"
896 $targetFolderObject = $this->getFileObject($cmds['target']);
897 // Uploading with non HTML-5-style, thus, make an array out of it, so we can loop over it
898 if (!is_array($uploadedFileData['name'])) {
899 $uploadedFileData = array(
900 'name' => array($uploadedFileData['name']),
901 'type' => array($uploadedFileData['type']),
902 'tmp_name' => array($uploadedFileData['tmp_name']),
903 'size' => array($uploadedFileData['size'])
904 );
905 }
906 $resultObjects = array();
907 $numberOfUploadedFilesForPosition = count($uploadedFileData['name']);
908 // Loop through all uploaded files
909 for ($i = 0; $i < $numberOfUploadedFilesForPosition; $i++) {
910 $fileInfo = array(
911 'name' => $uploadedFileData['name'][$i],
912 'type' => $uploadedFileData['type'][$i],
913 'tmp_name' => $uploadedFileData['tmp_name'][$i],
914 'size' => $uploadedFileData['size'][$i]
915 );
916 try {
917 // @todo can be improved towards conflict mode naming
918 if ($this->dontCheckForUnique) {
919 $conflictMode = 'replace';
920 } else {
921 $conflictMode = 'cancel';
922 }
923 /** @var $fileObject File */
924 $fileObject = $targetFolderObject->addUploadedFile($fileInfo, $conflictMode);
925 $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObjectByStorageAndIdentifier($targetFolderObject->getStorage()->getUid(), $fileObject->getIdentifier());
926 if ($conflictMode === 'replace') {
927 $this->getIndexer($fileObject->getStorage())->updateIndexEntry($fileObject);
928 }
929 $resultObjects[] = $fileObject;
930 $this->writelog(1, 0, 1, 'Uploading file "%s" to "%s"', array($fileInfo['name'], $targetFolderObject->getIdentifier()));
931 } catch (\TYPO3\CMS\Core\Resource\Exception\UploadException $e) {
932 $this->writelog(1, 2, 106, 'The upload has failed, no uploaded file found!', '');
933 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
934 $this->writelog(1, 1, 105, 'You are not allowed to upload files!', '');
935 } catch (\TYPO3\CMS\Core\Resource\Exception\UploadSizeException $e) {
936 $this->writelog(1, 1, 104, 'The uploaded file "%s" exceeds the size-limit', array($fileInfo['name']));
937 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException $e) {
938 $this->writelog(1, 1, 103, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier()));
939 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
940 $this->writelog(1, 1, 102, 'Extension of file name "%s" is not allowed in "%s"!', array($fileInfo['name'], $targetFolderObject->getIdentifier()));
941 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
942 $this->writelog(1, 1, 101, 'No unique filename available in "%s"!', array($targetFolderObject->getIdentifier()));
943 } catch (\RuntimeException $e) {
944 $this->writelog(1, 1, 100, 'Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolderObject->getIdentifier()));
945 }
946 }
947
948 return $resultObjects;
949 }
950
951 /**
952 * Unzipping file (action=7)
953 * This is permitted only if the user has fullAccess or if the file resides
954 *
955 * @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.
956 * @return boolean Returns TRUE on success
957 * @todo Define visibility
958 */
959 public function func_unzip($cmds) {
960 if (!$this->isInit || $this->dont_use_exec_commands) {
961 return FALSE;
962 }
963 $theFile = $cmds['data'];
964 if (!@is_file($theFile)) {
965 $this->writelog(7, 2, 105, 'The file "%s" did not exist!', array($theFile));
966 return FALSE;
967 }
968 $fI = GeneralUtility::split_fileref($theFile);
969 if (!isset($cmds['target'])) {
970 $cmds['target'] = $fI['path'];
971 }
972 // Clean up destination directory
973 // !!! Method has been put in the local driver, can be saftely removed
974 $theDest = $this->is_directory($cmds['target']);
975 if (!$theDest) {
976 $this->writelog(7, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
977 return FALSE;
978 }
979 if (!$this->actionPerms['unzipFile']) {
980 $this->writelog(7, 1, 103, 'You are not allowed to unzip files', '');
981 return FALSE;
982 }
983 if ($fI['fileext'] != 'zip') {
984 $this->writelog(7, 1, 102, 'File extension is not "zip"', '');
985 return FALSE;
986 }
987 if (!$this->checkIfFullAccess($theDest)) {
988 $this->writelog(7, 1, 101, 'You don\'t have full access to the destination directory "%s"!', array($theDest));
989 return FALSE;
990 }
991 // !!! Method has been put in the sotrage driver, can be saftely removed
992 if ($this->checkPathAgainstMounts($theFile) && $this->checkPathAgainstMounts($theDest . '/')) {
993 // No way to do this under windows.
994 $cmd = $this->unzipPath . 'unzip -qq ' . escapeshellarg($theFile) . ' -d ' . escapeshellarg($theDest);
995 \TYPO3\CMS\Core\Utility\CommandUtility::exec($cmd);
996 $this->writelog(7, 0, 1, 'Unzipping file "%s" in "%s"', array($theFile, $theDest));
997 return TRUE;
998 } else {
999 $this->writelog(7, 1, 100, 'File "%s" or destination "%s" was not within your mountpoints!', array($theFile, $theDest));
1000 return FALSE;
1001 }
1002 }
1003
1004 /**
1005 * Add flash message to message queue
1006 *
1007 * @param \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage
1008 * @return void
1009 */
1010 protected function addFlashMessage(\TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage) {
1011 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
1012 $flashMessageService = GeneralUtility::makeInstance(
1013 'TYPO3\\CMS\\Core\\Messaging\\FlashMessageService'
1014 );
1015 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
1016 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
1017 $defaultFlashMessageQueue->enqueue($flashMessage);
1018 }
1019
1020 /**
1021 * Gets Indexer
1022 *
1023 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
1024 * @return \TYPO3\CMS\Core\Resource\Index\Indexer
1025 */
1026 protected function getIndexer(\TYPO3\CMS\Core\Resource\ResourceStorage $storage) {
1027 return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Index\\Indexer', $storage);
1028 }
1029
1030 /**
1031 * Get database connection
1032 *
1033 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
1034 */
1035 protected function getDatabaseConnection() {
1036 return $GLOBALS['TYPO3_DB'];
1037 }
1038
1039 /**
1040 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1041 */
1042 protected function getBackendUser() {
1043 return $GLOBALS['BE_USER'];
1044 }
1045
1046 }