[BUGFIX] FAL links in RTE not transformed when link has rel attribute 42/27142/3
authorStanislas Rolland <typo3@sjbr.ca>
Thu, 30 Jan 2014 02:04:52 +0000 (21:04 -0500)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 18 Feb 2014 23:12:47 +0000 (00:12 +0100)
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

index e8eed9d..37452ac 100644 (file)
@@ -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) . '>';