/** * @param FileReference $fileReference * @return array */ public function getResource($fileReference) { $file = $fileReference->getOriginalFile(); $fileReferenceProperties = $fileReference->getProperties(); $fileProperties = ResourceUtility::getFileArray($file); ArrayUtility::mergeRecursiveWithOverrule($fileProperties, $fileReferenceProperties, true, false, false); return $fileProperties; }
/** * @param \TYPO3\CMS\Core\Resource\FileReference $originalResource */ public function setOriginalResource(\TYPO3\CMS\Core\Resource\FileReference $originalResource) { $this->originalResource = $originalResource; # Absorb properties from original resource, because otherwise we'll get an empty sys_file_reference row. $originalResourceProperties = $originalResource->getReferenceProperties(); foreach ($originalResourceProperties as $propertyName => $propertyValue) { $setter = 'set' . GeneralUtility::underscoredToUpperCamelCase($propertyName); if (method_exists($this, $setter)) { $this->{$setter}($propertyValue); } } }
/** * Creates and returns a TypoScript "imgResource". * The value ($file) can either be a file reference (TypoScript resource) or the string "GIFBUILDER". * In the first case a current image is returned, possibly scaled down or otherwise processed. * In the latter case a GIFBUILDER image is returned; This means an image is made by TYPO3 from layers of elements as GIFBUILDER defines. * In the function IMG_RESOURCE() this function is called like $this->getImgResource($conf['file'], $conf['file.']); * * Structure of the returned info array: * 0 => width * 1 => height * 2 => file extension * 3 => file name * origFile => original file name * origFile_mtime => original file mtime * -- only available if processed via FAL: -- * originalFile => original file object * processedFile => processed file object * fileCacheHash => checksum of processed file * * @param string|File|FileReference $file A "imgResource" TypoScript data type. Either a TypoScript file resource, a file or a file reference object or the string GIFBUILDER. See description above. * @param array $fileArray TypoScript properties for the imgResource type * @return array|NULL Returns info-array * @see IMG_RESOURCE(), cImage(), \TYPO3\CMS\Frontend\Imaging\GifBuilder */ public function getImgResource($file, $fileArray) { if (empty($file) && empty($fileArray)) { return null; } if (!is_array($fileArray)) { $fileArray = (array) $fileArray; } $imageResource = null; $tsfe = $this->getTypoScriptFrontendController(); if ($file === 'GIFBUILDER') { /** @var GifBuilder $gifCreator */ $gifCreator = GeneralUtility::makeInstance(GifBuilder::class); $gifCreator->init(); $theImage = ''; if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) { $gifCreator->start($fileArray, $this->data); $theImage = $gifCreator->gifBuild(); } $imageResource = $gifCreator->getImageDimensions($theImage); $imageResource['origFile'] = $theImage; } else { if ($file instanceof File) { $fileObject = $file; } elseif ($file instanceof FileReference) { $fileObject = $file->getOriginalFile(); if (!isset($fileArray['crop'])) { $fileArray['crop'] = $file->getProperty('crop'); } } else { try { if ($fileArray['import.']) { $importedFile = trim($this->stdWrap('', $fileArray['import.'])); if (!empty($importedFile)) { $file = $importedFile; } } if (MathUtility::canBeInterpretedAsInteger($file)) { $treatIdAsReference = isset($fileArray['treatIdAsReference.']) ? $this->stdWrap($fileArray['treatIdAsReference'], $fileArray['treatIdAsReference.']) : $fileArray['treatIdAsReference']; if (!empty($treatIdAsReference)) { $fileReference = $this->getResourceFactory()->getFileReferenceObject($file); $fileObject = $fileReference->getOriginalFile(); if (!isset($fileArray['crop'])) { $fileArray['crop'] = $fileReference->getProperty('crop'); } } else { $fileObject = $this->getResourceFactory()->getFileObject($file); } } elseif (preg_match('/^(0|[1-9][0-9]*):/', $file)) { // combined identifier $fileObject = $this->getResourceFactory()->retrieveFileOrFolderObject($file); } else { if (isset($importedFile) && !empty($importedFile) && !empty($fileArray['import'])) { $file = $fileArray['import'] . $file; } $fileObject = $this->getResourceFactory()->retrieveFileOrFolderObject($file); } } catch (Exception $exception) { /** @var \TYPO3\CMS\Core\Log\Logger $logger */ $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); $logger->warning('The image "' . $file . '" could not be found and won\'t be included in frontend output'); return null; } } if ($fileObject instanceof File) { $processingConfiguration = array(); $processingConfiguration['width'] = isset($fileArray['width.']) ? $this->stdWrap($fileArray['width'], $fileArray['width.']) : $fileArray['width']; $processingConfiguration['height'] = isset($fileArray['height.']) ? $this->stdWrap($fileArray['height'], $fileArray['height.']) : $fileArray['height']; $processingConfiguration['fileExtension'] = isset($fileArray['ext.']) ? $this->stdWrap($fileArray['ext'], $fileArray['ext.']) : $fileArray['ext']; $processingConfiguration['maxWidth'] = isset($fileArray['maxW.']) ? (int) $this->stdWrap($fileArray['maxW'], $fileArray['maxW.']) : (int) $fileArray['maxW']; $processingConfiguration['maxHeight'] = isset($fileArray['maxH.']) ? (int) $this->stdWrap($fileArray['maxH'], $fileArray['maxH.']) : (int) $fileArray['maxH']; $processingConfiguration['minWidth'] = isset($fileArray['minW.']) ? (int) $this->stdWrap($fileArray['minW'], $fileArray['minW.']) : (int) $fileArray['minW']; $processingConfiguration['minHeight'] = isset($fileArray['minH.']) ? (int) $this->stdWrap($fileArray['minH'], $fileArray['minH.']) : (int) $fileArray['minH']; $processingConfiguration['noScale'] = isset($fileArray['noScale.']) ? $this->stdWrap($fileArray['noScale'], $fileArray['noScale.']) : $fileArray['noScale']; $processingConfiguration['additionalParameters'] = isset($fileArray['params.']) ? $this->stdWrap($fileArray['params'], $fileArray['params.']) : $fileArray['params']; $processingConfiguration['frame'] = isset($fileArray['frame.']) ? (int) $this->stdWrap($fileArray['frame'], $fileArray['frame.']) : (int) $fileArray['frame']; $processingConfiguration['crop'] = isset($fileArray['crop.']) ? $this->stdWrap($fileArray['crop'], $fileArray['crop.']) : (isset($fileArray['crop']) ? $fileArray['crop'] : null); // Possibility to cancel/force profile extraction // see $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_stripProfileCommand'] if (isset($fileArray['stripProfile'])) { $processingConfiguration['stripProfile'] = $fileArray['stripProfile']; } // Check if we can handle this type of file for editing if (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileObject->getExtension())) { $maskArray = $fileArray['m.']; // Must render mask images and include in hash-calculating // - otherwise we cannot be sure the filename is unique for the setup! if (is_array($maskArray)) { $mask = $this->getImgResource($maskArray['mask'], $maskArray['mask.']); $bgImg = $this->getImgResource($maskArray['bgImg'], $maskArray['bgImg.']); $bottomImg = $this->getImgResource($maskArray['bottomImg'], $maskArray['bottomImg.']); $bottomImg_mask = $this->getImgResource($maskArray['bottomImg_mask'], $maskArray['bottomImg_mask.']); $processingConfiguration['maskImages']['maskImage'] = $mask['processedFile']; $processingConfiguration['maskImages']['backgroundImage'] = $bgImg['processedFile']; $processingConfiguration['maskImages']['maskBottomImage'] = $bottomImg['processedFile']; $processingConfiguration['maskImages']['maskBottomImageMask'] = $bottomImg_mask['processedFile']; } $processedFileObject = $fileObject->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $processingConfiguration); $hash = $processedFileObject->calculateChecksum(); // store info in the TSFE template cache (kept for backwards compatibility) if ($processedFileObject->isProcessed() && !isset($tsfe->tmpl->fileCache[$hash])) { $tsfe->tmpl->fileCache[$hash] = array(0 => $processedFileObject->getProperty('width'), 1 => $processedFileObject->getProperty('height'), 2 => $processedFileObject->getExtension(), 3 => $processedFileObject->getPublicUrl(), 'origFile' => $fileObject->getPublicUrl(), 'origFile_mtime' => $fileObject->getModificationTime(), 'originalFile' => $fileObject, 'processedFile' => $processedFileObject, 'fileCacheHash' => $hash); } $imageResource = $tsfe->tmpl->fileCache[$hash]; } } } // If image was processed by GIFBUILDER: // ($imageResource indicates that it was processed the regular way) if (!isset($imageResource)) { $theImage = $tsfe->tmpl->getFileName($file); if ($theImage) { $gifCreator = GeneralUtility::makeInstance(GifBuilder::class); /** @var $gifCreator GifBuilder */ $gifCreator->init(); $info = $gifCreator->imageMagickConvert($theImage, 'WEB'); $info['origFile'] = $theImage; // This is needed by \TYPO3\CMS\Frontend\Imaging\GifBuilder, ln 100ff in order for the setup-array to create a unique filename hash. $info['origFile_mtime'] = @filemtime($theImage); $imageResource = $info; } } // Hook 'getImgResource': Post-processing of image resources if (isset($imageResource)) { /** @var ContentObjectGetImageResourceHookInterface $hookObject */ foreach ($this->getGetImgResourceHookObjects() as $hookObject) { $imageResource = $hookObject->getImgResourcePostProcess($file, (array) $fileArray, $imageResource, $this); } } return $imageResource; }
/** * @param \TYPO3\CMS\Core\Resource\FileReference $originalResource */ public function setOriginalResource(\TYPO3\CMS\Core\Resource\FileReference $originalResource) { $this->originalResource = $originalResource; $this->uidLocal = (int) $originalResource->getOriginalFile()->getUid(); }
/** * Generates a public URL to the specified file * This is necessary because TYPO3 doesn't prepend the absRefPrefix in all cases. * * @param \TYPO3\CMS\Core\Resource\FileReference $mediaFile media file * @return string URL to the file */ protected function generatePublicUrl(\TYPO3\CMS\Core\Resource\FileReference $mediaFile) { return $this->configurationManager->getContentObject()->typolink_URL(array('parameter' => $mediaFile->getPublicUrl())); }
/** * @param FileReference $fileReference * @return array */ private function getTitleAndDescription(FileReference $fileReference) { $title = ''; $description = ''; try { $title = $fileReference->getTitle(); } catch (\InvalidArgumentException $exception) { } try { $description = $fileReference->getDescription(); } catch (\InvalidArgumentException $exception) { } return array($title, $description); }
/** * Add new sys_file_reference for the preview image * * @param FileReference $fileObject * @param array $postRecord * * @return void */ protected function createPostSysFileReference(FileReference $fileObject, $postRecord) { if (!$fileObject instanceof FileReference) { return; } $dataArray = array('uid_local' => $fileObject->getOriginalFile()->getUid(), 'tablenames' => 'tx_t3blog_post', 'fieldname' => 'preview_image', 'uid_foreign' => $postRecord['uid'], 'table_local' => 'sys_file', 'cruser_id' => 999, 'pid' => $postRecord['pid']); $this->databaseConnection->exec_INSERTquery('sys_file_reference', $dataArray); $this->logDatabaseExec(); }
protected static function getReferenceFileInfo(\TYPO3\CMS\Core\Resource\FileReference $reference) { // getProperties gets merged values from reference and the orig file $info = $reference->getProperties(); // add some fileinfo $info['file_path_name'] = $reference->getOriginalFile()->getPublicUrl(); $info['file_abs_url'] = tx_rnbase_util_Misc::getIndpEnv('TYPO3_SITE_URL') . $info['file_path_name']; $info['file_name'] = $info['name']; return $info; }
/** * Returns an FileObject from a given FileReference * * @param \TYPO3\CMS\Core\Resource\FileReference $item The item * * @return \TYPO3\CMS\Core\Resource\File */ protected function getFileObjectFromFileReference(FileReference $item) { /** * The item to return * * @var \TYPO3\CMS\Core\Resource\File $returnItem */ $returnItem = $item->getOriginalFile(); $returnItem->updateProperties($item->getProperties()); return $returnItem; }