From cd85f30c1d758dc801da41d5043dc577b3626e2b Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Mon, 11 Jan 2016 17:03:02 +0100
Subject: [PATCH] [!!!][TASK] RTE Remove relative path calculation options

The RTE has no calculations anymore for defining the
relPath (thus, it's always empty) and can be removed safely.

Resolves: #72666
Releases: master
Change-Id: Ie90de879efca397a81ef9d0ddd4dda53b21e8214
Reviewed-on: https://review.typo3.org/45817
Reviewed-by: Wolfgang Klinger <wolfgang@wazum.com>
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
---
 .../core/Classes/DataHandling/DataHandler.php |  1 -
 .../core/Classes/Html/RteHtmlParser.php       | 47 ++-----------------
 ...2666-RTERemoveRelativePathCalculations.rst | 21 +++++++++
 .../Classes/Form/Element/RichTextElement.php  |  1 -
 4 files changed, 25 insertions(+), 45 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Breaking-72666-RTERemoveRelativePathCalculations.rst

diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
index 2f048ec4f67f..4f1c83dfac0b 100644
--- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php
+++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
@@ -1565,7 +1565,6 @@ class DataHandler
                 // Initialize transformation:
                 $parseHTML = GeneralUtility::makeInstance(RteHtmlParser::class);
                 $parseHTML->init($table . ':' . $field, $pid);
-                $parseHTML->setRelPath('');
                 // Perform transformation:
                 $value = $parseHTML->RTE_transform($value, $defaultExtras, 'db', $thisConfig);
             }
diff --git a/typo3/sysext/core/Classes/Html/RteHtmlParser.php b/typo3/sysext/core/Classes/Html/RteHtmlParser.php
index 09190c8131a0..bb27d18fbccf 100644
--- a/typo3/sysext/core/Classes/Html/RteHtmlParser.php
+++ b/typo3/sysext/core/Classes/Html/RteHtmlParser.php
@@ -46,20 +46,6 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
      */
     public $elRef = '';
 
-    /**
-     * Relative path
-     *
-     * @var string
-     */
-    public $relPath = '';
-
-    /**
-     * Relative back-path
-     *
-     * @var string
-     */
-    public $relBackPath = '';
-
     /**
      * Current Page TSConfig
      *
@@ -122,30 +108,6 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
         $this->elRef = $elRef;
     }
 
-    /**
-     * Setting the ->relPath and ->relBackPath to proper values so absolute references to links and images can be converted to relative dittos.
-     * This is used when editing files with the RTE
-     *
-     * @param string $path The relative path from PATH_site to the place where the file being edited is. Eg. "fileadmin/static".
-     * @return void There is no output, it is set in internal variables. With the above example of "fileadmin/static" as input this will yield ->relPath to be "fileadmin/static/" and ->relBackPath to be "../../
-     * @TODO: Check if relPath and relBackPath are used for anything useful after removal of "static file edit" with #63818
-     */
-    public function setRelPath($path)
-    {
-        $path = trim($path);
-        $path = preg_replace('/^\\//', '', $path);
-        $path = preg_replace('/\\/$/', '', $path);
-        if ($path) {
-            $this->relPath = $path;
-            $this->relBackPath = '';
-            $partsC = count(explode('/', $path));
-            for ($a = 0; $a < $partsC; $a++) {
-                $this->relBackPath .= '../';
-            }
-            $this->relPath .= '/';
-        }
-    }
-
     /**********************************************
      *
      * Main function
@@ -450,7 +412,7 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                     }
                     // Convert absolute to relative url
                     if (GeneralUtility::isFirstPartOfStr($attribArray['src'], $siteUrl)) {
-                        $attribArray['src'] = $this->relBackPath . substr($attribArray['src'], strlen($siteUrl));
+                        $attribArray['src'] = substr($attribArray['src'], strlen($siteUrl));
                     }
                     $imgSplit[$k] = '<img ' . GeneralUtility::implodeAttributes($attribArray, 1, 1) . ' />';
                 }
@@ -482,7 +444,6 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                     $absoluteUrl = trim($attribArray['src']);
                     // Transform the src attribute into an absolute url, if it not already
                     if (strtolower(substr($absoluteUrl, 0, 4)) !== 'http') {
-                        $attribArray['src'] = substr($attribArray['src'], strlen($this->relBackPath));
                         // If site is in a subpath (eg. /~user_jim/) this path needs to be removed because it will be added with $siteUrl
                         $attribArray['src'] = preg_replace('#^' . preg_quote($sitePath, '#') . '#', '', $attribArray['src']);
                         $attribArray['src'] = $siteUrl . $attribArray['src'];
@@ -523,7 +484,7 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                         list($attribArray) = $this->get_tag_attributes($this->getFirstTag($v), true);
                         // 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));
+                            $attribArray['href'] = substr($attribArray['href'], strlen($siteURL));
                         }
                         $bTag = '<a ' . GeneralUtility::implodeAttributes($attribArray, 1) . '>';
                         $eTag = '</a>';
@@ -614,7 +575,7 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                         $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));
+                            $attribArray['href'] = substr($attribArray['href'], strlen($siteURL));
                         }
                         // Check for FAL link-handler keyword
                         list($linkHandlerKeyword, $linkHandlerValue) = explode(':', $attribArray['href'], 2);
@@ -1530,7 +1491,7 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                 if ($attribArray['href'] !== '') {
                     $uP = parse_url(strtolower($attribArray['href']));
                     if (!$uP['scheme']) {
-                        $attribArray['href'] = $this->siteUrl() . substr($attribArray['href'], strlen($this->relBackPath));
+                        $attribArray['href'] = $this->siteUrl() . $attribArray['href'];
                     } elseif ($uP['scheme'] != 'mailto') {
                         $attribArray['data-htmlarea-external'] = 1;
                     }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-72666-RTERemoveRelativePathCalculations.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-72666-RTERemoveRelativePathCalculations.rst
new file mode 100644
index 000000000000..d3a3f3cc5928
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-72666-RTERemoveRelativePathCalculations.rst
@@ -0,0 +1,21 @@
+=========================================================
+Breaking: #72666 - RTE: Remove relative path calculations
+=========================================================
+
+Description
+===========
+
+Since the removal of the feature editing static files with the Rich Text Editor (option "static_file_edit"), the path calculations for files
+within the HtmlParser including the method ``RteHtmlParser->setRelPath()`` were removed as well.
+
+
+Impact
+======
+
+Using the method ``RteHtmlParser->setRelPath()`` will result in a fatal PHP error.
+
+
+Affected Installations
+======================
+
+Any installations with custom RTE transformations that use a custom implementation of the RteHtmlParser PHP class.
\ No newline at end of file
diff --git a/typo3/sysext/rtehtmlarea/Classes/Form/Element/RichTextElement.php b/typo3/sysext/rtehtmlarea/Classes/Form/Element/RichTextElement.php
index 4f13d8c7b919..bc499ff0c091 100644
--- a/typo3/sysext/rtehtmlarea/Classes/Form/Element/RichTextElement.php
+++ b/typo3/sysext/rtehtmlarea/Classes/Form/Element/RichTextElement.php
@@ -1303,7 +1303,6 @@ class RichTextElement extends AbstractFormElement
                 /** @var RteHtmlParser $parseHTML */
                 $parseHTML = GeneralUtility::makeInstance(RteHtmlParser::class);
                 $parseHTML->init($this->data['table'] . ':' . $this->data['fieldName'], $this->pidOfVersionedMotherRecord);
-                $parseHTML->setRelPath('');
                 $value = $parseHTML->RTE_transform($value, $this->defaultExtras, 'rte', $this->processedRteConfiguration);
             }
         }
-- 
GitLab