[BUGFIX] IMG_RESOURCE not capable of sys_file_reference
authorNicole Cordes <nicole@cordes.co>
Mon, 19 Nov 2012 22:15:43 +0000 (23:15 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Mon, 26 Nov 2012 23:46:15 +0000 (00:46 +0100)
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
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

index b0fcdef..54b0293 100644 (file)
@@ -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
+?>