예제 #1
0
 /**
  * Write CSV Data to a temporary file and will be used for the import
  *
  * @return	string		path of the temp file
  */
 public function writeTempFile()
 {
     $newfile = "";
     $userPermissions = $GLOBALS['BE_USER']->getFilePermissions();
     unset($this->fileProcessor);
     // add uploads/tx_directmail to user filemounts
     $GLOBALS['FILEMOUNTS']['tx_directmail'] = array('name' => 'direct_mail', 'path' => GeneralUtility::getFileAbsFileName('uploads/tx_directmail/'), 'type');
     // Initializing:
     /* @var $fileProcessor \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility */
     $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility');
     $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
     $this->fileProcessor->setActionPermissions($userPermissions);
     $this->fileProcessor->dontCheckForUnique = 1;
     if (is_array($GLOBALS['FILEMOUNTS']) && !empty($GLOBALS['FILEMOUNTS'])) {
         // we have a filemount
         // do something here
     } else {
         // we don't have a valid file mount
         // should be fixed
         // this throws a error message because we have no rights to upload files
         // to our extension's own upload folder
         // further investigation needed
         $file['upload']['1']['target'] = GeneralUtility::getFileAbsFileName('uploads/tx_directmail/');
     }
     // Checking referer / executing:
     $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER'));
     $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
     if (empty($this->indata['newFile'])) {
         // new file
         $file['newfile']['1']['target'] = $this->userTempFolder();
         $file['newfile']['1']['data'] = 'import_' . $GLOBALS['EXEC_TIME'] . '.txt';
         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);
             $newfileObj = $this->fileProcessor->func_newfile($file['newfile']['1']);
             // in TYPO3 6.0 func_newfile returns an object, but we need the path to the new file name later on!
             if (is_object($newfileObj)) {
                 $storageConfig = $newfileObj->getStorage()->getConfiguration();
                 $newfile = $storageConfig['basePath'] . ltrim($newfileObj->getIdentifier(), '/');
             }
         }
     } else {
         $newfile = $this->indata['newFile'];
     }
     if ($newfile) {
         $csvFile['data'] = $this->indata['csv'];
         $csvFile['target'] = $newfile;
         $write = $this->fileProcessor->func_edit($csvFile);
     }
     return $newfile;
 }