/** * action feeditAction * Bearbeiten eines bestehenden Datensatzes aus fremder Tabelle starten. * Dazu Kopie in tx_nnfesubmit_domain_model_entry anlegen und zum Formular weiterleiten * * @return array */ public function feeditAction($params) { $this->settings = $this->settingsUtility->getSettings(); $uid = intval($params['uid']); $type = $params['type']; $settings = $this->settings[$type]; $extName = $settings['extension']; // Prüfen, ob Datensatz in fremder Tabelle exisitert if (!($data = $this->tableService->getEntry($settings, $uid))) { return $this->anyHelper->addFlashMessage('Kein Eintrag gefunden', "In der Tabelle {$settings['tablename']} wurde kein Datensatz mit der uid={$uid} gefunden.", 'ERROR'); } // Datensatz zum Bearbeiten anlegen if (!($entry = $this->entryRepository->getEntryForExt($uid, $type))) { $entry = $this->objectManager->get('\\Nng\\Nnfesubmit\\Domain\\Model\\Entry'); $this->entryRepository->add($entry); $this->persistenceManager->persistAll(); //$unique_filename = $this->basicFileFunctions->getUniqueName($file, 'uploads/tx_nnfesubmit/'); //if (\TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move($files['tmp_name'][$k], $unique_filename)) { } // Media zurück in den Ordner uploads/tx_nnfesubmit kopieren $media = $settings['media']; foreach ($media as $k => $path) { if ($data[$k]) { $unique_filename = $this->basicFileFunctions->getUniqueName(trim(basename($data[$k])), 'uploads/tx_nnfesubmit/'); \TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move($path . $data[$k], $unique_filename); if (!file_exists($unique_filename)) { $this->anyHelper->addFlashMessage('Datei nicht kopiert', 'Die Datei ' . $data[$k] . ' konnte nicht kopiert werden.', 'WARNING'); } } } //$entry->setFeUser( $GLOBALS['TSFE']->fe_user->user['uid'] ); $entry->setCruserId($GLOBALS['TSFE']->fe_user->user['uid']); $entry->setSrcuid($uid); $entry->setExt($type); $entry->setData(json_encode($data)); $this->entryRepository->update($entry); $this->persistenceManager->persistAll(); $entryUid = $entry->getUid(); $newAdminKey = ''; if ($params['adminKey'] && $this->anyHelper->validateKeyForUid($uid, $params['adminKey'], 'admin')) { $newAdminKey = $this->anyHelper->createKeyForUid($entryUid, 'admin'); } //http://adhok.99grad.de/index.php?id=17&id=17&nnf%5B193%5D%5Buid%5D=3&cHash=f14da214fc18a7f53b4da7342f3abe64&eID=nnfesubmit&action=feedit&type=nnfilearchive&uid=21&key=02bc7442 $this->anyHelper->httpRedirect($settings['editPid'], array('nnf' => $params['nnf'], 'tx_nnfesubmit_nnfesubmit[key]' => $this->anyHelper->createKeyForUid($entryUid), 'tx_nnfesubmit_nnfesubmit[adminKey]' => $newAdminKey, 'tx_nnfesubmit_nnfesubmit[entry]' => $entryUid, 'tx_nnfesubmit_nnfesubmit[pluginUid]' => intval($params['pluginUid']), 'tx_nnfesubmit_nnfesubmit[returnUrl]' => $params['returnUrl'])); // \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($entry); // $this->editAction( $entry->getUid() ); die; }
/** * Copies any "RTEmagic" image files found in record with table/id to new names. * Usage: After copying a record this function should be called to search for "RTEmagic"-images inside the record. If such are found they should be duplicated to new names so all records have a 1-1 relation to them. * Reason for copying RTEmagic files: a) if you remove an RTEmagic image from a record it will remove the file - any other record using it will have a lost reference! b) RTEmagic images keeps an original and a copy. The copy always is re-calculated to have the correct physical measures as the HTML tag inserting it defines. This is calculated from the original. Two records using the same image could have difference HTML-width/heights for the image and the copy could only comply with one of them. If you don't want a 1-1 relation you should NOT use RTEmagic files but just insert it as a normal file reference to a file inside fileadmin/ folder * * @param string $table Table name * @param int $theNewSQLID Record UID * @return void */ public function copyRecord_fixRTEmagicImages($table, $theNewSQLID) { // Creating fileFunc object. if (!$this->fileFunc) { $this->fileFunc = GeneralUtility::makeInstance(BasicFileUtility::class); $this->include_filefunctions = 1; } // Select all RTEmagic files in the reference table from the table/ID $where = join(' AND ', array('ref_table=' . $this->databaseConnection->fullQuoteStr('_FILE', 'sys_refindex'), 'ref_string LIKE ' . $this->databaseConnection->fullQuoteStr('%/RTEmagic%', 'sys_refindex'), 'softref_key=' . $this->databaseConnection->fullQuoteStr('images', 'sys_refindex'), 'tablename=' . $this->databaseConnection->fullQuoteStr($table, 'sys_refindex'), 'recuid=' . (int) $theNewSQLID)); $rteFileRecords = $this->databaseConnection->exec_SELECTgetRows('*', 'sys_refindex', $where, '', 'sorting DESC'); // Traverse the files found and copy them: if (!is_array($rteFileRecords)) { return; } foreach ($rteFileRecords as $rteFileRecord) { $filename = basename($rteFileRecord['ref_string']); if (!GeneralUtility::isFirstPartOfStr($filename, 'RTEmagicC_')) { continue; } $fileInfo = array(); $fileInfo['exists'] = @is_file(PATH_site . $rteFileRecord['ref_string']); $fileInfo['original'] = substr($rteFileRecord['ref_string'], 0, -strlen($filename)) . 'RTEmagicP_' . preg_replace('/\\.[[:alnum:]]+$/', '', substr($filename, 10)); $fileInfo['original_exists'] = @is_file(PATH_site . $fileInfo['original']); // CODE from tx_impexp and class.rte_images.php adapted for use here: if (!$fileInfo['exists'] || !$fileInfo['original_exists']) { if ($this->enableLogging) { $this->newlog('Trying to copy RTEmagic files (' . $rteFileRecord['ref_string'] . ' / ' . $fileInfo['original'] . ') but one or both were missing', 1); } continue; } // Initialize; Get directory prefix for file and set the original name: $dirPrefix = dirname($rteFileRecord['ref_string']) . '/'; $rteOrigName = basename($fileInfo['original']); // If filename looks like an RTE file, and the directory is in "uploads/", then process as a RTE file! if ($rteOrigName && GeneralUtility::isFirstPartOfStr($dirPrefix, 'uploads/') && @is_dir(PATH_site . $dirPrefix)) { // RTE: // From the "original" RTE filename, produce a new "original" destination filename which is unused. $origDestName = $this->fileFunc->getUniqueName($rteOrigName, PATH_site . $dirPrefix); // Create copy file name: $pI = pathinfo($rteFileRecord['ref_string']); $copyDestName = dirname($origDestName) . '/RTEmagicC_' . substr(basename($origDestName), 10) . '.' . $pI['extension']; if (!@is_file($copyDestName) && !@is_file($origDestName) && $origDestName === GeneralUtility::getFileAbsFileName($origDestName) && $copyDestName === GeneralUtility::getFileAbsFileName($copyDestName)) { // Making copies: GeneralUtility::upload_copy_move(PATH_site . $fileInfo['original'], $origDestName); GeneralUtility::upload_copy_move(PATH_site . $rteFileRecord['ref_string'], $copyDestName); clearstatcache(); // Register this: $this->RTEmagic_copyIndex[$rteFileRecord['tablename']][$rteFileRecord['recuid']][$rteFileRecord['field']][$rteFileRecord['ref_string']] = PathUtility::stripPathSitePrefix($copyDestName); // Check and update the record using \TYPO3\CMS\Core\Database\ReferenceIndex if (@is_file($copyDestName)) { /** @var ReferenceIndex $sysRefObj */ $sysRefObj = GeneralUtility::makeInstance(ReferenceIndex::class); $error = $sysRefObj->setReferenceValue($rteFileRecord['hash'], PathUtility::stripPathSitePrefix($copyDestName), false, true); if ($this->enableLogging && $error) { echo $this->newlog(ReferenceIndex::class . '::setReferenceValue(): ' . $error, 1); } } elseif ($this->enableLogging) { $this->newlog('File "' . $copyDestName . '" was not created!', 1); } } elseif ($this->enableLogging) { $this->newlog('Could not construct new unique names for file!', 1); } } elseif ($this->enableLogging) { $this->newlog('Maybe directory of file was not within "uploads/"?', 1); } } }
/** * Returns a unique absolute path of a file or folder. * * @param string $path * the path of a file or folder relative to the calling extension's * upload directory, must not be empty * * @return string the unique absolute path of a file or folder * * @throws \InvalidArgumentException */ public function getUniqueFileOrFolderPath($path) { if (empty($path)) { throw new \InvalidArgumentException('The first parameter $path must not be empty.', 1334439457); } if (!self::$fileNameProcessor) { self::$fileNameProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility'); } return self::$fileNameProcessor->getUniqueName(basename($path), $this->uploadFolderPath . GeneralUtility::dirname($path)); }
/** * Copies any "RTEmagic" image files found in record with table/id to new names. * Usage: After copying a record this function should be called to search for "RTEmagic"-images inside the record. If such are found they should be duplicated to new names so all records have a 1-1 relation to them. * Reason for copying RTEmagic files: a) if you remove an RTEmagic image from a record it will remove the file - any other record using it will have a lost reference! b) RTEmagic images keeps an original and a copy. The copy always is re-calculated to have the correct physical measures as the HTML tag inserting it defines. This is calculated from the original. Two records using the same image could have difference HTML-width/heights for the image and the copy could only comply with one of them. If you don't want a 1-1 relation you should NOT use RTEmagic files but just insert it as a normal file reference to a file inside fileadmin/ folder * * @param string $table Table name * @param integer $theNewSQLID Record UID * @return void * @todo Define visibility */ public function copyRecord_fixRTEmagicImages($table, $theNewSQLID) { // Creating fileFunc object. if (!$this->fileFunc) { $this->fileFunc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility'); $this->include_filefunctions = 1; } // Select all RTEmagic files in the reference table from the table/ID $recs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', 'ref_table=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('_FILE', 'sys_refindex') . ' AND ref_string LIKE ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('%/RTEmagic%', 'sys_refindex') . ' AND softref_key=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('images', 'sys_refindex') . ' AND tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_refindex') . ' AND recuid=' . intval($theNewSQLID), '', 'sorting DESC'); // Traverse the files found and copy them: if (is_array($recs)) { foreach ($recs as $rec) { $filename = basename($rec['ref_string']); $fileInfo = array(); if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($filename, 'RTEmagicC_')) { $fileInfo['exists'] = @is_file(PATH_site . $rec['ref_string']); $fileInfo['original'] = substr($rec['ref_string'], 0, -strlen($filename)) . 'RTEmagicP_' . preg_replace('/\\.[[:alnum:]]+$/', '', substr($filename, 10)); $fileInfo['original_exists'] = @is_file(PATH_site . $fileInfo['original']); // CODE from tx_impexp and class.rte_images.php adapted for use here: if ($fileInfo['exists'] && $fileInfo['original_exists']) { // Initialize; Get directory prefix for file and set the original name: $dirPrefix = dirname($rec['ref_string']) . '/'; $rteOrigName = basename($fileInfo['original']); // If filename looks like an RTE file, and the directory is in "uploads/", then process as a RTE file! if ($rteOrigName && \TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($dirPrefix, 'uploads/') && @is_dir(PATH_site . $dirPrefix)) { // RTE: // From the "original" RTE filename, produce a new "original" destination filename which is unused. $origDestName = $this->fileFunc->getUniqueName($rteOrigName, PATH_site . $dirPrefix); // Create copy file name: $pI = pathinfo($rec['ref_string']); $copyDestName = dirname($origDestName) . '/RTEmagicC_' . substr(basename($origDestName), 10) . '.' . $pI['extension']; if (!@is_file($copyDestName) && !@is_file($origDestName) && $origDestName === \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($origDestName) && $copyDestName === \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($copyDestName)) { // Making copies: \TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move(PATH_site . $fileInfo['original'], $origDestName); \TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move(PATH_site . $rec['ref_string'], $copyDestName); clearstatcache(); // Register this: $this->RTEmagic_copyIndex[$rec['tablename']][$rec['recuid']][$rec['field']][$rec['ref_string']] = substr($copyDestName, strlen(PATH_site)); // Check and update the record using the t3lib_refindex class: if (@is_file($copyDestName)) { $sysRefObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\ReferenceIndex'); $error = $sysRefObj->setReferenceValue($rec['hash'], substr($copyDestName, strlen(PATH_site)), FALSE, TRUE); if ($error) { echo $this->newlog('TYPO3\\CMS\\Core\\Database\\ReferenceIndex::setReferenceValue(): ' . $error, 1); } } else { $this->newlog('File "' . $copyDestName . '" was not created!', 1); } } else { $this->newlog('Could not construct new unique names for file!', 1); } } else { $this->newlog('Maybe directory of file was not within "uploads/"?', 1); } } else { $this->newlog('Trying to copy RTEmagic files (' . $rec['ref_string'] . ' / ' . $fileInfo['original'] . ') but one or both were missing', 1); } } } } }
/** * Processing of files. * NOTICE: for now files can be handled only on creation of records. But a more advanced feature is that PREVIEW of files is handled. * * @param array $cmdParts Array with cmd-parts (from parseValues()). This will for example contain information about allowed file extensions and max size of uploaded files. * @param string $theField The fieldname with the files. * * @return void * @see parseValues() */ protected function processFiles($cmdParts, $theField) { // First, make an array with the filename and file reference, whether the file is just uploaded or a preview $filesArr = []; if (is_string($this->dataArr[$theField])) { // files from preview. $tmpArr = explode(',', $this->dataArr[$theField]); foreach ($tmpArr as $val) { $valParts = explode('|', $val); $filesArr[] = ['name' => $valParts[1], 'tmp_name' => PATH_site . 'typo3temp/' . $valParts[0]]; } } elseif (is_array($_FILES['FE'][$this->theTable][$theField]['name'])) { // Files from upload foreach ($_FILES['FE'][$this->theTable][$theField]['name'] as $kk => $vv) { if ($vv) { $tmpFile = GeneralUtility::upload_to_tempfile($_FILES['FE'][$this->theTable][$theField]['tmp_name'][$kk]); if ($tmpFile) { $this->unlinkTempFiles[] = $tmpFile; $filesArr[] = ['name' => $vv, 'tmp_name' => $tmpFile]; } } } } elseif (is_array($_FILES['FE']['name'][$this->theTable][$theField])) { // Files from upload foreach ($_FILES['FE']['name'][$this->theTable][$theField] as $kk => $vv) { if ($vv) { $tmpFile = GeneralUtility::upload_to_tempfile($_FILES['FE']['tmp_name'][$this->theTable][$theField][$kk]); if ($tmpFile) { $this->unlinkTempFiles[] = $tmpFile; $filesArr[] = ['name' => $vv, 'tmp_name' => $tmpFile]; } } } } // Then verify the files in that array; check existence, extension and size $this->dataArr[$theField] = ''; $finalFilesArr = []; if (count($filesArr)) { $extArray = GeneralUtility::trimExplode(';', strtolower($cmdParts[1]), 1); $maxSize = intval($cmdParts[3]); foreach ($filesArr as $infoArr) { $fI = pathinfo($infoArr['name']); if (GeneralUtility::verifyFilenameAgainstDenyPattern($fI['name'])) { if (!count($extArray) || in_array(strtolower($fI['extension']), $extArray)) { $tmpFile = $infoArr['tmp_name']; if (@is_file($tmpFile)) { if (!$maxSize || filesize($tmpFile) < $maxSize * 1024) { $finalFilesArr[] = $infoArr; } elseif ($this->conf['debug']) { debug('Size is beyond ' . $maxSize . ' kb (' . filesize($tmpFile) . ' bytes) and the file cannot be saved.'); } } elseif ($this->conf['debug']) { debug('Surprisingly there was no file for ' . $vv . ' in ' . $tmpFile); } } elseif ($this->conf['debug']) { debug('Extension "' . $fI['extension'] . '" not allowed'); } } elseif ($this->conf['debug']) { debug('Filename matched illegal pattern.'); } } } // Copy the files in the resulting array to the proper positions based on preview/non-preview. $fileNameList = []; $uploadPath = ''; foreach ($finalFilesArr as $infoArr) { if ($this->isPreview()) { // If the form is a preview form (and data is therefore not going into the database...) do this. $this->createFileFuncObj(); $fI = pathinfo($infoArr['name']); $tmpFilename = $this->theTable . '_' . GeneralUtility::shortmd5(uniqid($infoArr['name'])) . '.' . $fI['extension']; $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($tmpFilename), PATH_site . 'typo3temp/'); GeneralUtility::upload_copy_move($infoArr['tmp_name'], $theDestFile); // Setting the filename in the list $fI2 = pathinfo($theDestFile); $fileNameList[] = $fI2['basename'] . '|' . $infoArr['name']; } else { $this->createFileFuncObj(); if (is_array($GLOBALS['TCA'][$this->theTable]['columns'][$theField])) { $uploadPath = $GLOBALS['TCA'][$this->theTable]['columns'][$theField]['config']['uploadfolder']; } if ($uploadPath !== '') { $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($infoArr['name']), PATH_site . $uploadPath); GeneralUtility::upload_copy_move($infoArr['tmp_name'], $theDestFile); // Setting the filename in the list $fI2 = pathinfo($theDestFile); $fileNameList[] = $fI2['basename']; $this->filesStoredInUploadFolders[] = $theDestFile; } } // Implode the list of filenames $this->dataArr[$theField] = implode(',', $fileNameList); } }