Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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, ['width' => 150, 'height' => 150]);
         $previewImage = $processedFile->getPublicUrl(true);
         $content = '';
         if ($file->isMissing()) {
             $content .= '<span class="label label-danger label-space-right">' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing')) . '</span>';
         }
         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 .= htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:fileMetaDataLocation')) . ': ';
         $content .= htmlspecialchars($file->getStorage()->getName()) . ' - ' . htmlspecialchars($file->getIdentifier()) . '<br />';
         $content .= '<br />';
     } else {
         $content = '<h2>' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:fileMetaErrorInvalidRecord')) . '</h2>';
     }
     return $content;
 }
Пример #3
0
 /**
  * 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;
 }
Пример #4
0
 /**
  * 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;
 }
Пример #5
0
 /**
  * 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);
 }
Пример #6
0
 /**
  * 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);
     }
 }
Пример #7
0
 /**
  * Create the thumbnail
  * Will exit before return if all is well.
  *
  * @return void
  * @todo Define visibility
  */
 public function main()
 {
     // Clean output buffer to ensure no extraneous output exists
     ob_clean();
     // If file exists, we make a thumbnail of the file.
     if (is_object($this->image)) {
         // Check file extension:
         if ($this->image->getExtension() == 'ttf') {
             // Make font preview... (will not return)
             $this->fontGif($this->image);
         } elseif ($this->image->getType() != File::FILETYPE_IMAGE && !GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $this->image->getExtension())) {
             $this->errorGif('Not imagefile!', 'No ext!', $this->image->getName());
         }
         // ... so we passed the extension test meaning that we are going to make a thumbnail here:
         // default
         if (!$this->size) {
             $this->size = $this->sizeDefault;
         }
         // I added extra check, so that the size input option could not be fooled to pass other values.
         // That means the value is exploded, evaluated to an integer and the imploded to [value]x[value].
         // Furthermore you can specify: size=340 and it'll be translated to 340x340.
         // explodes the input size (and if no "x" is found this will add size again so it is the same for both dimensions)
         $sizeParts = explode('x', $this->size . 'x' . $this->size);
         // Cleaning it up, only two parameters now.
         $sizeParts = array(MathUtility::forceIntegerInRange($sizeParts[0], 1, 1000), MathUtility::forceIntegerInRange($sizeParts[1], 1, 1000));
         // Imploding the cleaned size-value back to the internal variable
         $this->size = implode('x', $sizeParts);
         // Getting max value
         $sizeMax = max($sizeParts);
         // Init
         $outpath = PATH_site . $this->outdir;
         // Should be - ? 'png' : 'gif' - , but doesn't work (ImageMagick prob.?)
         // René: png work for me
         $thmMode = MathUtility::forceIntegerInRange($GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails_png'], 0);
         $outext = $this->image->getExtension() != 'jpg' || $thmMode & 2 ? $thmMode & 1 ? 'png' : 'gif' : 'jpg';
         $outfile = 'tmb_' . substr(md5($this->image->getName() . $this->mtime . $this->size), 0, 10) . '.' . $outext;
         $this->output = $outpath . $outfile;
         if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
             // If thumbnail does not exist, we generate it
             if (!file_exists($this->output)) {
                 $parameters = '-sample ' . $this->size . ' ' . $this->wrapFileName($this->image->getForLocalProcessing(FALSE)) . '[0] ' . $this->wrapFileName($this->output);
                 $cmd = GeneralUtility::imageMagickCommand('convert', $parameters);
                 \TYPO3\CMS\Core\Utility\CommandUtility::exec($cmd);
                 if (!file_exists($this->output)) {
                     $this->errorGif('No thumb', 'generated!', $this->image->getName());
                 } else {
                     GeneralUtility::fixPermissions($this->output);
                 }
             }
             // The thumbnail is read and output to the browser
             if ($fd = @fopen($this->output, 'rb')) {
                 $fileModificationTime = filemtime($this->output);
                 header('Content-Type: image/' . ($outext === 'jpg' ? 'jpeg' : $outext));
                 header('Last-Modified: ' . date('r', $fileModificationTime));
                 header('ETag: ' . md5($this->output) . '-' . $fileModificationTime);
                 // Expiration time is chosen arbitrary to 1 month
                 header('Expires: ' . date('r', $fileModificationTime + 30 * 24 * 60 * 60));
                 fpassthru($fd);
                 fclose($fd);
             } else {
                 $this->errorGif('Read problem!', '', $this->output);
             }
         } else {
             die;
         }
     } else {
         $this->errorGif('No valid', 'inputfile!', basename($this->image));
     }
 }
Пример #8
0
 /**
  * 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
         $graphicalFunctions = GeneralUtility::makeInstance(GraphicalFunctions::class);
         $graphicalFunctions->getTemporaryImageWithText($targetFilePath, 'Not imagefile!', 'No ext!', $file->getName());
         $result = array('filePath' => $targetFilePath);
     } elseif ($file->getExtension() === 'svg') {
         /** @var $gifBuilder \TYPO3\CMS\Frontend\Imaging\GifBuilder */
         $gifBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class);
         $gifBuilder->init();
         $gifBuilder->absPrefix = PATH_site;
         $info = $gifBuilder->getImageDimensions($originalFileName);
         $newInfo = $gifBuilder->getImageScale($info, $configuration['width'], $configuration['height'], array());
         $result = array('width' => $newInfo[0], 'height' => $newInfo[1], 'filePath' => '');
     } else {
         // Create the temporary file
         if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
             $parameters = '-sample ' . $configuration['width'] . 'x' . $configuration['height'] . ' ' . CommandUtility::escapeShellArgument($originalFileName) . '[0] ' . CommandUtility::escapeShellArgument($targetFilePath);
             $cmd = GeneralUtility::imageMagickCommand('convert', $parameters) . ' 2>&1';
             CommandUtility::exec($cmd);
             if (!file_exists($targetFilePath)) {
                 // Create a error gif
                 $graphicalFunctions = GeneralUtility::makeInstance(GraphicalFunctions::class);
                 $graphicalFunctions->getTemporaryImageWithText($targetFilePath, 'No thumb', 'generated!', $file->getName());
             }
         }
         $result = array('filePath' => $targetFilePath);
     }
     return $result;
 }
Пример #9
0
 /**
  * Returns the fileType of this file
  *
  * @return int $fileType
  */
 public function getType()
 {
     return (int) $this->originalFile->getType();
 }
Пример #10
0
 /**
  * Return a new target folder when moving file from one storage to another.
  *
  * @param ResourceStorage $storage
  * @param File $file
  * @return \TYPO3\CMS\Core\Resource\Folder
  */
 public function getDefaultFolderInStorage(ResourceStorage $storage, File $file)
 {
     // default is the root level
     $folder = $storage->getRootLevelFolder();
     // Retrieve storage record and a possible configured mount point.
     $storageRecord = $storage->getStorageRecord();
     $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $file->getType()];
     if ($mountPointIdentifier > 0) {
         // We don't have a Mount Point repository in FAL, so query the database directly.
         $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('path', 'sys_filemounts', 'deleted = 0 AND uid = ' . $mountPointIdentifier);
         if (!empty($record['path'])) {
             $folder = $storage->getFolder($record['path']);
         }
     }
     return $folder;
 }
Пример #11
0
 /**
  * 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);
         $metaData = array();
         list($metaData['width'], $metaData['height']) = getimagesize($rawFileLocation);
         $this->getMetaDataRepository()->update($fileObject->getUid(), $metaData);
         $fileObject->_updateMetaDataProperties($metaData);
     }
 }