/** * Get Online Media item id * * @param File $file * @return string */ public function getOnlineMediaId(File $file) { if (!isset($this->onlineMediaIdCache[$file->getUid()])) { // By definition these files only contain the ID of the remote media source $this->onlineMediaIdCache[$file->getUid()] = trim($file->getContents()); } return $this->onlineMediaIdCache[$file->getUid()]; }
/** * Create a processed file according to some configuration. * * @param File $file * @param array $processingConfiguration * @return string */ public function createAction(File $file, array $processingConfiguration = array()) { $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $processingConfiguration); $response = array('success' => TRUE, 'original' => $file->getUid(), 'title' => $file->getProperty('title') ? $file->getProperty('title') : $file->getName(), 'publicUrl' => $processedFile->getPublicUrl(), 'width' => $processedFile->getProperty('width'), 'height' => $processedFile->getProperty('height')); header("Content-Type: text/json"); return htmlspecialchars(json_encode($response), ENT_NOQUOTES); }
/** * Render a thumbnail of a media * * @throws MissingTcaConfigurationException * @return string */ public function create() { if (empty($this->file)) { throw new MissingTcaConfigurationException('Missing File object. Forgotten to set a file?', 1355933144); } // Default class name $className = 'Fab\\Media\\Thumbnail\\FallBackThumbnailProcessor'; if (File::FILETYPE_IMAGE == $this->file->getType()) { $className = 'Fab\\Media\\Thumbnail\\ImageThumbnailProcessor'; } elseif (File::FILETYPE_AUDIO == $this->file->getType()) { $className = 'Fab\\Media\\Thumbnail\\AudioThumbnailProcessor'; } elseif (File::FILETYPE_VIDEO == $this->file->getType()) { $className = 'Fab\\Media\\Thumbnail\\VideoThumbnailProcessor'; } elseif (File::FILETYPE_APPLICATION == $this->file->getType() || File::FILETYPE_TEXT == $this->file->getType()) { $className = 'Fab\\Media\\Thumbnail\\ApplicationThumbnailProcessor'; } /** @var $processorInstance \Fab\Media\Thumbnail\ThumbnailProcessorInterface */ $processorInstance = GeneralUtility::makeInstance($className); $thumbnail = ''; if ($this->file->exists()) { $thumbnail = $processorInstance->setThumbnailService($this)->create(); } else { $logger = Logger::getInstance($this); $logger->warning(sprintf('Resource not found for File uid "%s" at %s', $this->file->getUid(), $this->file->getIdentifier())); } return $thumbnail; }
/** * Generate the name of of the new File * * @return string */ public function generateProcessedFileNameWithoutExtension() { $name = $this->originalFile->getNameWithoutExtension(); $name .= '_' . $this->originalFile->getUid(); $name .= '_' . $this->calculateChecksum(); return $name; }
/** * Returns array of meta-data properties * * @param File $file * @return array */ public function findByFile(File $file) { $record = $this->findByFileUid($file->getUid()); // It could be possible that the meta information is freshly // created and inserted into the database. If this is the case // we have to take care about correct meta information for width and // height in case of an image. if (!empty($record['newlyCreated'])) { if ($file->getType() === File::FILETYPE_IMAGE && $file->getStorage()->getDriverType() === 'Local') { $fileNameAndPath = $file->getForLocalProcessing(false); $imageInfo = GeneralUtility::makeInstance(FileType\ImageInfo::class, $fileNameAndPath); $additionalMetaInformation = array('width' => $imageInfo->getWidth(), 'height' => $imageInfo->getHeight()); $this->update($file->getUid(), $additionalMetaInformation); } $record = $this->findByFileUid($file->getUid()); } return $record; }
/** * Main function, rendering the content of the rename form * * @return void */ public function main() { // Make page header: $this->content = $this->doc->startPage($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle')); $pageContent = $this->doc->header($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle')); if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) { $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier(); } else { $fileIdentifier = $this->fileOrFolderObject->getUid(); } $pageContent .= '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" name="editform" role="form">'; // Making the formfields for renaming: $pageContent .= ' <div class="form-group"> <input class="form-control" type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject->getName()) . '" ' . $this->getDocumentTemplate()->formWidth(40) . ' /> <input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" /> </div> '; // Making submit button: $pageContent .= ' <div class="form-group"> <input class="btn btn-primary" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.submit', TRUE) . '" /> <input class="btn btn-danger" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', TRUE) . '" onclick="backToList(); return false;" /> <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" /> ' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction') . ' </div> '; $pageContent .= '</form>'; $docHeaderButtons = array('back' => ''); $docHeaderButtons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_rename'); // Back if ($this->returnUrl) { $docHeaderButtons['back'] = '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisUrl($this->returnUrl)) . '" class="typo3-goBack" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-view-go-back') . '</a>'; } // Add the HTML as a section: $markerArray = array('CSH' => $docHeaderButtons['csh'], 'FUNC_MENU' => '', 'CONTENT' => $pageContent, 'PATH' => $this->title); $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray); $this->content .= $this->doc->endPage(); $this->content = $this->doc->insertStylesAndJS($this->content); }
/** * Main function, rendering the content of the rename form * * @return void */ public function main() { if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) { $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier(); } else { $fileIdentifier = $this->fileOrFolderObject->getUid(); } $pageContent = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" name="editform" role="form">'; // Making the formfields for renaming: $pageContent .= ' <div class="form-group"> <input class="form-control" type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject->getName()) . '" ' . $this->getDocumentTemplate()->formWidth(40) . ' /> <input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" /> </div> '; // Making submit button: $pageContent .= ' <div class="form-group"> <input class="btn btn-primary" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.submit', true) . '" /> <input class="btn btn-danger" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', true) . '" onclick="backToList(); return false;" /> <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" /> </div> '; $pageContent .= '</form>'; // Create buttons $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); // csh button $cshButton = $buttonBar->makeHelpButton()->setModuleName('xMOD_csh_corebe')->setFieldName('file_rename'); $buttonBar->addButton($cshButton); // back button if ($this->returnUrl) { $backButton = $buttonBar->makeLinkButton()->sethref(GeneralUtility::linkThisUrl($this->returnUrl))->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', true))->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL)); $buttonBar->addButton($backButton); } // set header $this->content = '<h1>' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle') . '</h1>'; // add section $this->content .= $this->moduleTemplate->section('', $pageContent); $this->moduleTemplate->setContent($this->content); }
/** * Returns a where clause to find a file in database * * @param File $file * * @return string */ protected function getWhereClauseForFile(File $file) { if ((int) $file->_getPropertyRaw('uid') > 0) { $where = 'uid=' . (int) $file->getUid(); } else { $where = sprintf('storage=%u AND identifier LIKE %s', (int) $file->getStorage()->getUid(), $this->getDatabaseConnection()->fullQuoteStr($file->_getPropertyRaw('identifier'), $this->table)); } return $where; }
/** * Save an image with FAL * @param \TYPO3\CMS\Core\Resource\File $fileObject * @param \MUM\BjrFreizeit\Domain\Model\Leisure $leisure * @param $pid * @return int last insert id, file reference uid * */ public function saveImage(\TYPO3\CMS\Core\Resource\File $fileObject, \MUM\BjrFreizeit\Domain\Model\Leisure $leisure) { //$dateiname = $filename; // Dateinamen auslesen $tabellenName = 'tx_bjrfreizeit_domain_model_leisure'; $feldName = 'image'; $data = array('uid_local' => $fileObject->getUid(), 'uid_foreign' => $leisure->getUid(), 'tablenames' => $tabellenName, 'fieldname' => $feldName, 'pid' => $leisure->getPid(), 'table_local' => 'sys_file', 'tstamp' => time(), 'crdate' => time(), 'cruser_id' => 100); $where = 'deleted ="0" AND hidden ="0" AND tablenames ="' . $tabellenName . '" AND uid_foreign=' . (int) $leisure->getUid() . ' AND table_local="sys_file"' . ' AND fieldname ="' . $feldName . '"'; $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'sys_file_reference', $where); if (empty($row)) { $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_file_reference', $data, FALSE); $res = $GLOBALS['TYPO3_DB']->sql_insert_id(); } else { $data = array('uid_local' => $fileObject->getUid(), 'tstamp' => time(), 'cruser_id' => 100); $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_file_reference', $where, $data, FALSE); } return $res; }
/** * Get an existing items from the references that matches the file * * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\GeorgRinger\News\Domain\Model\FileReference> $items * @param \TYPO3\CMS\Core\Resource\File $file * @return bool|FileReference */ protected function getIfFalRelationIfAlreadyExists(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $items, \TYPO3\CMS\Core\Resource\File $file) { $result = FALSE; if ($items->count() !== 0) { /** @var $item FileReference */ foreach ($items as $item) { // only check already persisted items if ($item->getFileUid() === (int) $file->getUid() || $item->getUid() && $item->getOriginalResource()->getName() === $file->getName() && $item->getOriginalResource()->getSize() === (int) $file->getSize()) { $result = $item; break; } } } return $result; }
/** * @param FalFile $file * @param int $resourcePointer * @return \Bureauoberhoff\H5upldr\Domain\Model\FileReference */ protected function createFileReferenceFromFalFileObject(FalFile $file, $resourcePointer = NULL) { $fileReference = $this->resourceFactory->createFileReferenceObject(array('uid_local' => $file->getUid(), 'uid_foreign' => uniqid('NEW_'), 'uid' => uniqid('NEW_'), 'crop' => NULL)); return $this->createFileReferenceFromFalFileReferenceObject($fileReference, $resourcePointer); }
/** * Make reference display * * @param string $table Table name * @param string|\TYPO3\CMS\Core\Resource\File $ref Filename or uid * @return string HTML * @todo Define visibility */ public function makeRef($table, $ref) { // Look up the path: if ($table === '_FILE') { $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_file_reference', 'uid_local=' . $ref->getUid()); } else { $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', 'ref_table=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_refindex') . ' AND ref_uid=' . intval($ref) . ' AND deleted=0'); } // Compile information for title tag: $infoData = array(); if (count($rows)) { $infoData[] = '<tr class="t3-row-header">' . '<td> </td>' . '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.table') . '</td>' . '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.title') . '</td>' . '<td>[uid]</td>' . '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.field') . '</td>' . '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.flexpointer') . '</td>' . '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.softrefKey') . '</td>' . '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.sorting') . '</td>' . '</tr>'; } foreach ($rows as $row) { if ($table === '_FILE') { $row = $this->mapFileReferenceOnRefIndex($row); } $record = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($row['tablename'], $row['recuid']); $parentRecord = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('pages', $record['pid']); $actions = $this->getRecordActions($row['tablename'], $row['recuid']); $infoData[] = '<tr class="bgColor4">' . '<td style="white-space:nowrap;">' . $actions . '</td>' . '<td>' . $GLOBALS['LANG']->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title'], TRUE) . '</td>' . '<td>' . \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle($row['tablename'], $record, TRUE) . '</td>' . '<td><span title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:page') . ': ' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle('pages', $parentRecord)) . ' (uid=' . $record['pid'] . ')">' . $record['uid'] . '</span></td>' . '<td>' . htmlspecialchars($this->getFieldName($row['tablename'], $row['field'])) . '</td>' . '<td>' . htmlspecialchars($row['flexpointer']) . '</td>' . '<td>' . htmlspecialchars($row['softref_key']) . '</td>' . '<td>' . htmlspecialchars($row['sorting']) . '</td>' . '</tr>'; } $referenceLine = ''; if (count($infoData)) { $referenceLine = '<table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist">' . implode('', $infoData) . '</table>'; } return $referenceLine; }
/** * Returns array of meta-data properties * * @param File $file * @return array */ public function findByFile(File $file) { return $this->findByFileUid($file->getUid()); }
/** * Make reference display * * @param string $table Table name * @param string|\TYPO3\CMS\Core\Resource\File $ref Filename or uid * @return string HTML */ protected function makeRef($table, $ref) { $lang = $this->getLanguageService(); // Files reside in sys_file table if ($table === '_FILE') { $selectTable = 'sys_file'; $selectUid = $ref->getUid(); } else { $selectTable = $table; $selectUid = $ref; } $rows = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_refindex', 'ref_table=' . $this->getDatabaseConnection()->fullQuoteStr($selectTable, 'sys_refindex') . ' AND ref_uid=' . (int) $selectUid . ' AND deleted=0'); // Compile information for title tag: $infoData = array(); $infoDataHeader = ''; if (!empty($rows)) { $infoDataHeader = ' <tr> <th class="col-icon"></th> <th class="col-title">' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.title') . '</th> <th>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.table') . '</th> <th>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.uid') . '</th> <th>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.field') . '</th> <th>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.flexpointer') . '</th> <th>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.softrefKey') . '</th> <th>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.sorting') . '</th> <th class="col-control"></th> </tr>'; } foreach ($rows as $row) { if ($row['tablename'] === 'sys_file_reference') { $row = $this->transformFileReferenceToRecordReference($row); if ($row['tablename'] === null || $row['recuid'] === null) { return ''; } } $record = BackendUtility::getRecord($row['tablename'], $row['recuid']); if ($record) { $parentRecord = BackendUtility::getRecord('pages', $record['pid']); $parentRecordTitle = is_array($parentRecord) ? BackendUtility::getRecordTitle('pages', $parentRecord) : ''; $icon = $this->iconFactory->getIconForRecord($row['tablename'], $record, Icon::SIZE_SMALL)->render(); $actions = $this->getRecordActions($row['tablename'], $row['recuid']); $urlParameters = ['edit' => [$row['tablename'] => [$row['recuid'] => 'edit']], 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')]; $url = BackendUtility::getModuleUrl('record_edit', $urlParameters); $infoData[] = ' <tr> <td class="col-icon"> <a href="' . htmlspecialchars($url) . '" title="id=' . $record['uid'] . '"> ' . $icon . ' </a> </td> <td class="col-title"> <a href="' . htmlspecialchars($url) . '" title="id=' . $record['uid'] . '" > ' . BackendUtility::getRecordTitle($row['tablename'], $record, true) . ' </a> </td> <td>' . $lang->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title'], true) . '</td> <td> <span title="' . $lang->sL('LLL:EXT:lang/locallang_common.xlf:page') . ': ' . htmlspecialchars($parentRecordTitle) . ' (uid=' . $record['pid'] . ')"> ' . $record['uid'] . ' </span> </td> <td>' . htmlspecialchars($this->getLabelForTableColumn($row['tablename'], $row['field'])) . '</td> <td>' . htmlspecialchars($row['flexpointer']) . '</td> <td>' . htmlspecialchars($row['softref_key']) . '</td> <td>' . htmlspecialchars($row['sorting']) . '</td> <td class="col-control">' . $actions . '</td> </tr>'; } else { $infoData[] = ' <tr> <td class="col-icon"></td> <td class="col-title">' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.missing_record') . ' (uid=' . (int) $row['recuid'] . ')</td> <td>' . htmlspecialchars($lang->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title']) ?: $row['tablename']) . '</td> <td></td> <td>' . htmlspecialchars($this->getLabelForTableColumn($row['tablename'], $row['field'])) . '</td> <td>' . htmlspecialchars($row['flexpointer']) . '</td> <td>' . htmlspecialchars($row['softref_key']) . '</td> <td>' . htmlspecialchars($row['sorting']) . '</td> <td class="col-control"></td> </tr>'; } } $referenceLine = ''; if (!empty($infoData)) { $referenceLine = ' <div class="table-fit"> <table class="table table-striped table-hover"> <thead>' . $infoDataHeader . '</thead> <tbody>' . implode('', $infoData) . '</tbody> </table> </div>'; } return $referenceLine; }
/** * Since the core desperately needs image sizes in metadata table put them there * This should be called after every "content" update and "record" creation * * @param File $fileObject */ protected function extractRequiredMetaData(File $fileObject) { // since the core desperately needs image sizes in metadata table do this manually // prevent doing this for remote storages, remote storages must provide the data with extractors if ($fileObject->getType() == File::FILETYPE_IMAGE && $this->storage->getDriverType() === 'Local') { $rawFileLocation = $fileObject->getForLocalProcessing(FALSE); $imageInfo = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Type\\File\\ImageInfo', $rawFileLocation); $metaData = array('width' => $imageInfo->getWidth(), 'height' => $imageInfo->getHeight()); $this->getMetaDataRepository()->update($fileObject->getUid(), $metaData); $fileObject->_updateMetaDataProperties($metaData); } }
/** * migrate file from dam record to fal system * * @param array $damRecord * @param \TYPO3\CMS\Core\Resource\File $fileObject * @throws \Exception * @return void */ protected function migrateFileFromDamToFal(array $damRecord, \TYPO3\CMS\Core\Resource\File $fileObject) { // in getProperties() we don't have the required UID of metadata record // if no metadata record is available it will automatically created within FAL $metadataRecord = $fileObject->_getMetaData(); if (is_array($metadataRecord)) { // update existing record $this->database->exec_UPDATEquery('sys_file_metadata', 'uid = ' . $metadataRecord['uid'], $this->createArrayForUpdateInsertSysFileRecord($damRecord)); // add the migrated uid of the DAM record to the FAL record $this->database->exec_UPDATEquery('sys_file', 'uid = ' . $fileObject->getUid(), array('_migrateddamuid' => $damRecord['uid'])); } }
/** * The actual processing TASK * * Should return an array with database properties for sys_file_metadata to write * * @param File $file * @param array $previousExtractedData optional, contains the array of already extracted data * @return array */ public function extractMetaData(File $file, array $previousExtractedData = []) { $metadata = []; try { if (!class_exists('ColorThief\\ColorThief')) { throw new \RuntimeException('Class ColorThief\\ColorThief does not exist', 1470749087524); } $path = $file->getForLocalProcessing(); $averageColor = ColorThief::getColor($path); if (!is_array($averageColor)) { throw new \RuntimeException('$averageColor is not an array', 1470749109020); } if (count($averageColor) !== 3) { throw new \RuntimeException('$averageColor is an array, but has less than 3 items', 1470749136303); } $r = dechex((int) $averageColor[0]); $g = dechex((int) $averageColor[1]); $b = dechex((int) $averageColor[2]); $metadata['average_color'] = '#' . $r . $g . $b; $this->logger->debug(sprintf('Extracted average color "%s"', $metadata['average_color']), ['file' => $file->getUid()]); } catch (\Exception $e) { $this->logger->error($e->getCode() . ': ' . $e->getMessage(), ['file' => $file->getUid()]); } return $metadata; }
/** * Adds a files content from a sys file record to the export memory * * @param \TYPO3\CMS\Core\Resource\File $file * @return void */ public function export_addSysFile(\TYPO3\CMS\Core\Resource\File $file) { if ($file->getProperty('size') >= $this->maxFileSize) { $this->error('File ' . $file->getPublicUrl() . ' was larger (' . GeneralUtility::formatSize($file->getProperty('size')) . ') than the maxFileSize (' . GeneralUtility::formatSize($this->maxFileSize) . ')! Skipping.'); return; } try { $fileContent = $file->getContents(); } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) { $this->error('File ' . $file->getPublicUrl() . ': ' . $e->getMessage()); return; } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) { $this->error('File ' . $file->getPublicUrl() . ': ' . $e->getMessage()); return; } $fileUid = $file->getUid(); $fileInfo = $file->getStorage()->getFileInfo($file); // we sadly have to cast it to string here, because the size property is also returning a string $fileSize = (string) $fileInfo['size']; if ($fileSize !== $file->getProperty('size')) { $this->error('File size of ' . $file->getCombinedIdentifier() . ' is not up-to-date in index! File added with current size.'); $this->dat['records']['sys_file:' . $fileUid]['data']['size'] = $fileSize; } $fileSha1 = $file->getStorage()->hashFile($file, 'sha1'); if ($fileSha1 !== $file->getProperty('sha1')) { $this->error('File sha1 hash of ' . $file->getCombinedIdentifier() . ' is not up-to-date in index! File added on current sha1.'); $this->dat['records']['sys_file:' . $fileUid]['data']['sha1'] = $fileSha1; } $fileRec = array(); $fileRec['filesize'] = $fileSize; $fileRec['filename'] = $file->getProperty('name'); $fileRec['filemtime'] = $file->getProperty('modification_date'); // build unique id based on the storage and the file identifier $fileId = md5($file->getStorage()->getUid() . ':' . $file->getProperty('identifier_hash')); // Setting this data in the header $this->dat['header']['files_fal'][$fileId] = $fileRec; // ... and finally add the heavy stuff: $fileRec['content'] = $fileContent; $fileRec['content_sha1'] = $fileSha1; $this->dat['files_fal'][$fileId] = $fileRec; }
/** * Generates a new file name based on an existing file and the format of the new name * * @param \TYPO3\CMS\Core\Resource\File $file original file * @param string $filenameFormat filename format with markers * @return string new file name */ protected function generateFilename(\TYPO3\CMS\Core\Resource\File $file, $filenameFormat) { return $this->cObj->substituteMarkerArray($filenameFormat, array('###NAME###' => basename($file->getProperty('name'), $file->getProperty('extension') ? '.' . $file->getProperty('extension') : ''), '###EXTENSION###' => $file->getProperty('extension'), '###UID###' => $file->getUid(), '###SHA1###' => $file->getProperty('sha1'), '###HASH###' => $file->getProperty('identifier_hash'), '###UNIQUE###' => md5(uniqid($file->getProperty('name'), true)))); }
/** * setFile * * @param \TYPO3\CMS\Core\Resource\File $falFile * @return void */ public function setFile(\TYPO3\CMS\Core\Resource\File $falFile) { $this->originalFileIdentifier = (int) $falFile->getUid(); }
/** * Creates the edit control section * * @param \TYPO3\CMS\Core\Resource\File|\TYPO3\CMS\Core\Resource\Folder $fileOrFolderObject Array with information about the file/directory for which to make the edit control section for the listing. * @return string HTML-table * @todo Define visibility */ protected function makeEdit7($fileOrFolderObject) { $cells = array(); $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier(); // Edit file content (if editable) if ($fileOrFolderObject instanceof File && $fileOrFolderObject->checkActionPermission('write') && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileOrFolderObject->getExtension())) { $url = BackendUtility::getModuleUrl('file_edit', array('target' => $fullIdentifier)); $editOnClick = 'top.content.list_frame.location.href=' . GeneralUtility::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;'; $cells['edit'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($editOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.editcontent') . '">' . IconUtility::getSpriteIcon('actions-page-open') . '</a>'; } else { $cells['edit'] = $this->spaceIcon; } if ($fileOrFolderObject instanceof File) { $fileUrl = $fileOrFolderObject->getPublicUrl(TRUE); if ($fileUrl) { $aOnClick = 'return top.openUrlInWindow(' . GeneralUtility::quoteJSvalue($fileUrl) . ', \'WebFile\');'; $cells['view'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($aOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.view') . '">' . IconUtility::getSpriteIcon('actions-document-view') . '</a>'; } else { $cells['view'] = $this->spaceIcon; } } else { $cells['view'] = $this->spaceIcon; } // rename the file if ($fileOrFolderObject->checkActionPermission('rename')) { $url = BackendUtility::getModuleUrl('file_rename', array('target' => $fullIdentifier)); $renameOnClick = 'top.content.list_frame.location.href = ' . GeneralUtility::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;'; $cells['rename'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($renameOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.rename') . '">' . IconUtility::getSpriteIcon('actions-edit-rename') . '</a>'; } else { $cells['rename'] = $this->spaceIcon; } if ($fileOrFolderObject->checkActionPermission('read')) { $infoOnClick = ''; if ($fileOrFolderObject instanceof Folder) { $infoOnClick = 'top.launchView( \'_FOLDER\', ' . GeneralUtility::quoteJSvalue($fullIdentifier) . ');return false;'; } elseif ($fileOrFolderObject instanceof File) { $infoOnClick = 'top.launchView( \'_FILE\', ' . GeneralUtility::quoteJSvalue($fullIdentifier) . ');return false;'; } $cells['info'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($infoOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.info') . '">' . IconUtility::getSpriteIcon('status-dialog-information') . '</a>'; } else { $cells['info'] = $this->spaceIcon; } // delete the file if ($fileOrFolderObject->checkActionPermission('delete')) { $identifier = $fileOrFolderObject->getIdentifier(); if ($fileOrFolderObject instanceof Folder) { $referenceCountText = BackendUtility::referenceCount('_FILE', $identifier, ' (There are %s reference(s) to this folder!)'); } else { $referenceCountText = BackendUtility::referenceCount('sys_file', $fileOrFolderObject->getUid(), ' (There are %s reference(s) to this file!)'); } if ($this->getBackendUser()->jsConfirmation(JsConfirmation::DELETE)) { $confirmationCheck = 'confirm(' . GeneralUtility::quoteJSvalue(sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'), $fileOrFolderObject->getName()) . $referenceCountText) . ')'; } else { $confirmationCheck = '1 == 1'; } $removeOnClick = 'if (' . $confirmationCheck . ') { top.content.list_frame.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_file') . '&file[delete][0][data]=' . rawurlencode($fileOrFolderObject->getCombinedIdentifier()) . '&vC=' . $this->getBackendUser()->veriCode() . BackendUtility::getUrlToken('tceAction') . '&redirect=') . '+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);};'; $cells['delete'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($removeOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.delete') . '">' . IconUtility::getSpriteIcon('actions-edit-delete') . '</a>'; } else { $cells['delete'] = $this->spaceIcon; } // Hook for manipulating edit icons. if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) { $hookObject = GeneralUtility::getUserObj($classData); if (!$hookObject instanceof FileListEditIconHookInterface) { throw new \UnexpectedValueException('$hookObject must implement interface \\TYPO3\\CMS\\Filelist\\FileListEditIconHookInterface', 1235225797); } $hookObject->manipulateEditIcons($cells, $this); } } $cells = array_merge($cells, $this->addAdditionalCells($fileOrFolderObject)); // Compile items into a DIV-element: return '<div class="btn-group">' . implode('', $cells) . '</div>'; }
/** * Count link image references. * * @param File|int $file * @return int */ public function countSoftLinkReferences($file) { $fileIdentifier = $file instanceof File ? $file->getUid() : (int) $file; // Count the link references of the file. $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('count(*) AS count', 'sys_refindex', 'deleted = 0 AND softref_key = "typolink_tag" AND ref_table = "sys_file" AND ref_uid = ' . $fileIdentifier); return (int) $record['count']; }
/** * Create a file reference * * @param File $file * @return void */ protected function createFileReference($file) { $faldata = array(); $falData['sys_file_reference']['NEW1234'] = array('table_local' => 'sys_file', 'uid_local' => $file->getUid(), 'tablenames' => 'tt_content', 'uid_foreign' => $this->id, 'fieldname' => 'image', 'pid' => $this->pid); if (isset($this->oEmbedData['title'])) { $falData['sys_file_reference']['NEW1234']['title'] = $this->oEmbedData['title']; $falData['sys_file_reference']['NEW1234']['alternative'] = $this->oEmbedData['title']; } $falData['tt_content'][$this->id] = array('image' => 'NEW1234'); /** @var \TYPO3\CMS\Core\DataHandling\DataHandler $tce */ $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler'); // create TCE instance $tce->start($falData, array()); $tce->process_datamap(); if ($tce->errorLog) { \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($tce->errorLog, 'Creating file reference for thumbnail failed. TCE->errorLog:'); } }
/** * Updates an existing file object in the database * * @param \TYPO3\CMS\Core\Resource\File $modifiedObject * @return void */ public function update($modifiedObject) { // TODO check if $modifiedObject is an instance of \TYPO3\CMS\Core\Resource\File // TODO check if $modifiedObject is indexed $changedProperties = $modifiedObject->getUpdatedProperties(); $properties = $modifiedObject->getProperties(); $updateFields = array(); foreach ($changedProperties as $propertyName) { $updateFields[$propertyName] = $properties[$propertyName]; } $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_file', 'uid=' . $modifiedObject->getUid(), $updateFields); }
/** * Make reference count * * @param \TYPO3\CMS\Core\Resource\File|\TYPO3\CMS\Core\Resource\Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing. * @return string HTML * @todo Define visibility */ public function makeRef($fileOrFolderObject) { if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FolderInterface) { return '-'; } // Look up the path: $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', 'ref_table = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('sys_file', 'sys_refindex') . ' AND ref_uid = ' . $fileOrFolderObject->getUid() . ' AND deleted=0'); return $this->generateReferenceToolTip($rows, '\'_FILE\', \'' . $fileOrFolderObject->getCombinedIdentifier() . '\''); }
/** * Make reference display * * @param string $table Table name * @param string|\TYPO3\CMS\Core\Resource\File $ref Filename or uid * @return array */ protected function makeRef($table, $ref) { $refLines = []; $lang = $this->getLanguageService(); // Files reside in sys_file table if ($table === '_FILE') { $selectTable = 'sys_file'; $selectUid = $ref->getUid(); } else { $selectTable = $table; $selectUid = $ref; } /** @var $queryBuilder \TYPO3\CMS\Core\Database\Query\QueryBuilder */ $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_refindex'); $rows = $queryBuilder->select('*')->from('sys_refindex')->where($queryBuilder->expr()->eq('ref_table', $queryBuilder->createNamedParameter($selectTable, \PDO::PARAM_STR)), $queryBuilder->expr()->eq('ref_uid', $queryBuilder->createNamedParameter($selectUid, \PDO::PARAM_INT)), $queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)))->execute()->fetchAll(); // Compile information for title tag: foreach ($rows as $row) { if ($row['tablename'] === 'sys_file_reference') { $row = $this->transformFileReferenceToRecordReference($row); if ($row['tablename'] === null || $row['recuid'] === null) { return; } } $line = []; $record = BackendUtility::getRecord($row['tablename'], $row['recuid']); if ($record) { $parentRecord = BackendUtility::getRecord('pages', $record['pid']); $parentRecordTitle = is_array($parentRecord) ? BackendUtility::getRecordTitle('pages', $parentRecord) : ''; $urlParameters = ['edit' => [$row['tablename'] => [$row['recuid'] => 'edit']], 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')]; $url = BackendUtility::getModuleUrl('record_edit', $urlParameters); $line['url'] = $url; $line['icon'] = $this->iconFactory->getIconForRecord($row['tablename'], $record, Icon::SIZE_SMALL)->render(); $line['row'] = $row; $line['record'] = $record; $line['recordTitle'] = BackendUtility::getRecordTitle($row['tablename'], $record, true); $line['parentRecordTitle'] = $parentRecordTitle; $line['title'] = $lang->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title']); $line['labelForTableColumn'] = $this->getLabelForTableColumn($row['tablename'], $row['field']); $line['actions'] = $this->getRecordActions($row['tablename'], $row['recuid']); } else { $line['row'] = $row; $line['title'] = $lang->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title']) ?: $row['tablename']; $line['labelForTableColumn'] = $this->getLabelForTableColumn($row['tablename'], $row['field']); } $refLines[] = $line; } return $refLines; }
/** * Make reference count * * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing. * @return string HTML */ public function makeRef($fileOrFolderObject) { if ($fileOrFolderObject instanceof FolderInterface) { return '-'; } // Look up the file in the sys_refindex. // Exclude sys_file_metadata records as these are no use references $databaseConnection = $this->getDatabaseConnection(); $table = 'sys_refindex'; $referenceCount = $databaseConnection->exec_SELECTcountRows('*', $table, 'ref_table=' . $databaseConnection->fullQuoteStr('sys_file', $table) . ' AND ref_uid=' . (int) $fileOrFolderObject->getUid() . ' AND deleted=0' . ' AND tablename != ' . $databaseConnection->fullQuoteStr('sys_file_metadata', $table)); return $this->generateReferenceToolTip($referenceCount, '\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier())); }
/** * Make reference count * * @param \TYPO3\CMS\Core\Resource\File|\TYPO3\CMS\Core\Resource\Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing. * @return string HTML * @todo Define visibility */ public function makeRef($fileOrFolderObject) { if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FolderInterface) { return '-'; } // Look up the file in the sys_refindex. // Exclude sys_file_metadata records as these are no use references $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', 'ref_table=\'sys_file\' AND ref_uid = ' . (int) $fileOrFolderObject->getUid() . ' AND deleted=0 AND tablename != "sys_file_metadata"'); return $this->generateReferenceToolTip($rows, '\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier())); }
/** * Adds a files content from a sys file record to the export memory * * @param File $file * @return void */ public function export_addSysFile(File $file) { if ($file->getProperty('size') >= $this->maxFileSize) { $this->error('File ' . $file->getPublicUrl() . ' was larger (' . GeneralUtility::formatSize($file->getProperty('size')) . ') than the maxFileSize (' . GeneralUtility::formatSize($this->maxFileSize) . ')! Skipping.'); return; } $fileContent = ''; try { if (!$this->saveFilesOutsideExportFile) { $fileContent = $file->getContents(); } else { $file->checkActionPermission('read'); } } catch (\Exception $e) { $this->error('Error when trying to add file ' . $file->getCombinedIdentifier() . ': ' . $e->getMessage()); return; } $fileUid = $file->getUid(); $fileInfo = $file->getStorage()->getFileInfo($file); // we sadly have to cast it to string here, because the size property is also returning a string $fileSize = (string) $fileInfo['size']; if ($fileSize !== $file->getProperty('size')) { $this->error('File size of ' . $file->getCombinedIdentifier() . ' is not up-to-date in index! File added with current size.'); $this->dat['records']['sys_file:' . $fileUid]['data']['size'] = $fileSize; } $fileSha1 = $file->getStorage()->hashFile($file, 'sha1'); if ($fileSha1 !== $file->getProperty('sha1')) { $this->error('File sha1 hash of ' . $file->getCombinedIdentifier() . ' is not up-to-date in index! File added on current sha1.'); $this->dat['records']['sys_file:' . $fileUid]['data']['sha1'] = $fileSha1; } $fileRec = array(); $fileRec['filesize'] = $fileSize; $fileRec['filename'] = $file->getProperty('name'); $fileRec['filemtime'] = $file->getProperty('modification_date'); // build unique id based on the storage and the file identifier $fileId = md5($file->getStorage()->getUid() . ':' . $file->getProperty('identifier_hash')); // Setting this data in the header $this->dat['header']['files_fal'][$fileId] = $fileRec; if (!$this->saveFilesOutsideExportFile) { // ... and finally add the heavy stuff: $fileRec['content'] = $fileContent; } else { GeneralUtility::upload_copy_move($file->getForLocalProcessing(false), $this->getTemporaryFilesPathForExport() . $file->getProperty('sha1')); } $fileRec['content_sha1'] = $fileSha1; $this->dat['files_fal'][$fileId] = $fileRec; }
/** * Make reference display * * @param string $table Table name * @param string|\TYPO3\CMS\Core\Resource\File $ref Filename or uid * @return string HTML */ protected function makeRef($table, $ref) { // Files reside in sys_file table if ($table === '_FILE') { $selectTable = 'sys_file'; $selectUid = $ref->getUid(); } else { $selectTable = $table; $selectUid = $ref; } $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', 'ref_table=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($selectTable, 'sys_refindex') . ' AND ref_uid=' . (int) $selectUid . ' AND deleted=0'); // Compile information for title tag: $infoData = array(); $infoDataHeader = ''; if (count($rows)) { $infoDataHeader = '<tr>' . '<td> </td>' . '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.table') . '</td>' . '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.title') . '</td>' . '<td>[uid]</td>' . '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.field') . '</td>' . '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.flexpointer') . '</td>' . '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.softrefKey') . '</td>' . '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.sorting') . '</td>' . '</tr>'; } foreach ($rows as $row) { if ($row['tablename'] === 'sys_file_reference') { $row = $this->transformFileReferenceToRecordReference($row); if ($row['tablename'] === NULL || $row['recuid'] === NULL) { return ''; } } $record = BackendUtility::getRecord($row['tablename'], $row['recuid']); if ($record) { $parentRecord = BackendUtility::getRecord('pages', $record['pid']); $parentRecordTitle = is_array($parentRecord) ? BackendUtility::getRecordTitle('pages', $parentRecord) : ''; $actions = $this->getRecordActions($row['tablename'], $row['recuid']); $infoData[] = '<tr class="db_list_normal">' . '<td style="white-space:nowrap;">' . $actions . '</td>' . '<td>' . $GLOBALS['LANG']->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title'], TRUE) . '</td>' . '<td>' . BackendUtility::getRecordTitle($row['tablename'], $record, TRUE) . '</td>' . '<td><span title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:page') . ': ' . htmlspecialchars($parentRecordTitle) . ' (uid=' . $record['pid'] . ')">' . $record['uid'] . '</span></td>' . '<td>' . htmlspecialchars($this->getLabelForTableColumn($row['tablename'], $row['field'])) . '</td>' . '<td>' . htmlspecialchars($row['flexpointer']) . '</td>' . '<td>' . htmlspecialchars($row['softref_key']) . '</td>' . '<td>' . htmlspecialchars($row['sorting']) . '</td>' . '</tr>'; } else { $infoData[] = '<tr class="db_list_normal">' . '<td style="white-space:nowrap;"></td>' . '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:show_item.php.missing_record') . ' (uid=' . $row['recuid'] . ')</td>' . '<td>' . htmlspecialchars($GLOBALS['LANG']->sL($GLOBALS['TCA'][$row['tablename']]['ctrl']['title']) ?: $row['tablename']) . '</td>' . '<td></td>' . '<td>' . htmlspecialchars($this->getLabelForTableColumn($row['tablename'], $row['field'])) . '</td>' . '<td>' . htmlspecialchars($row['flexpointer']) . '</td>' . '<td>' . htmlspecialchars($row['softref_key']) . '</td>' . '<td>' . htmlspecialchars($row['sorting']) . '</td>' . '</tr>'; } } $referenceLine = ''; if (count($infoData)) { $referenceLine = '<table class="t3-table">' . '<thead>' . $infoDataHeader . '</thead>' . '<tbody>' . implode('', $infoData) . '</tbody></table>'; } return $referenceLine; }