From 3903ee02f6bd663fc1ef23f14d936407724887ab Mon Sep 17 00:00:00 2001
From: Nicole Cordes <nicole@cordes.co>
Date: Mon, 19 Nov 2012 23:15:43 +0100
Subject: [PATCH] [BUGFIX] IMG_RESOURCE not capable of sys_file_reference

The file.import function can't handle file relations. Sometimes
you have to deal with uids of sys_file_references instead of
sys_file uids. One prominent case is import.data = levelmedia
This patch adds an flag to IMG_RESOURCE with that, a given uid
is interpreted as reference instead of file uid.

Change-Id: I4699d9e38b9a809fd194d33344678a64168d4300
Fixes: #43101
Releases: 6.0
Documentation: #43283
Reviewed-on: http://review.typo3.org/16584
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
Reviewed-by: Nicole Cordes
Tested-by: Nicole Cordes
Reviewed-by: Stefan Neufeind
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
---
 .../ContentObject/ContentObjectRenderer.php   | 33 +++++++++++--------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
index b0fcdefd8254..54b02932bd05 100644
--- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
+++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
@@ -5034,8 +5034,10 @@ class ContentObjectRenderer {
 	 * @todo Define visibility
 	 */
 	public function getImgResource($file, $fileArray) {
-		if (is_array($fileArray)) {
-			switch ($file) {
+		if (!is_array($fileArray)) {
+			$fileArray = (array) $fileArray;
+		}
+		switch ($file) {
 			case 'GIFBUILDER':
 				$gifCreator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder');
 				$gifCreator->init();
@@ -5048,18 +5050,24 @@ class ContentObjectRenderer {
 				break;
 			default:
 				try {
+					if ($fileArray['import.']) {
+						$importedFile = trim($this->stdWrap('', $fileArray['import.']));
+						if (!empty($importedFile)) {
+							$file = $importedFile;
+						}
+					}
+
 					if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($file)) {
+						if (!empty($fileArray['treatIdAsReference'])) {
+							$fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileReferenceObject($file)->getOriginalFile();
+						} else {
+							$fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObject($file);
+						}
+					} elseif (preg_match('/^(0|[1-9][0-9]*):/', $file)) { // combined identifier
 						$fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($file);
 					} else {
-						if ($fileArray['import.']) {
-							$ifile = $this->stdWrap('', $fileArray['import.']);
-							if ($ifile) {
-								if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($ifile)) {
-									$file = $ifile;
-								} else {
-									$file = $fileArray['import'] . $ifile;
-								}
-							}
+						if (isset($importedFile) && !empty($importedFile) && !empty($fileArray['import'])) {
+							$file = $fileArray['import'] . $file;
 						}
 						// clean ../ sections of the path and resolve to proper string. This is necessary for the Tx_File_BackwardsCompatibility_TslibContentAdapter to work.
 						$file = \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath($file);
@@ -5120,7 +5128,6 @@ class ContentObjectRenderer {
 					}
 				}
 				break;
-			}
 		}
 		$theImage = $GLOBALS['TSFE']->tmpl->getFileName($file);
 		// If image was processed by GIFBUILDER:
@@ -7774,4 +7781,4 @@ class ContentObjectRenderer {
 
 }
 
-?>
\ No newline at end of file
+?>
-- 
GitLab