Пример #1
0
 /**
  * @test
  */
 public function flattenResultDataValueFlattensFileAndFolderResourcesButReturnsAnythingElseAsIs()
 {
     $this->fileController = $this->getAccessibleMock('TYPO3\\CMS\\Backend\\Controller\\File\\FileController', array('dummy'));
     $this->folderResourceMock->expects($this->once())->method('getIdentifier')->will($this->returnValue('bar'));
     $this->mockFileProcessor->expects($this->any())->method('getErrorMessages')->will($this->returnValue(array()));
     $this->assertTrue($this->fileController->_call('flattenResultDataValue', TRUE));
     $this->assertSame(array(), $this->fileController->_call('flattenResultDataValue', array()));
     $this->assertSame(array('id' => 'foo', 'date' => '29-11-73', 'iconClasses' => 't3-icon t3-icon-mimetypes t3-icon-mimetypes-text t3-icon-text-html'), $this->fileController->_call('flattenResultDataValue', $this->fileResourceMock));
     $this->assertSame('bar', $this->fileController->_call('flattenResultDataValue', $this->folderResourceMock));
 }
Пример #2
0
 /**
  * @test
  */
 public function flattenResultDataValueFlattensFileAndFolderResourcesButReturnsAnythingElseAsIs()
 {
     $this->fileController = $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController::class, array('dummy'));
     $this->folderResourceMock->expects($this->once())->method('getIdentifier')->will($this->returnValue('bar'));
     $this->mockFileProcessor->expects($this->any())->method('getErrorMessages')->will($this->returnValue(array()));
     $this->assertTrue($this->fileController->_call('flattenResultDataValue', true));
     $this->assertSame(array(), $this->fileController->_call('flattenResultDataValue', array()));
     $result = $this->fileController->_call('flattenResultDataValue', $this->fileResourceMock);
     $this->assertContains('<span class="t3js-icon icon icon-size-small icon-state-default icon-mimetypes-text-html" data-identifier="mimetypes-text-html">', $result['icon']);
     unset($result['icon']);
     $this->assertSame(array('id' => 'foo', 'date' => '29-11-73', 'thumbUrl' => ''), $result);
     $this->assertSame('bar', $this->fileController->_call('flattenResultDataValue', $this->folderResourceMock));
 }
Пример #3
0
 /**
  * Checks if a file has been uploaded. If so, create a File object and return it.
  *
  * @return File|NULL
  */
 protected function checkUpload()
 {
     $file = GeneralUtility::_GP('file');
     // Initializing:
     $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility');
     $this->fileProcessor->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
     $this->fileProcessor->setActionPermissions();
     $this->fileProcessor->dontCheckForUnique = $this->inData['preset']['overwriteExistingFiles'] ? 1 : 0;
     /** @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $backendUserAuthentication */
     $backendUserAuthentication = $this->getBackendUserAuthentication();
     $userTemporaryDirectory = $backendUserAuthentication->getDefaultUploadTemporaryFolder();
     $storageUid = $userTemporaryDirectory->getStorage()->getUid();
     $file['upload']['1']['target'] = $storageUid . ':' . $userTemporaryDirectory->getIdentifier();
     // Checking referer / executing:
     $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER'));
     $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
     if ($httpHost != $refInfo['host'] && $this->vC != $this->getBackendUserAuthentication()->veriCode() && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) {
         $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
     } else {
         $this->fileProcessor->start($file);
         /** @var array<\TYPO3\CMS\Core\Resource\File> $newfile */
         $newFiles = $this->fileProcessor->func_upload($file['upload']['1']);
     }
     if ($newFiles[0] instanceof File) {
         return $newFiles[0];
     } else {
         if (!empty($this->fileProcessor->lastError) && GeneralUtility::isFirstPartOfStr($this->fileProcessor->lastError, 'No unique filename')) {
             /** @var $flashMessage FlashMessage */
             $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('f1.tab1.section.importFile.noUniqueFilename'), '', FlashMessage::WARNING);
             return $flashMessage->render();
         } else {
             return null;
         }
     }
 }
Пример #4
0
 /**
  * Handles the actual process from within the ajaxExec function
  * therefore, it does exactly the same as the real typo3/tce_file.php
  * but without calling the "finish" method, thus makes it simpler to deal with the
  * actual return value
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @return ResponseInterface
  */
 public function processAjaxRequest(ServerRequestInterface $request, ResponseInterface $response)
 {
     $this->main();
     $errors = $this->fileProcessor->getErrorMessages();
     if (!empty($errors)) {
         $response->getBody()->write(implode(',', $errors));
         $response = $response->withHeader('Content-Type', 'text/html; charset=utf-8');
     } else {
         $flatResult = array();
         foreach ($this->fileData as $action => $results) {
             foreach ($results as $result) {
                 if (is_array($result)) {
                     foreach ($result as $subResult) {
                         $flatResult[$action][] = $this->flattenResultDataValue($subResult);
                     }
                 } else {
                     $flatResult[$action][] = $this->flattenResultDataValue($result);
                 }
             }
         }
         $content = ['result' => $flatResult];
         if ($this->redirect) {
             $content['redirect'] = $this->redirect;
         }
         $response->getBody()->write(json_encode($content));
     }
     return $response;
 }
Пример #5
0
 /**
  * Handles the actual process from within the ajaxExec function
  * therefore, it does exactly the same as the real typo3/tce_file.php
  * but without calling the "finish" method, thus makes it simpler to deal with the
  * actual return value
  *
  * @param array $params Always empty.
  * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj The AjaxRequestHandler object used to return content and set content types
  * @return void
  */
 public function processAjaxRequest(array $params, \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj)
 {
     $this->init();
     $this->main();
     $errors = $this->fileProcessor->getErrorMessages();
     if (!empty($errors)) {
         $ajaxObj->setError(implode(',', $errors));
     } else {
         $flatResult = array();
         foreach ($this->fileData as $action => $results) {
             foreach ($results as $result) {
                 if (is_array($result)) {
                     foreach ($result as $subResult) {
                         $flatResult[$action][] = $this->flattenResultDataValue($subResult);
                     }
                 } else {
                     $flatResult[$action][] = $this->flattenResultDataValue($result);
                 }
             }
         }
         $ajaxObj->addContent('result', $flatResult);
         if ($this->redirect) {
             $ajaxObj->addContent('redirect', $this->redirect);
         }
         $ajaxObj->setContentFormat('json');
     }
 }
Пример #6
0
 /**
  * Returns file processing object, initialized only once.
  *
  * @return ExtendedFileUtility File processor object
  */
 public function getFileProcObj()
 {
     if (!is_object($this->fileProcObj)) {
         $this->fileProcObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ExtendedFileUtility::class);
         $this->fileProcObj->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
         $this->fileProcObj->setActionPermissions();
     }
     return $this->fileProcObj;
 }
 /**
  * @test
  */
 public function copyFolderInLocalStorage()
 {
     // Computes a $folderIdentifier which looks like 8:/folderName.txt where 8 is the storage Uid
     $storage = $this->getDefaultStorage();
     $folderIdentifier = $storage->getUid() . ':/' . $this->copyFolderNameInput;
     $targetFolder = $this->getRootFolderIdentifier() . $this->newFolderNameInput;
     // Defines values
     $fileValues = array('newfolder' => array(array('data' => $this->newFolderNameInput, 'target' => $this->getRootFolderIdentifier()), array('data' => $this->copyFolderNameInput, 'target' => $this->getRootFolderIdentifier())), 'copy' => array(array('data' => $folderIdentifier, 'target' => $targetFolder)));
     $this->fileProcessor->start($fileValues);
     $results = $this->fileProcessor->processData();
     $folderObject = NULL;
     if (!empty($results['copy'][0])) {
         $folderObject = $results['copy'][0];
     }
     // remove parent folder
     if (!empty($results['newfolder'][0])) {
         $this->objectsToTearDown[] = $results['newfolder'][0];
     }
     if (!empty($results['newfolder'][1])) {
         $this->objectsToTearDown[] = $results['newfolder'][1];
     }
     $this->assertEquals(TRUE, $folderObject instanceof \TYPO3\CMS\Core\Resource\Folder);
 }
Пример #8
0
 /**
  * Checks if a file has been uploaded and returns the complete physical fileinfo if so.
  *
  * @return	string		the complete physical file name, including path info.
  */
 public function checkUpload()
 {
     $file = GeneralUtility::_GP('file');
     $fm = array();
     $tempFolder = $this->userTempFolder();
     $fm = array($GLOBALS['EXEC_TIME'] => array('path' => $tempFolder, 'name' => array_pop(explode('/', trim($tempFolder, '/'))) . '/'));
     // Initializing:
     /* @var $fileProcessor \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility */
     $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility');
     $this->fileProcessor->init($fm, $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
     $this->fileProcessor->setActionPermissions();
     $this->fileProcessor->dontCheckForUnique = 1;
     // Checking referer / executing:
     $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER'));
     $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
     if ($httpHost != $refInfo['host'] && $this->vC != $GLOBALS['BE_USER']->veriCode() && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) {
         $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
     } else {
         $this->fileProcessor->start($file);
         $newfile = $this->fileProcessor->func_upload($file['upload']['1']);
     }
     return $newfile;
 }
 /**
  * Check if a file has been uploaded
  *
  * @throws \InvalidArgumentException
  * @throws \UnexpectedValueException
  * @return void
  */
 public function checkUpload()
 {
     $file = GeneralUtility::_GP('file');
     // Initializing:
     $this->fileProcessor = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::class);
     $this->fileProcessor->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
     $this->fileProcessor->setActionPermissions();
     $this->fileProcessor->setExistingFilesConflictMode((int) GeneralUtility::_GP('overwriteExistingFiles') === 1 ? DuplicationBehavior::REPLACE : DuplicationBehavior::CANCEL);
     // Checking referer / executing:
     $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER'));
     $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
     if ($httpHost != $refInfo['host'] && !$GLOBALS['$TYPO3_CONF_VARS']['SYS']['doNotCheckReferer'] && $this->vC != $this->getBackendUser()->veriCode()) {
         $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
     } else {
         $this->fileProcessor->start($file);
         $result = $this->fileProcessor->processData();
         if (!empty($result['upload'])) {
             foreach ($result['upload'] as $uploadedFiles) {
                 $this->uploadedFiles += $uploadedFiles;
             }
         }
     }
 }
Пример #10
0
 /**
  * Returns file processing object, initialized only once.
  *
  * @return object File processor object
  * @todo Define visibility
  */
 public function getFileProcObj()
 {
     if (!is_object($this->fileProcObj)) {
         $this->fileProcObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility');
         $this->fileProcObj->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
         $this->fileProcObj->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
     }
     return $this->fileProcObj;
 }
Пример #11
0
 /**
  * Returns file processing object, initialized only once.
  *
  * @return ExtendedFileUtility File processor object
  */
 public function getFileProcObj()
 {
     if ($this->fileProcObj === null) {
         $this->fileProcObj = GeneralUtility::makeInstance(ExtendedFileUtility::class);
         $this->fileProcObj->setActionPermissions();
     }
     return $this->fileProcObj;
 }
Пример #12
0
 /**
  * Returns file processing object, initialized only once.
  *
  * @return object File processor object
  * @todo Define visibility
  */
 public function getFileProcObj()
 {
     if ($this->fileProcObj === NULL) {
         $this->fileProcObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility');
         $this->fileProcObj->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
         $this->fileProcObj->setActionPermissions();
     }
     return $this->fileProcObj;
 }