/**
  * 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'];
     }
 }
    /**
     * Main function. Will generate the information to display for the item
     * set internally.
     *
     * @param string $returnLinkTag <a> tag closing/returning.
     * @return void
     * @todo Define visibility
     */
    public function renderFileInfo($returnLinkTag)
    {
        $fileExtension = $this->fileObject->getExtension();
        $code = '<div class="fileInfoContainer">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileExtension) . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.file', TRUE) . ':</strong> ' . $this->fileObject->getName() . '&nbsp;&nbsp;' . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.filesize') . ':</strong> ' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($this->fileObject->getSize()) . '</div>
			';
        $this->content .= $this->doc->section('', $code);
        $this->content .= $this->doc->divider(2);
        // If the file was an image...
        // @todo: add this check in the domain model, or in the processing folder
        if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
            // @todo: find a way to make getimagesize part of the t3lib_file object
            $imgInfo = @getimagesize($this->fileObject->getForLocalProcessing(FALSE));
            $thumbUrl = $this->fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => '150m', 'height' => '150m'))->getPublicUrl(TRUE);
            $code = '<div class="fileInfoContainer fileDimensions">' . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.dimensions') . ':</strong> ' . $imgInfo[0] . 'x' . $imgInfo[1] . ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.pixels') . '</div>';
            $code .= '<br />
				<div align="center">' . $returnLinkTag . '<img src="' . $thumbUrl . '" alt="' . htmlspecialchars(trim($this->fileObject->getName())) . '" title="' . htmlspecialchars(trim($this->fileObject->getName())) . '" /></a></div>';
            $this->content .= $this->doc->section('', $code);
        } elseif ($fileExtension == 'ttf') {
            $thumbUrl = $this->fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => '530m', 'height' => '600m'))->getPublicUrl(TRUE);
            $thumb = '<br />
				<div align="center">' . $returnLinkTag . '<img src="' . $thumbUrl . '" border="0" title="' . htmlspecialchars(trim($this->fileObject->getName())) . '" alt="" /></a></div>';
            $this->content .= $this->doc->section('', $thumb);
        }
        // Traverse the list of fields to display for the record:
        $tableRows = array();
        $showRecordFieldList = $GLOBALS['TCA'][$this->table]['interface']['showRecordFieldList'];
        $fieldList = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $showRecordFieldList, TRUE);
        foreach ($fieldList as $name) {
            $name = trim($name);
            if (!isset($GLOBALS['TCA'][$this->table]['columns'][$name])) {
                continue;
            }
            $isExcluded = !(!$GLOBALS['TCA'][$this->table]['columns'][$name]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $this->table . ':' . $name));
            if ($isExcluded) {
                continue;
            }
            $uid = $this->row['uid'];
            $itemValue = \TYPO3\CMS\Backend\Utility\BackendUtility::getProcessedValue($this->table, $name, $this->row[$name], 0, 0, FALSE, $uid);
            $itemLabel = $GLOBALS['LANG']->sL(\TYPO3\CMS\Backend\Utility\BackendUtility::getItemLabel($this->table, $name), 1);
            $tableRows[] = '
				<tr>
					<td class="t3-col-header">' . $itemLabel . '</td>
					<td>' . htmlspecialchars($itemValue) . '</td>
				</tr>';
        }
        // Create table from the information:
        $tableCode = '
			<table border="0" cellpadding="0" cellspacing="0" id="typo3-showitem" class="t3-table-info">
				' . implode('', $tableRows) . '
			</table>';
        $this->content .= $this->doc->section('', $tableCode);
        // References:
        if ($this->fileObject->isIndexed()) {
            $header = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.referencesToThisItem');
            $this->content .= $this->doc->section($header, $this->makeRef('_FILE', $this->fileObject));
        }
    }
Пример #4
0
 /**
  * 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;
 }
Пример #5
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;
 }
Пример #6
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);
 }
 /**
  * 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);
 }
Пример #8
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));
     }
 }
Пример #9
0
 /**
  * Takes a file reference and detects its content's language.
  *
  * @param \TYPO3\CMS\Core\Resource\File $file
  * @return string Language ISO code
  */
 public function detectLanguageFromFile(File $file)
 {
     $localTempFilePath = $file->getForLocalProcessing(FALSE);
     $language = $this->detectLanguageFromLocalFile($localTempFilePath);
     $this->cleanupTempFile($localTempFilePath, $file);
     return $language;
 }
Пример #10
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);
     }
 }
Пример #11
0
 /**
  * Returns a path to a local version of this file to process it locally (e.g. with some system tool).
  * If the file is normally located on a remote storages, this creates a local copy.
  * If the file is already on the local system, this only makes a new copy if $writable is set to TRUE.
  *
  * @param bool $writable Set this to FALSE if you only want to do read operations on the file.
  * @return string
  */
 public function getForLocalProcessing($writable = true)
 {
     return $this->originalFile->getForLocalProcessing($writable);
 }
Пример #12
0
 /**
  * Insert a plain image
  *
  * @param \TYPO3\CMS\Core\Resource\File $fileObject: the image file
  * @param 	string		$altText: text for the alt attribute of the image
  * @param 	string		$titleText: text for the title attribute of the image
  * @param 	string		$additionalParams: text representing more HTML attributes to be added on the img tag
  * @return 	void
  */
 public function insertPlainImage(Resource\File $fileObject, $altText = '', $titleText = '', $additionalParams = '')
 {
     $width = $fileObject->getProperty('width');
     $height = $fileObject->getProperty('height');
     if (!$width || !$height) {
         $filePath = $fileObject->getForLocalProcessing(FALSE);
         $imageInfo = @getimagesize($filePath);
         $width = $imageInfo[0];
         $height = $imageInfo[1];
     }
     $imageUrl = $fileObject->getPublicUrl();
     // If file is local, make the url absolute
     if (substr($imageUrl, 0, 4) !== 'http') {
         $imageUrl = $this->siteURL . $imageUrl;
     }
     $this->imageInsertJS($imageUrl, $width, $height, $altText, $titleText, $additionalParams);
 }
 /**
  * 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;
 }
 /**
  * Updates the dimension (height, width) and duration metadata of the specified media file in FAL
  *
  * @param  \TYPO3\CMS\Core\Resource\File $file  FAL record
  * @return void
  */
 protected function setFileMetadata(\TYPO3\CMS\Core\Resource\File $file)
 {
     // Get file for local processing
     $localFile = $file->getForLocalProcessing(FALSE);
     // Fetch media information
     $parser = new \PHPVideoToolkit\MediaParser();
     $fileInfo = $parser->getFileInformation($localFile);
     // Collect relevant media information
     $fileMetadata = array();
     $fileMetadata['duration'] = $fileInfo['duration']->total_seconds;
     if (isset($fileInfo['video']['dimensions'])) {
         $fileMetadata['height'] = $fileInfo['video']['dimensions']['height'];
         $fileMetadata['width'] = $fileInfo['video']['dimensions']['width'];
     }
     // Update metadata of FAL record
     if (!empty($fileMetadata)) {
         $file->_updateMetaDataProperties($fileMetadata);
         $this->metaDataRepository->update($file->getUid(), $fileMetadata);
     }
 }
Пример #15
0
 /**
  * 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())
 {
     $metadata = array();
     $this->extractPdfMetaData($metadata, $file->getForLocalProcessing());
     return $metadata;
 }
Пример #16
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);
     }
 }
Пример #17
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;
 }