/** * Checks if the ProcessedFile needs reprocessing * * @return bool */ public function needsReprocessing() { $fileMustBeRecreated = false; // if original is missing we can not reprocess the file if ($this->originalFile->isMissing()) { return false; } // processedFile does not exist if (!$this->usesOriginalFile() && !$this->exists()) { $fileMustBeRecreated = true; } // hash does not match if (array_key_exists('checksum', $this->properties) && $this->calculateChecksum() !== $this->properties['checksum']) { $fileMustBeRecreated = true; } // original file changed if ($this->originalFile->getSha1() !== $this->originalFileSha1) { $fileMustBeRecreated = true; } if (!array_key_exists('uid', $this->properties)) { $fileMustBeRecreated = true; } // remove outdated file if ($fileMustBeRecreated && $this->exists()) { $this->delete(); } return $fileMustBeRecreated; }
/** * Render preview for current record * * @return string */ protected function renderPreview() { // Perhaps @TODO in future: Also display preview for records - without fileObject if (!$this->fileObject) { return; } $imageTag = ''; $downloadLink = ''; // check if file is marked as missing if ($this->fileObject->isMissing()) { $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($this->fileObject); $imageTag .= $flashMessage->render(); } else { $fileExtension = $this->fileObject->getExtension(); $thumbUrl = ''; if (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) { $thumbUrl = $this->fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => '400m', 'height' => '400m'))->getPublicUrl(TRUE); } // Create thumbnail image? if ($thumbUrl) { $imageTag .= '<img src="' . $thumbUrl . '" ' . 'alt="' . htmlspecialchars(trim($this->fileObject->getName())) . '" ' . 'title="' . htmlspecialchars(trim($this->fileObject->getName())) . '" />'; } // Display download link? $url = $this->fileObject->getPublicUrl(TRUE); if ($url) { $downloadLink .= '<a href="' . htmlspecialchars($url) . '" target="_blank" class="t3-button">' . IconUtility::getSpriteIcon('actions-edit-download') . ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:download', TRUE) . '</a>'; } } return ($imageTag ? '<p>' . $imageTag . '</p>' : '') . ($downloadLink ? '<p>' . $downloadLink . '</p>' : ''); }
/** * 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; }
/** * Get preview for current record * * @return array */ protected function getPreview() : array { $preview = []; // Perhaps @todo in future: Also display preview for records - without fileObject if (!$this->fileObject) { return $preview; } // check if file is marked as missing if ($this->fileObject->isMissing()) { $preview['missingFile'] = $this->fileObject->getName(); } else { /** @var \TYPO3\CMS\Core\Resource\Rendering\RendererRegistry $rendererRegistry */ $rendererRegistry = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Rendering\RendererRegistry::class); $fileRenderer = $rendererRegistry->getRenderer($this->fileObject); $fileExtension = $this->fileObject->getExtension(); $preview['url'] = $this->fileObject->getPublicUrl(true); $width = '590m'; $heigth = '400m'; // Check if there is a FileRenderer if ($fileRenderer !== null) { $preview['fileRenderer'] = $fileRenderer->render($this->fileObject, $width, $heigth, [], true); // else check if we can create an Image preview } elseif (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) { $preview['fileObject'] = $this->fileObject; $preview['width'] = $width; $preview['heigth'] = $heigth; } } return $preview; }
/** * Render preview for current record * * @return string */ protected function renderPreview() { // Perhaps @todo in future: Also display preview for records - without fileObject if (!$this->fileObject) { return ''; } $previewTag = ''; $showLink = ''; // check if file is marked as missing if ($this->fileObject->isMissing()) { $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($this->fileObject); $previewTag .= $flashMessage->render(); } else { /** @var \TYPO3\CMS\Core\Resource\Rendering\RendererRegistry $rendererRegistry */ $rendererRegistry = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Rendering\RendererRegistry::class); $fileRenderer = $rendererRegistry->getRenderer($this->fileObject); $fileExtension = $this->fileObject->getExtension(); $url = $this->fileObject->getPublicUrl(true); // Check if there is a FileRenderer if ($fileRenderer !== null) { $previewTag = $fileRenderer->render($this->fileObject, '590m', '400m', array(), true); // else check if we can create an Image preview } elseif (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) { $processedFile = $this->fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => '590m', 'height' => '400m')); // Create thumbnail image? if ($processedFile) { $thumbUrl = $processedFile->getPublicUrl(true); $previewTag .= '<img class="img-responsive img-thumbnail" src="' . $thumbUrl . '" ' . 'width="' . $processedFile->getProperty('width') . '" ' . 'height="' . $processedFile->getProperty('height') . '" ' . 'alt="' . htmlspecialchars(trim($this->fileObject->getName())) . '" ' . 'title="' . htmlspecialchars(trim($this->fileObject->getName())) . '" />'; } } // Show if ($url) { $showLink .= ' <a class="btn btn-primary" href="' . htmlspecialchars($url) . '" target="_blank"> ' . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render() . ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.show', true) . ' </a>'; } } return ($previewTag ? '<p>' . $previewTag . '</p>' : '') . ($showLink ? '<p>' . $showLink . '</p>' : ''); }