Fixes a bug in TYPO3 6.2.0 that the properties metadata is not overlayed on localization.
public static getFileArray ( TYPO3\CMS\Core\Resource\File $file ) : array | ||
$file | TYPO3\CMS\Core\Resource\File | |
Результат | array |
/** * @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 mixed $identity * @return mixed */ public function getResource($identity) { $fileReference = $this->resourceFactory->getFileReferenceObject(intval($identity)); $file = $fileReference->getOriginalFile(); $fileReferenceProperties = $fileReference->getProperties(); $fileProperties = ResourceUtility::getFileArray($file); ArrayUtility::mergeRecursiveWithOverrule($fileProperties, $fileReferenceProperties, TRUE, FALSE, FALSE); return $fileProperties; }
/** * @test */ public function canGetFileInformationArrayFromFileObject() { $propertiesFromFile = array('foo' => 123, 'bar' => 321); $propertiesFromStorage = array('foo' => 'abc', 'baz' => 123); $expectation = array_merge($propertiesFromFile, $propertiesFromStorage); $mockStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Storage', array('getFileInfo')); $mockFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array('getProperties', 'getStorage', 'toArray'), array(), '', FALSE); $mockFile->expects($this->once())->method('getProperties')->will($this->returnValue($propertiesFromFile)); $mockFile->expects($this->once())->method('getStorage')->will($this->returnValue($mockStorage)); $mockStorage->expects($this->once())->method('getFileInfo')->will($this->returnValue($propertiesFromStorage)); $result = ResourceUtility::getFileArray($mockFile); $this->assertEquals($expectation, $result); }
/** * Returns the files * * @param boolean $onlyProperties * @param mixed $identifier * @param mixed $categories * @return array|NULL */ public function getFiles($onlyProperties = FALSE, $identifier = NULL, $categories = NULL) { $identifier = $this->arrayForMixedArgument($identifier, 'identifier'); $categories = $this->arrayForMixedArgument($categories, 'categories'); $treatIdAsUid = (bool) $this->arguments['treatIdAsUid']; $treatIdAsReference = (bool) $this->arguments['treatIdAsReference']; if (TRUE === $treatIdAsUid && TRUE === $treatIdAsReference) { throw new \RuntimeException('The arguments "treatIdAsUid" and "treatIdAsReference" may not both be TRUE.', 1384604695); } if (TRUE === empty($identifier) && TRUE === empty($categories)) { return NULL; } $files = array(); $resourceFactory = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory'); if (FALSE === empty($categories)) { $sqlCategories = implode(',', $GLOBALS['TYPO3_DB']->fullQuoteArray($categories, 'sys_category_record_mm')); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid_foreign', 'sys_category_record_mm', 'tablenames = \'sys_file\' AND uid_local IN (' . $sqlCategories . ')'); $fileUids = array(); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $fileUids[] = intval($row['uid_foreign']); } $fileUids = array_unique($fileUids); if (TRUE === empty($identifier)) { foreach ($fileUids as $fileUid) { try { $file = $resourceFactory->getFileObject($fileUid); if (TRUE === $onlyProperties) { $file = ResourceUtility::getFileArray($file); } $files[] = $file; } catch (\Exception $e) { continue; } } return $files; } } foreach ($identifier as $i) { try { if (TRUE === $treatIdAsUid) { $file = $resourceFactory->getFileObject(intval($i)); } elseif (TRUE === $treatIdAsReference) { $fileReference = $resourceFactory->getFileReferenceObject(intval($i)); $file = $fileReference->getOriginalFile(); } else { $file = $resourceFactory->getFileObjectFromCombinedIdentifier($i); } if (TRUE === isset($fileUids) && FALSE === in_array($file->getUid(), $fileUids)) { continue; } if (TRUE === $onlyProperties) { $file = ResourceUtility::getFileArray($file); } $files[] = $file; } catch (\Exception $e) { continue; } } return $files; }
/** * @param integer $uid * @return array */ public function getInfoByUid($uid) { $file = $this->resourceFactory->getFileObject($uid); return ResourceUtility::getFileArray($file); }
/** * @param array $files * @param boolean $onlyProperties * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception * @return array|NULL */ public function preprocessImages($files, $onlyProperties = FALSE) { if (TRUE === empty($files)) { return NULL; } if ('BE' === TYPO3_MODE) { $this->simulateFrontendEnvironment(); } $setup = array('width' => $this->arguments['width'], 'height' => $this->arguments['height'], 'minW' => $this->arguments['minWidth'], 'minH' => $this->arguments['minHeight'], 'maxW' => $this->arguments['maxWidth'], 'maxH' => $this->arguments['maxHeight'], 'treatIdAsReference' => FALSE); $images = array(); foreach ($files as $file) { $imageInfo = $this->contentObject->getImgResource($file->getUid(), $setup); $GLOBALS['TSFE']->lastImageInfo = $imageInfo; if (FALSE === is_array($imageInfo)) { throw new Exception('Could not get image resource for "' . htmlspecialchars($file->getCombinedIdentifier()) . '".', 1253191060); } $imageInfo[3] = GeneralUtility::png_to_gif_by_imagemagick($imageInfo[3]); $GLOBALS['TSFE']->imagesOnPage[] = $imageInfo[3]; $imageSource = $GLOBALS['TSFE']->absRefPrefix . GeneralUtility::rawUrlEncodeFP($imageInfo[3]); if (TRUE === $onlyProperties) { $file = ResourceUtility::getFileArray($file); } $images[] = array('info' => $imageInfo, 'source' => $imageSource, 'file' => $file); } if ('BE' === TYPO3_MODE) { $this->resetFrontendEnvironment(); } return $images; }
/** * @param array $files * @param boolean $onlyProperties * @throws Exception * @return array|NULL */ public function preprocessImages($files, $onlyProperties = false) { if (true === empty($files)) { return null; } if ('BE' === TYPO3_MODE) { $this->simulateFrontendEnvironment(); } $setup = ['width' => $this->arguments['width'], 'height' => $this->arguments['height'], 'minW' => $this->arguments['minWidth'], 'minH' => $this->arguments['minHeight'], 'maxW' => $this->arguments['maxWidth'], 'maxH' => $this->arguments['maxHeight'], 'treatIdAsReference' => false]; $images = []; foreach ($files as $file) { $imageInfo = $this->contentObject->getImgResource($file->getUid(), $setup); $GLOBALS['TSFE']->lastImageInfo = $imageInfo; if (false === is_array($imageInfo)) { throw new Exception('Could not get image resource for "' . htmlspecialchars($file->getCombinedIdentifier()) . '".', 1253191060); } if ((double) substr(TYPO3_version, 0, 3) < 7.1) { $imageInfo[3] = GeneralUtility::png_to_gif_by_imagemagick($imageInfo[3]); } else { $imageInfo[3] = GraphicalFunctions::pngToGifByImagemagick($imageInfo[3]); } $imageInfo[3] = GeneralUtility::png_to_gif_by_imagemagick($imageInfo[3]); $GLOBALS['TSFE']->imagesOnPage[] = $imageInfo[3]; if (true === GeneralUtility::isValidUrl($imageInfo[3])) { $imageSource = $imageInfo[3]; } else { $imageSource = $GLOBALS['TSFE']->absRefPrefix . GeneralUtility::rawUrlEncodeFP($imageInfo[3]); } if (true === $onlyProperties) { $file = ResourceUtility::getFileArray($file); } $images[] = ['info' => $imageInfo, 'source' => $imageSource, 'file' => $file]; } if ('BE' === TYPO3_MODE) { $this->resetFrontendEnvironment(); } return $images; }