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