/**
  * Create a link to a file that forces a download
  *
  * @param \TYPO3\CMS\Core\Resource\FileInterface $file
  * @param bool $uriOnly
  * @return string
  */
 public function render(\TYPO3\CMS\Core\Resource\FileInterface $file, $uriOnly = FALSE)
 {
     $queryParameterArray = array('eID' => 'dumpFile', 't' => '');
     if ($file instanceof \TYPO3\CMS\Core\Resource\File) {
         $queryParameterArray['f'] = $file->getUid();
         $queryParameterArray['t'] = 'f';
     } elseif ($file instanceof \TYPO3\CMS\Core\Resource\ProcessedFile) {
         $queryParameterArray['p'] = $file->getUid();
         $queryParameterArray['t'] = 'p';
     }
     $queryParameterArray['token'] = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac(implode('|', $queryParameterArray), 'resourceStorageDumpFile');
     $queryParameterArray['download'] = '';
     $uri = 'index.php?' . str_replace('+', '%20', http_build_query($queryParameterArray));
     // Add absRefPrefix
     if (!empty($GLOBALS['TSFE'])) {
         $uri = $GLOBALS['TSFE']->absRefPrefix . $uri;
     }
     if ($uriOnly) {
         return $uri;
     }
     $this->tag->addAttribute('href', $uri);
     $this->tag->setContent($this->renderChildren());
     $this->tag->forceClosingTag(TRUE);
     return $this->tag->render();
 }
Exemple #2
0
 /**
  * Render for given File(Reference) HTML output
  *
  * @param FileInterface $file
  * @param int|string $width TYPO3 known format; examples: 220, 200m or 200c
  * @param int|string $height TYPO3 known format; examples: 220, 200m or 200c
  * @param array $options controls = TRUE/FALSE (default TRUE), autoplay = TRUE/FALSE (default FALSE), loop = TRUE/FALSE (default FALSE)
  * @param bool $usedPathsRelativeToCurrentScript See $file->getPublicUrl()
  * @return string
  */
 public function render(FileInterface $file, $width, $height, array $options = [], $usedPathsRelativeToCurrentScript = false)
 {
     // If autoplay isn't set manually check if $file is a FileReference take autoplay from there
     if (!isset($options['autoplay']) && $file instanceof FileReference) {
         $autoplay = $file->getProperty('autoplay');
         if ($autoplay !== null) {
             $options['autoplay'] = $autoplay;
         }
     }
     $attributes = [];
     if ((int) $width > 0) {
         $attributes[] = 'width="' . (int) $width . '"';
     }
     if ((int) $height > 0) {
         $attributes[] = 'height="' . (int) $height . '"';
     }
     if (!isset($options['controls']) || !empty($options['controls'])) {
         $attributes[] = 'controls';
     }
     if (!empty($options['autoplay'])) {
         $attributes[] = 'autoplay';
     }
     if (!empty($options['muted'])) {
         $attributes[] = 'muted';
     }
     if (!empty($options['loop'])) {
         $attributes[] = 'loop';
     }
     foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick'] as $key) {
         if (!empty($options[$key])) {
             $attributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"';
         }
     }
     return sprintf('<video%s><source src="%s" type="%s"></video>', empty($attributes) ? '' : ' ' . implode(' ', $attributes), htmlspecialchars($file->getPublicUrl($usedPathsRelativeToCurrentScript)), $file->getMimeType());
 }
 /**
  * When retrieving the width for a media file
  * a possible cropping needs to be taken into account.
  *
  * @param FileInterface $fileObject
  * @return int
  */
 protected function getCroppedWidth(FileInterface $fileObject)
 {
     if (!$fileObject->hasProperty('crop') || empty($fileObject->getProperty('crop'))) {
         return $fileObject->getProperty('width');
     }
     $croppingConfiguration = json_decode($fileObject->getProperty('crop'), true);
     return (int) $croppingConfiguration['width'];
 }
 /**
  * When retrieving the height or width for a media file
  * a possible cropping needs to be taken into account.
  *
  * @param  FileInterface $fileObject
  * @param  string        $dimensionalProperty 'width' or 'height'
  * @return int
  */
 protected function getCroppedProperty(FileInterface $fileObject, $dimensionalProperty)
 {
     if (!$fileObject->hasProperty('crop') || empty($fileObject->getProperty('crop'))) {
         return $fileObject->getProperty($dimensionalProperty);
     }
     $croppingConfiguration = json_decode($fileObject->getProperty('crop'), true);
     return (int) $croppingConfiguration[$dimensionalProperty];
 }
Exemple #5
0
 /**
  * Get public url of image depending on the environment
  *
  * @param FileInterface $image
  * @return string
  * @api
  */
 public function getImageUri(FileInterface $image)
 {
     if ($this->environmentService->isEnvironmentInFrontendMode()) {
         $uriPrefix = $GLOBALS['TSFE']->absRefPrefix;
     } else {
         $uriPrefix = '../';
     }
     return $uriPrefix . $image->getPublicUrl();
 }
 public function populateMetadata(\TYPO3\CMS\Core\Resource\FileInterface $file, \TYPO3\CMS\Core\Resource\Folder $folder)
 {
     $qualities = GeneralUtility::makeInstance(CalculateService::class)->quality($file->getUid());
     $message = '';
     foreach ($qualities as $key => $value) {
         $message .= $key . ' => ' . $value . "\n";
     }
     $this->flash($message);
 }
Exemple #7
0
 /**
  * Takes a file reference and extracts its meta data.
  *
  * @param \TYPO3\CMS\Core\Resource\FileInterface $file
  * @return array
  */
 public function extractMetaData(FileInterface $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;
 }
Exemple #8
0
 /**
  * Get public url of image depending on the environment
  *
  * @param FileInterface $image
  * @return string
  * @api
  */
 public function getImageUri(FileInterface $image)
 {
     $imageUrl = $image->getPublicUrl();
     // no prefix in case of an already fully qualified URL (having a schema)
     if (strpos($imageUrl, '://')) {
         $uriPrefix = '';
     } elseif ($this->environmentService->isEnvironmentInFrontendMode()) {
         $uriPrefix = $GLOBALS['TSFE']->absRefPrefix;
     } else {
         $uriPrefix = '../';
     }
     return $uriPrefix . $imageUrl;
 }
 /**
  * Render for given File(Reference) HTML output
  *
  * @param FileInterface $file
  * @param int|string $width TYPO3 known format; examples: 220, 200m or 200c
  * @param int|string $height TYPO3 known format; examples: 220, 200m or 200c
  * @param array $options controls = TRUE/FALSE (default TRUE), autoplay = TRUE/FALSE (default FALSE), loop = TRUE/FALSE (default FALSE)
  * @param bool $usedPathsRelativeToCurrentScript See $file->getPublicUrl()
  * @return string
  */
 public function render(FileInterface $file, $width, $height, array $options = array(), $usedPathsRelativeToCurrentScript = FALSE)
 {
     $additionalAttributes = array();
     if (!isset($options['controls']) || !empty($options['controls'])) {
         $additionalAttributes[] = 'controls';
     }
     if (!empty($options['autoplay'])) {
         $additionalAttributes[] = 'autoplay';
     }
     if (!empty($options['loop'])) {
         $additionalAttributes[] = 'loop';
     }
     return sprintf('<video width="%d" height="%d"%s><source src="%s" type="%s"></video>', (int) $width, (int) $height, empty($additionalAttributes) ? '' : ' ' . implode(' ', $additionalAttributes), htmlspecialchars($file->getPublicUrl($usedPathsRelativeToCurrentScript)), $file->getMimeType());
 }
Exemple #10
0
 /**
  * Get public url of image depending on the environment
  *
  * @param FileInterface $image
  * @return string
  * @api
  */
 public function getImageUri(FileInterface $image)
 {
     $imageUrl = $image->getPublicUrl();
     // no prefix in case of an already fully qualified URL (having a schema)
     // We need to fix the dection for PHP 5.4.6 and below as the host detection is broken
     if (parse_url($imageUrl, PHP_URL_HOST) !== NULL || strpos($imageUrl, '//') === 0) {
         $uriPrefix = '';
     } elseif ($this->environmentService->isEnvironmentInFrontendMode()) {
         $uriPrefix = $GLOBALS['TSFE']->absRefPrefix;
     } else {
         $uriPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
     }
     return $uriPrefix . $imageUrl;
 }
 /**
  * The actual text extraction.
  *
  * @param FileInterface $file
  * @return string
  */
 public function extractText(FileInterface $file)
 {
     $localTempFile = $file->getForLocalProcessing(false);
     // extract text
     $content = file_get_contents($localTempFile);
     // In case of remote storage, the temporary copy of the
     // original file in typo3temp must be removed
     // Simply compare the filenames, because the filename is so unique that
     // it is nearly impossible to have a file with this name in a storage
     if (PathUtility::basename($localTempFile) !== $file->getName()) {
         unlink($localTempFile);
     }
     return $content;
 }
 /**
  * Render for given File(Reference) html output
  *
  * @param FileInterface $file
  * @param int|string $width TYPO3 known format; examples: 220, 200m or 200c
  * @param int|string $height TYPO3 known format; examples: 220, 200m or 200c
  * @param array $options
  * @param bool $usedPathsRelativeToCurrentScript See $file->getPublicUrl()
  * @return string
  */
 public function render(FileInterface $file, $width, $height, array $options = null, $usedPathsRelativeToCurrentScript = false)
 {
     if ($file instanceof FileReference) {
         $autoplay = $file->getProperty('autoplay');
         if ($autoplay !== null) {
             $options['autoplay'] = $autoplay;
         }
     }
     $urlParams = array();
     if (!empty($options['autoplay'])) {
         $urlParams[] = 'auto_play=1';
     }
     if ($file instanceof FileReference) {
         $orgFile = $file->getOriginalFile();
     } else {
         $orgFile = $file;
     }
     $soundCloudId = $this->getOnlineMediaHelper($file)->getOnlineMediaId($orgFile);
     $src = sprintf('//w.soundcloud.com/player/?url=%s?%s', urlencode('https://api.soundcloud.com/tracks/' . $soundCloudId), implode('&amp;', $urlParams));
     foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick'] as $key) {
         if (!empty($options[$key])) {
             $attributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"';
         }
     }
     return sprintf('<iframe src="%s"%s></iframe>', $src, empty($attributes) ? '' : ' ' . implode(' ', $attributes));
 }
 /**
  * Creates a magic image
  *
  * @param \TYPO3\CMS\Core\Resource\FileInterface $imageFileObject: the original image file
  * @param array $fileConfiguration (width, height, maxW, maxH)
  * @param string $targetFolderCombinedIdentifier: target folder combined identifier
  * @return \TYPO3\CMS\Core\Resource\FileInterface
  */
 public function createMagicImage(\TYPO3\CMS\Core\Resource\FileInterface $imageFileObject, array $fileConfiguration, $targetFolderCombinedIdentifier)
 {
     $magicImage = NULL;
     // Get file for processing
     $imageFilePath = $imageFileObject->getForLocalProcessing(TRUE);
     // Process dimensions
     $maxWidth = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($fileConfiguration['width'], 0, $fileConfiguration['maxW']);
     $maxHeight = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($fileConfiguration['height'], 0, $fileConfiguration['maxH']);
     if (!$maxWidth) {
         $maxWidth = $fileConfiguration['maxW'];
     }
     if (!$maxHeight) {
         $maxHeight = $fileConfiguration['maxH'];
     }
     // Create the magic image
     $magicImageInfo = $this->getImageObject()->imageMagickConvert($imageFilePath, 'WEB', $maxWidth . 'm', $maxHeight . 'm');
     if ($magicImageInfo[3]) {
         $targetFileName = 'RTEmagicC_' . pathInfo($imageFileObject->getName(), PATHINFO_FILENAME) . '.' . pathinfo($magicImageInfo[3], PATHINFO_EXTENSION);
         $magicFolder = $this->getMagicFolder($targetFolderCombinedIdentifier);
         if ($magicFolder instanceof \TYPO3\CMS\Core\Resource\Folder) {
             $magicImage = $magicFolder->addFile($magicImageInfo[3], $targetFileName, 'changeName');
         }
     }
     return $magicImage;
 }
 /**
  * Generate public url for file
  *
  * @param Resource\ResourceStorage $storage
  * @param Resource\Driver\DriverInterface $driver
  * @param Resource\FileInterface $file
  * @param $relativeToCurrentScript
  * @param array $urlData
  * @return void
  */
 public function generatePublicUrl(Resource\ResourceStorage $storage, Resource\Driver\DriverInterface $driver, Resource\FileInterface $file, $relativeToCurrentScript, array $urlData)
 {
     // We only render special links for non-public files
     if ($this->enabled && !$storage->isPublic()) {
         $queryParameterArray = array('eID' => 'dumpFile', 't' => '');
         if ($file instanceof Resource\File) {
             $queryParameterArray['f'] = $file->getUid();
             $queryParameterArray['t'] = 'f';
         } elseif ($file instanceof Resource\ProcessedFile) {
             $queryParameterArray['p'] = $file->getUid();
             $queryParameterArray['t'] = 'p';
         }
         $queryParameterArray['token'] = GeneralUtility::hmac(implode('|', $queryParameterArray), 'BeResourceStorageDumpFile');
         // $urlData['publicUrl'] is passed by reference, so we can change that here and the value will be taken into account
         $urlData['publicUrl'] = BackendUtility::getAjaxUrl('FalSecuredownload::publicUrl', $queryParameterArray);
     }
 }
 /**
  * Get the cropped image by File Object
  *
  * @param FileInterface $file
  * @param string        $ratio
  *
  * @return string The new filename
  */
 public function getCroppedImageSrcByFile(FileInterface $file, $ratio)
 {
     $absoluteImageName = GeneralUtility::getFileAbsFileName($file->getPublicUrl());
     $focusPointX = MathUtility::forceIntegerInRange((int) $file->getProperty('focus_point_x'), -100, 100, 0);
     $focusPointY = MathUtility::forceIntegerInRange((int) $file->getProperty('focus_point_y'), -100, 100, 0);
     $tempImageFolder = 'typo3temp/focuscrop/';
     $tempImageName = $tempImageFolder . $file->getSha1() . '-' . str_replace(':', '-', $ratio) . '-' . $focusPointX . '-' . $focusPointY . '.' . $file->getExtension();
     $absoluteTempImageName = GeneralUtility::getFileAbsFileName($tempImageName);
     if (is_file($absoluteTempImageName)) {
         return $tempImageName;
     }
     $absoluteTempImageFolder = GeneralUtility::getFileAbsFileName($tempImageFolder);
     if (!is_dir($absoluteTempImageFolder)) {
         GeneralUtility::mkdir_deep($absoluteTempImageFolder);
     }
     $this->graphicalFunctions = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions');
     $imageSizeInformation = getimagesize($absoluteImageName);
     $width = $imageSizeInformation[0];
     $height = $imageSizeInformation[1];
     // dimensions
     /** @var \HDNET\Focuspoint\Service\DimensionService $service */
     $dimensionService = GeneralUtility::makeInstance('HDNET\\Focuspoint\\Service\\DimensionService');
     list($focusWidth, $focusHeight) = $dimensionService->getFocusWidthAndHeight($width, $height, $ratio);
     $cropMode = $dimensionService->getCropMode($width, $height, $ratio);
     list($sourceX, $sourceY) = $dimensionService->calculateSourcePosition($cropMode, $width, $height, $focusWidth, $focusHeight, $focusPointX, $focusPointY);
     // generate image
     $sourceImage = $this->graphicalFunctions->imageCreateFromFile($absoluteImageName);
     $destinationImage = imagecreatetruecolor($focusWidth, $focusHeight);
     $this->graphicalFunctions->imagecopyresized($destinationImage, $sourceImage, 0, 0, $sourceX, $sourceY, $focusWidth, $focusHeight, $focusWidth, $focusHeight);
     $this->graphicalFunctions->ImageWrite($destinationImage, $absoluteTempImageName, $GLOBALS['TYPO3_CONF_VARS']['GFX']['jpg_quality']);
     return $tempImageName;
 }
 /**
  * Fetch, cache and return the number of references of a file
  *
  * @return int
  */
 public function getReferenceCount()
 {
     $uid = (int) $this->resource->getProperty('uid');
     if ($uid <= 0) {
         return 0;
     }
     if (!isset(static::$referenceCounts[$uid])) {
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_refindex');
         $count = $queryBuilder->count('*')->from('sys_refindex')->where($queryBuilder->expr()->eq('ref_table', $queryBuilder->quote('sys_file')))->andWhere($queryBuilder->expr()->eq('ref_uid', (int) $this->resource->getProperty('uid')))->andWhere($queryBuilder->expr()->neq('tablename', $queryBuilder->quote('sys_file_metadata')))->execute()->fetchColumn();
         static::$referenceCounts[$uid] = $count;
     }
     return static::$referenceCounts[$uid];
 }
 /**
  * Get public url of image depending on the environment
  *
  * @param FileInterface $image
  * @param bool|FALSE $absolute Force absolute URL
  * @return string
  * @api
  */
 public function getImageUri(FileInterface $image, $absolute = false)
 {
     $imageUrl = $image->getPublicUrl();
     $parsedUrl = parse_url($imageUrl);
     // no prefix in case of an already fully qualified URL
     if (isset($parsedUrl['host'])) {
         $uriPrefix = '';
     } elseif ($this->environmentService->isEnvironmentInFrontendMode()) {
         $uriPrefix = $GLOBALS['TSFE']->absRefPrefix;
     } else {
         $uriPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
     }
     if ($absolute) {
         // If full URL has no scheme we add the same scheme as used by the site
         // so we have an absolute URL also usable outside of browser scope (e.g. in an email message)
         if (isset($parsedUrl['host']) && !isset($parsedUrl['scheme'])) {
             $uriPrefix = (GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https:' : 'http:') . $uriPrefix;
         }
         return GeneralUtility::locationHeaderUrl($uriPrefix . $imageUrl);
     } else {
         return $uriPrefix . $imageUrl;
     }
 }
Exemple #18
0
 /**
  * Fetch, cache and return the number of references of a file
  *
  * @return int
  */
 public function getReferenceCount()
 {
     $uid = (int) $this->resource->getProperty('uid');
     if ($uid <= 0) {
         return 0;
     }
     if (!isset(static::$referenceCounts[$uid])) {
         $count = $this->getDatabaseConnection()->exec_SELECTcountRows('*', 'sys_refindex', 'ref_table=\'sys_file\'' . ' AND ref_uid=' . (int) $this->resource->getProperty('uid') . ' AND deleted=0' . ' AND tablename != \'sys_file_metadata\'');
         if (!is_int($count)) {
             $count = 0;
         }
         static::$referenceCounts[$uid] = $count;
     }
     return static::$referenceCounts[$uid];
 }
 /**
  * Render for given File(Reference) html output
  *
  * @param FileInterface $file
  * @param int|string $width TYPO3 known format; examples: 220, 200m or 200c
  * @param int|string $height TYPO3 known format; examples: 220, 200m or 200c
  * @param array $options
  * @param bool $usedPathsRelativeToCurrentScript See $file->getPublicUrl()
  * @return string
  */
 public function render(FileInterface $file, $width, $height, array $options = null, $usedPathsRelativeToCurrentScript = false)
 {
     // Check for an autoplay option at the file reference itself, if not overriden yet.
     if (!isset($options['autoplay']) && $file instanceof FileReference) {
         $autoplay = $file->getProperty('autoplay');
         if ($autoplay !== null) {
             $options['autoplay'] = $autoplay;
         }
     }
     $urlParams = array('autohide=1');
     if (!isset($options['controls']) || !empty($options['controls'])) {
         $urlParams[] = 'controls=2';
     }
     if (!empty($options['autoplay'])) {
         $urlParams[] = 'autoplay=1';
     }
     if (!empty($options['loop'])) {
         $urlParams[] = 'loop=1';
     }
     if (!isset($options['enablejsapi']) || !empty($options['enablejsapi'])) {
         $urlParams[] = 'enablejsapi=1&amp;origin=' . GeneralUtility::getIndpEnv('HTTP_HOST');
     }
     $urlParams[] = 'showinfo=' . (int) (!empty($options['showinfo']));
     if ($file instanceof FileReference) {
         $orgFile = $file->getOriginalFile();
     } else {
         $orgFile = $file;
     }
     $videoId = $this->getOnlineMediaHelper($file)->getOnlineMediaId($orgFile);
     $src = sprintf('//www.youtube%s.com/embed/%s?%s', !empty($options['no-cookie']) ? '-nocookie' : '', $videoId, implode('&amp;', $urlParams));
     $attributes = ['allowfullscreen'];
     if ((int) $width > 0) {
         $attributes[] = 'width="' . (int) $width . '"';
     }
     if ((int) $height > 0) {
         $attributes[] = 'height="' . (int) $height . '"';
     }
     if (is_object($GLOBALS['TSFE']) && $GLOBALS['TSFE']->config['config']['doctype'] !== 'html5') {
         $attributes[] = 'frameborder="0"';
     }
     foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick', 'poster', 'preload'] as $key) {
         if (!empty($options[$key])) {
             $attributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"';
         }
     }
     return sprintf('<iframe src="%s"%s></iframe>', $src, empty($attributes) ? '' : ' ' . implode(' ', $attributes));
 }
Exemple #20
0
 /**
  * Render for given File(Reference) html output
  *
  * @param FileInterface $file
  * @param int|string $width TYPO3 known format; examples: 220, 200m or 200c
  * @param int|string $height TYPO3 known format; examples: 220, 200m or 200c
  * @param array $options
  * @param bool $usedPathsRelativeToCurrentScript See $file->getPublicUrl()
  * @return string
  */
 public function render(FileInterface $file, $width, $height, array $options = null, $usedPathsRelativeToCurrentScript = false)
 {
     //        if ($file instanceof FileReference) {
     //            $autoplay = $file->getProperty('autoplay');
     //            if ($autoplay !== null) {
     //                $options['autoplay'] = $autoplay;
     //            }
     //        }
     //
     //        $urlParams = array();
     //        if (!empty($options['autoplay'])) {
     //            $urlParams[] = 'autoplay=1';
     //        }
     $urlParams[] = 'autoplay=1';
     if (!empty($options['loop'])) {
         $urlParams[] = 'loop=1';
     }
     $urlParams[] = 'title=' . (int) (!empty($options['showinfo']));
     $urlParams[] = 'byline=' . (int) (!empty($options['showinfo']));
     $urlParams[] = 'portrait=0';
     if ($file instanceof FileReference) {
         $orgFile = $file->getOriginalFile();
     } else {
         $orgFile = $file;
     }
     $videoId = $this->getOnlineMediaHelper($file)->getOnlineMediaId($orgFile);
     $src = sprintf('//player.vimeo.com/video/%s?%s', $videoId, implode('&amp;', $urlParams));
     $attributes = ['allowfullscreen'];
     if ((int) $width > 0) {
         $attributes[] = 'width="' . (int) $width . '"';
     }
     if ((int) $height > 0) {
         $attributes[] = 'height="' . (int) $height . '"';
     }
     if (is_object($GLOBALS['TSFE']) && $GLOBALS['TSFE']->config['config']['doctype'] !== 'html5') {
         $attributes[] = 'frameborder="0"';
     }
     foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick'] as $key) {
         if (!empty($options[$key])) {
             $attributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"';
         }
     }
     return sprintf('<iframe src="%s"%s></iframe>', $src, empty($attributes) ? '' : ' ' . implode(' ', $attributes));
 }
 /**
  * Renames a file in this storage.
  *
  * @param \TYPO3\CMS\Core\Resource\FileInterface $file
  * @param string $newName The target path (including the file name!)
  * @return string The identifier of the file after renaming
  */
 public function renameFile(\TYPO3\CMS\Core\Resource\FileInterface $file, $newName)
 {
     // Makes sure the Path given as parameter is valid
     $newName = $this->sanitizeFileName($newName);
     $newIdentifier = rtrim(GeneralUtility::fixWindowsFilePath(dirname($file->getIdentifier())), '/') . '/' . $newName;
     // The target should not exist already
     if ($this->fileExists($newIdentifier)) {
         throw new \TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException('The target file already exists.', 1320291063);
     }
     $sourcePath = $this->getAbsolutePath($file);
     $targetPath = $this->absoluteBasePath . '/' . ltrim($newIdentifier, '/');
     $result = rename($sourcePath, $targetPath);
     if ($result === FALSE) {
         throw new \RuntimeException('Renaming file ' . $sourcePath . ' to ' . $targetPath . ' failed.', 1320375115);
     }
     return $newIdentifier;
 }
 /**
  * Checks if the given file is selectable in the filelist.
  *
  * In "plain" RTE mode only image files with a maximum width and height are selectable.
  *
  * @param FileInterface $file
  * @param array $imgInfo Image dimensions from \TYPO3\CMS\Core\Imaging\GraphicalFunctions::getImageDimensions()
  * @return bool TRUE if file is selectable.
  */
 protected function fileIsSelectableInFileList(FileInterface $file, array $imgInfo)
 {
     return $this->mode !== 'plain' || GeneralUtility::inList(SelectImageController::PLAIN_MODE_IMAGE_FILE_EXTENSIONS, strtolower($file->getExtension())) && $imgInfo[0] <= $this->plainMaxWidth && $imgInfo[1] <= $this->plainMaxHeight;
 }
Exemple #23
0
 /**
  * Removes a temporary file.
  *
  * When working with a file, the actual file might be on a remote storage.
  * To work with it it gets copied to local storage, those temporary local
  * copies need to be removed when they're not needed anymore.
  *
  * @param string $localTempFilePath Path to the local file copy
  * @param \TYPO3\CMS\Core\Resource\FileInterface $sourceFile Original file
  */
 protected function cleanupTempFile($localTempFilePath, FileInterface $sourceFile)
 {
     if (PathUtility::basename($localTempFilePath) !== $sourceFile->getName()) {
         unlink($localTempFilePath);
     }
 }
Exemple #24
0
 /**
  * Checks if the given file can be processed by this Extractor
  *
  * @param FileInterface $file
  * @return bool
  */
 public function canExtractText(FileInterface $file)
 {
     return in_array($file->getExtension(), $this->supportedFileTypes);
 }
 /**
  * Previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::func_rename()
  *
  * @param FileInterface $file
  * @param string $targetFileName
  *
  * @throws Exception\InsufficientFileWritePermissionsException
  * @throws Exception\InsufficientFileReadPermissionsException
  * @throws Exception\InsufficientUserPermissionsException
  * @return FileInterface
  */
 public function renameFile($file, $targetFileName)
 {
     // @todo add $conflictMode setting
     // The name should be different from the current.
     if ($file->getName() === $targetFileName) {
         return $file;
     }
     $sanitizedTargetFileName = $this->driver->sanitizeFileName($targetFileName);
     $this->assureFileRenamePermissions($file, $sanitizedTargetFileName);
     $this->emitPreFileRenameSignal($file, $sanitizedTargetFileName);
     // Call driver method to rename the file and update the index entry
     try {
         $newIdentifier = $this->driver->renameFile($file->getIdentifier(), $sanitizedTargetFileName);
         if ($file instanceof File) {
             $file->updateProperties(array('identifier' => $newIdentifier));
         }
         $this->getIndexer()->updateIndexEntry($file);
     } catch (\RuntimeException $e) {
     }
     $this->emitPostFileRenameSignal($file, $sanitizedTargetFileName);
     return $file;
 }
 /**
  * Retrieves Index record for a given $fileObject
  *
  * @param \TYPO3\CMS\Core\Resource\FileInterface $fileObject
  * @return array|boolean
  *
  * @internal only for use from FileRepository
  */
 public function findOneByFileObject(\TYPO3\CMS\Core\Resource\FileInterface $fileObject)
 {
     $storageUid = $fileObject->getStorage()->getUid();
     $identifierHash = $fileObject->getHashedIdentifier();
     return $this->findOneByStorageUidAndIdentifierHash($storageUid, $identifierHash);
 }
 /**
  * Calculate new dimensions for SVG image
  * No cropping, if cropped info present image is scaled down
  *
  * @param Resource\FileInterface $file
  * @param array $configuration
  * @param array $options
  * @param GifBuilder $gifBuilder
  * @return array width,height
  */
 protected function getNewSvgDimensions($file, array $configuration, array $options, GifBuilder $gifBuilder)
 {
     $info = array($file->getProperty('width'), $file->getProperty('height'));
     $data = $gifBuilder->getImageScale($info, $configuration['width'], $configuration['height'], $options);
     // Turn cropScaling into scaling
     if ($data['crs']) {
         if (!$data['origW']) {
             $data['origW'] = $data[0];
         }
         if (!$data['origH']) {
             $data['origH'] = $data[1];
         }
         if ($data[0] > $data['origW']) {
             $data[1] = (int) ($data['origW'] * $data[1] / $data[0]);
             $data[0] = $data['origW'];
         } else {
             $data[0] = (int) ($data['origH'] * $data[0] / $data[1]);
             $data[1] = $data['origH'];
         }
     }
     return array('width' => $data[0], 'height' => $data[1]);
 }
 /**
  * Passes a file to the File Processing Services and returns the resulting ProcessedFile object.
  *
  * @param \TYPO3\CMS\Core\Resource\FileInterface $fileObject The file object
  * @param string $context
  * @param array $configuration
  *
  * @return \TYPO3\CMS\Core\Resource\ProcessedFile
  * @throws \InvalidArgumentException
  */
 public function processFile(\TYPO3\CMS\Core\Resource\FileInterface $fileObject, $context, array $configuration)
 {
     if ($fileObject->getStorage() !== $this) {
         throw new \InvalidArgumentException('Cannot process files of foreign storage', 1353401835);
     }
     $processedFile = $this->getFileProcessingService()->processFile($fileObject, $this, $context, $configuration);
     return $processedFile;
 }
Exemple #29
0
 /**
  * Returns a (local copy of) a file for processing it. When changing the
  * file, you have to take care of replacing the current version yourself!
  *
  * @param \TYPO3\CMS\Core\Resource\FileInterface $file
  * @param bool $writable Set this to FALSE if you only need the file for read operations. This might speed up things, e.g. by using a cached local version. Never modify the file if you have set this flag!
  * @return string The path to the file on the local disk
  */
 public function getFileForLocalProcessing(\TYPO3\CMS\Core\Resource\FileInterface $file, $writable = true)
 {
     error_log('FAL DRIVER: ' . __FUNCTION__);
     if (!$file->isIndexed() || !$file->getProperty('yagItem') instanceof \Tx_Yag_Domain_Model_Item) {
         $identifier = $file->getIdentifier();
         $fileInfo = $this->getFileInfoByIdentifier($identifier);
         $sourceUri = $this->yagFileSystemDiv->makePathAbsolute($fileInfo['sourceUri']);
     } else {
         $item = $file->getProperty('yagItem');
         $sourceUri = $this->yagFileSystemDiv->makePathAbsolute($item->getSourceuri());
     }
     return $sourceUri;
 }
 /**
  * Returns information about a file for a given file object.
  *
  * @param \TYPO3\CMS\Core\Resource\FileInterface $file
  * @return array
  */
 public function getFileInfo(\TYPO3\CMS\Core\Resource\FileInterface $file)
 {
     return $this->getFileInfoByIdentifier($file->getIdentifier());
 }