From ba7628572ec33010e270d5738d99fbdffc17aed2 Mon Sep 17 00:00:00 2001
From: Stanislas Rolland <typo3@sjbr.ca>
Date: Wed, 29 Jan 2014 21:04:52 -0500
Subject: [PATCH] [BUGFIX] FAL links in RTE not transformed when link has rel
 attribute

Problem: When the RTE inserts the link, the href looks like
http://somedomain/?file:1234. If a rel attribute is present, the link
is not transformed into a typolink on the way to the database.
However, the href attribute is not transformed, as it should, into a
normal file url. It should because the a-tag will be rendered as is in
the frontend.

Solution: When a link is not be transformed into a typolink,
transform the href into a normal file url.

Resolves: #54944
Release: 6.2
Change-Id: I92c45363ffd62de0f4e89941944f55320d4fc708
Reviewed-on: https://review.typo3.org/27142
Reviewed-by: Stefan Froemken
Tested-by: Stefan Froemken
Reviewed-by: Steffen Ritter
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
---
 typo3/sysext/core/Classes/Html/RteHtmlParser.php | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/typo3/sysext/core/Classes/Html/RteHtmlParser.php b/typo3/sysext/core/Classes/Html/RteHtmlParser.php
index e8eed9d59dae..37452acea49b 100644
--- a/typo3/sysext/core/Classes/Html/RteHtmlParser.php
+++ b/typo3/sysext/core/Classes/Html/RteHtmlParser.php
@@ -667,11 +667,23 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser {
 					// Unsetting 'rtekeep' attribute if that had been set.
 					unset($attribArray['rtekeep']);
 					if (!$attribArray['data-htmlarea-external']) {
-						// If the url is local, remove url-prefix
 						$siteURL = $this->siteUrl();
+						// If the url is local, remove url-prefix
 						if ($siteURL && substr($attribArray['href'], 0, strlen($siteURL)) == $siteURL) {
 							$attribArray['href'] = $this->relBackPath . substr($attribArray['href'], strlen($siteURL));
 						}
+						// Check for FAL link-handler keyword
+						list($linkHandlerKeyword, $linkHandlerValue) = explode(':', $attribArray['href'], 2);
+						if ($linkHandlerKeyword === '?file') {
+							try {
+								$fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject(rawurldecode($linkHandlerValue));
+								if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface || $fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
+									$attribArray['href'] = $fileOrFolderObject->getPublicUrl();
+								}
+							} catch (\TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException $resourceDoesNotExistException) {
+								// The indentifier inserted in the RTE is already gone...
+							}
+						}
 					}
 					unset($attribArray['data-htmlarea-external']);
 					$bTag = '<a ' . GeneralUtility::implodeAttributes($attribArray, 1) . '>';
-- 
GitLab