/** * renders <f:then> child if the current logged in FE user has access to the given asset * otherwise renders <f:else> child. * * @param Folder $folder * @param File $file * @return bool|string */ public function render(Folder $folder, File $file = NULL) { /** @var $checkPermissionsService \BeechIt\FalSecuredownload\Security\CheckPermissions */ $checkPermissionsService = GeneralUtility::makeInstance('BeechIt\\FalSecuredownload\\Security\\CheckPermissions'); $userFeGroups = $this->getFeUserGroups(); $access = FALSE; // check folder access if ($checkPermissionsService->checkFolderRootLineAccess($folder, $userFeGroups)) { if ($file === NULL) { $access = TRUE; } else { $feGroups = $file->getProperty('fe_groups'); if ($feGroups !== '') { $access = $checkPermissionsService->matchFeGroupsWithFeUser($feGroups, $userFeGroups); } else { $access = TRUE; } } } if ($access) { return $this->renderThenChild(); } else { return $this->renderElseChild(); } }
/** * @param File $file * @return string */ protected function getUri(File $file) { $metadataProperties = $file->_getMetaData(); $parameterName = sprintf('edit[sys_file_metadata][%s]', $metadataProperties['uid']); $uri = BackendUtility::getModuleUrl('record_edit', array($parameterName => 'edit', 'returnUrl' => BackendUtility::getModuleUrl(GeneralUtility::_GP('M'), $this->getAdditionalParameters()))); return $uri; }
/** * Renders a HTML Block with file information * * @param File $file * @return string */ protected function renderFileInformationContent(File $file = null) { /** @var LanguageService $lang */ $lang = $GLOBALS['LANG']; if ($file !== null) { $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => 150, 'height' => 150)); $previewImage = $processedFile->getPublicUrl(true); $content = ''; if ($file->isMissing()) { $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($file); $content .= $flashMessage->render(); } if ($previewImage) { $content .= '<img src="' . htmlspecialchars($previewImage) . '" ' . 'width="' . $processedFile->getProperty('width') . '" ' . 'height="' . $processedFile->getProperty('height') . '" ' . 'alt="" class="t3-tceforms-sysfile-imagepreview" />'; } $content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>'; $content .= ' (' . htmlspecialchars(GeneralUtility::formatSize($file->getSize())) . 'bytes)<br />'; $content .= BackendUtility::getProcessedValue('sys_file', 'type', $file->getType()) . ' (' . $file->getMimeType() . ')<br />'; $content .= $lang->sL('LLL:EXT:lang/locallang_misc.xlf:fileMetaDataLocation', true) . ': '; $content .= htmlspecialchars($file->getStorage()->getName()) . ' - ' . htmlspecialchars($file->getIdentifier()) . '<br />'; $content .= '<br />'; } else { $content = '<h2>' . $lang->sL('LLL:EXT:lang/locallang_misc.xlf:fileMetaErrorInvalidRecord', true) . '</h2>'; } return $content; }
/** * Checks if the given file can be processed by this Extractor * * @param Resource\File $file * @return boolean */ public function canProcess(Resource\File $file) { // TODO use MIME type instead of extension // tika.jar --list-supported-types -> cache supported types // compare to file's MIME type return in_array($file->getProperty('extension'), $this->supportedFileTypes); }
/** * This test accounts for an inconsistency in the Storage–Driver interface of FAL: The driver returns the MIME * type in a field "mimetype", while the file object and the database table use mime_type. * The test is placed in the test case for AbstractFile because the broken functionality resides there, though * it is only triggered when constructing a File instance with an index record. * * @test */ public function storageIsNotAskedForMimeTypeForPersistedRecord() { $mockedStorage = $this->getMockBuilder('TYPO3\\CMS\\Core\\Resource\\ResourceStorage')->disableOriginalConstructor()->getMock(); $mockedStorage->expects($this->never())->method('getFileInfoByIdentifier')->with('/foo', 'mimetype'); $subject = new File(array('identifier' => '/foo', 'mime_type' => 'my/mime-type'), $mockedStorage); $this->assertEquals('my/mime-type', $subject->getMimeType()); }
/** * 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()]; }
/** * Get helper class for given File * * @param File $file * @return bool|OnlineMediaHelperInterface */ public function getOnlineMediaHelper(File $file) { $registeredHelpers = $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['onlineMediaHelpers']; if (isset($registeredHelpers[$file->getExtension()])) { return GeneralUtility::makeInstance($registeredHelpers[$file->getExtension()], $file->getExtension()); } return false; }
/** * This test accounts for an inconsistency in the Storage–Driver interface of FAL: The driver returns the MIME * type in a field "mimetype", while the file object and the database table use mime_type. * The test is placed in the test case for AbstractFile because the broken functionality resides there, though * it is only triggered when constructing a File instance with an index record. * * @test */ public function storageIsNotAskedForMimeTypeForPersistedRecord() { /** @var ResourceStorage|\PHPUnit_Framework_MockObject_MockObject $mockedStorage */ $mockedStorage = $this->getMockBuilder(ResourceStorage::class)->disableOriginalConstructor()->getMock(); $mockedStorage->expects($this->never())->method('getFileInfoByIdentifier')->with('/foo', 'mimetype'); $subject = new File(array('identifier' => '/foo', 'mime_type' => 'my/mime-type'), $mockedStorage); $this->assertEquals('my/mime-type', $subject->getMimeType()); }
/** * Returns a default template. * * @param File $file * @return string */ protected function getDefaultTemplate(File $file) { $template = '%size Ko'; if ($file->getType() == File::FILETYPE_IMAGE) { $template = '%width x %height - ' . $template; } return $template; }
/** * Sets up this test case. */ protected function setUp() { $this->fileResourceMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array('toArray', 'getModificationTime', 'getExtension'), array(), '', FALSE); $this->folderResourceMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Folder', array('getIdentifier'), array(), '', FALSE); $this->mockFileProcessor = $this->getMock('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility', array('getErrorMessages'), array(), '', FALSE); $this->fileResourceMock->expects($this->any())->method('toArray')->will($this->returnValue(array('id' => 'foo'))); $this->fileResourceMock->expects($this->any())->method('getModificationTime')->will($this->returnValue(123456789)); $this->fileResourceMock->expects($this->any())->method('getExtension')->will($this->returnValue('html')); }
/** * Sets up this test case. */ protected function setUp() { $this->fileResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, array('toArray', 'getModificationTime', 'getExtension'), array(), '', false); $this->folderResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\Folder::class, array('getIdentifier'), array(), '', false); $this->mockFileProcessor = $this->getMock(\TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::class, array('getErrorMessages'), array(), '', false); $this->fileResourceMock->expects($this->any())->method('toArray')->will($this->returnValue(array('id' => 'foo'))); $this->fileResourceMock->expects($this->any())->method('getModificationTime')->will($this->returnValue(123456789)); $this->fileResourceMock->expects($this->any())->method('getExtension')->will($this->returnValue('html')); $this->request = new ServerRequest(); $this->response = new Response(); }
/** * Takes a file reference and extracts its meta data. * * @param \TYPO3\CMS\Core\Resource\File $file * @return array */ public function extractMetaData(File $file) { $localTempFilePath = $file->getForLocalProcessing(FALSE); $query = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Tika\\Service\\Tika\\SolrCellQuery', $localTempFilePath); $query->setExtractOnly(); $response = $this->solr->extract($query); $metaData = $this->solrResponseToArray($response[1]); $this->cleanupTempFile($localTempFilePath, $file); $this->log('Meta Data Extraction using Solr', array('file' => $file, 'solr connection' => (array) $this->solr, 'query' => (array) $query, 'response' => $response, 'meta data' => $metaData)); return $metaData; }
/** * Fixes a bug in TYPO3 6.2.0 that the properties metadata is not overlayed on localization. * * @param File $file * @return array */ public static function getFileArray(File $file) { $properties = $file->getProperties(); $stat = $file->getStorage()->getFileInfo($file); $array = $file->toArray(); foreach ($properties as $key => $value) { $array[$key] = $value; } foreach ($stat as $key => $value) { $array[$key] = $value; } return $array; }
/** * Resize image and garantees a minimum size for each dimension * @param File $file * @return File|ProcessedFile */ public function createProcessedThumbnail(File $file) { $minSize = 84; $width = (int) $file->getProperty('width'); $height = (int) $file->getProperty('height'); $ratio = $width / $height; if ($width > $height) { $configuration = ['maxWidth' => ceil($minSize * $ratio), 'height' => $minSize]; } else { $configuration = ['width' => $minSize, 'maxHeight' => ceil($minSize / $ratio)]; } $file = $file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $configuration); return $file; }
/** * Creates a magic image * * @param Resource\File $imageFileObject: the original image file * @param array $fileConfiguration (width, height) * @return Resource\ProcessedFile */ public function createMagicImage(Resource\File $imageFileObject, array $fileConfiguration) { // Process dimensions $maxWidth = MathUtility::forceIntegerInRange($fileConfiguration['width'], 0, $this->magicImageMaximumWidth); $maxHeight = MathUtility::forceIntegerInRange($fileConfiguration['height'], 0, $this->magicImageMaximumHeight); if (!$maxWidth) { $maxWidth = $this->magicImageMaximumWidth; } if (!$maxHeight) { $maxHeight = $this->magicImageMaximumHeight; } // Create the magic image $magicImage = $imageFileObject->process(Resource\ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, array('width' => $maxWidth . 'm', 'height' => $maxHeight . 'm')); return $magicImage; }
/** * 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; }
/** * 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; }
/** * Check file access for given FeGroups combination * * @param \TYPO3\CMS\Core\Resource\File $file * @param bool|array $userFeGroups FALSE = no login, array() fe groups of user * @return bool */ public function checkFileAccess($file, $userFeGroups) { // all files in public storage are accessible if ($file->getStorage()->isPublic()) { return true; // check folder access } elseif ($this->checkFolderRootLineAccess($file->getParentFolder(), $userFeGroups)) { // access to folder then check file privileges if present $feGroups = $file->getProperty('fe_groups'); if ($feGroups !== '') { return $this->matchFeGroupsWithFeUser($feGroups, $userFeGroups); } return true; } return false; }
/** * return file path * * @return string Filepath (f.e. /var/www/fileadmin/) */ public function getPath() { if ($this->file !== NULL) { return $this->file->getForLocalProcessing(FALSE); } else { return $this->fileInfo['path']; } }
/** * return file path * @return string Filepath (f.e. /var/www/fileadmin/) */ public function getPath() { if ($this->file !== null) { return $this->file->getForLocalProcessing(false); } else { return $this->fileInfo['path']; } }
/** * @return void */ public function testWithDataAndSourceCollection() { $this->file->expects($this->at(1))->method('process')->will($this->returnValue($this->processedFiles[1])); $this->file->expects($this->at(2))->method('process')->will($this->returnValue($this->processedFiles[2])); $this->file->expects($this->at(3))->method('process')->will($this->returnValue($this->processedFiles[0])); $this->imageRendererConfiguration->expects($this->once())->method('getSourceCollection')->will($this->returnValue([10 => ['width' => '360m', 'dataKey' => 'small'], 20 => ['width' => '720m', 'dataKey' => 'small-retina']])); $this->imageRendererConfiguration->expects($this->once())->method('getLayoutKey')->will($this->returnValue('data')); $this->assertEquals('<img src="image.jpg" alt="alt" title="title" data-small="image360.jpg" data-small-retina="image720.jpg" />', $this->imageRenderer->render($this->file, '1000', '1000', [])); }
/** * Does the actual image processing * * @return \TYPO3\CMS\Core\Resource\ProcessedFile */ protected function processImage() { if (strstr($this->width . $this->height, 'm')) { $max = 'm'; } else { $max = ''; } $this->height = MathUtility::forceIntegerInRange($this->height, 0); $this->width = MathUtility::forceIntegerInRange($this->width, 0) . $max; $processingConfiguration = array('width' => $this->width, 'height' => $this->height, 'frame' => $this->frame); return $this->file->process('Image.CropScaleMask', $processingConfiguration); }
/** * Generates a preview for a file * * @param File $file The source file * @param array $configuration Processing configuration * @param string $targetFilePath Output file path * @return array|NULL */ protected function generatePreviewFromFile(File $file, array $configuration, $targetFilePath) { $originalFileName = $file->getForLocalProcessing(FALSE); // Check file extension if ($file->getType() != File::FILETYPE_IMAGE && !GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $file->getExtension())) { // Create a default image $this->processor->getTemporaryImageWithText($targetFilePath, 'Not imagefile!', 'No ext!', $file->getName()); } else { // Create the temporary file if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) { $parameters = '-sample ' . $configuration['width'] . 'x' . $configuration['height'] . ' ' . $this->processor->wrapFileName($originalFileName) . '[0] ' . $this->processor->wrapFileName($targetFilePath); $cmd = GeneralUtility::imageMagickCommand('convert', $parameters) . ' 2>&1'; CommandUtility::exec($cmd); if (!file_exists($targetFilePath)) { // Create a error gif $this->processor->getTemporaryImageWithText($targetFilePath, 'No thumb', 'generated!', $file->getName()); } } } return array('filePath' => $targetFilePath); }
/** * 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); }
/** * 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 = array()) { $filename = $file->getForLocalProcessing(); $metadata = array('unit' => 'px'); // Parse basic metadata from getimagesize, write additional metadata to $info $imageSize = getimagesize($filename, $info); if (isset($imageSize['channels'])) { $metadata['color_space'] = $this->getColorSpace($imageSize['channels']); } $this->extractExifMetaData($metadata, $filename); $this->extractIptcMetaData($metadata, $info); return $this->getUnicodeUtility()->convertValues($metadata); }
/** * @test * @todo Old code getAvailableProperties() needs to be replaced by current behaviour */ public function propertiesPassedToConstructorAreAvailableViaGenericGetter() { $this->markTestSkipped('TYPO3\\CMS\\Core\\Resource\\File::getAvailableProperties() does not exist'); $properties = array($this->getUniqueId() => $this->getUniqueId(), $this->getUniqueId() => $this->getUniqueId(), 'uid' => 1); $fixture = new \TYPO3\CMS\Core\Resource\File($properties, $this->storageMock); $availablePropertiesBackup = \TYPO3\CMS\Core\Resource\File::getAvailableProperties(); \TYPO3\CMS\Core\Resource\File::setAvailableProperties(array_keys($properties)); foreach ($properties as $key => $value) { $this->assertTrue($fixture->hasProperty($key)); $this->assertEquals($value, $fixture->getProperty($key)); } $this->assertFalse($fixture->hasProperty($this->getUniqueId())); \TYPO3\CMS\Core\Resource\File::setAvailableProperties($availablePropertiesBackup); $this->setExpectedException('InvalidArgumentException', '', 1314226805); $fixture->getProperty($this->getUniqueId()); }
/** * 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() { 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); }
/** * 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); }
/** * 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; }