From c6f14a9a9a9757effaca487fae77f4ac88e24f17 Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Wed, 20 Jan 2016 11:53:06 +0100
Subject: [PATCH] [!!!][TASK] RTE: Remove deprecated ts & ts_transform

As stated in the official documentation since TYPO3 4.0
the transformation option "ts" and "ts_transform" are
outdated and only for very old transformations (before
there was CSS Styled Content).

The option is marked as obsolete and outdated in the
documentation already, so it is removed in the code as well.

Resolves: #72830
Releases: master
Change-Id: Ibd8e34071e784d41db0f8a76059c150308820dbb
Reviewed-on: https://review.typo3.org/46104
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Daniel Gorges <daniel.gorges@b13.de>
Tested-by: Daniel Gorges <daniel.gorges@b13.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
---
 .../core/Classes/Html/RteHtmlParser.php       | 42 +++++--------------
 ...ecatedRTETransformationsTsTs_transform.rst | 30 +++++++++++++
 2 files changed, 40 insertions(+), 32 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Breaking-72830-RemovedDeprecatedRTETransformationsTsTs_transform.rst

diff --git a/typo3/sysext/core/Classes/Html/RteHtmlParser.php b/typo3/sysext/core/Classes/Html/RteHtmlParser.php
index 99babe2b4345..31841d32730d 100644
--- a/typo3/sysext/core/Classes/Html/RteHtmlParser.php
+++ b/typo3/sysext/core/Classes/Html/RteHtmlParser.php
@@ -143,10 +143,6 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
         }
         $revmodes = array_flip($modes);
         // Find special modes and extract them:
-        if (isset($revmodes['ts'])) {
-            $modes[$revmodes['ts']] = 'ts_transform,ts_preserve,ts_images,ts_links';
-        }
-        // Find special modes and extract them:
         if (isset($revmodes['ts_css'])) {
             $modes[$revmodes['ts_css']] = 'css_transform,ts_images,ts_links';
         }
@@ -192,8 +188,6 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                         case 'ts_preserve':
                             $value = $this->TS_preserve_db($value);
                             break;
-                        case 'ts_transform':
-
                         case 'css_transform':
                             $this->allowedClasses = GeneralUtility::trimExplode(',', $this->procOptions['allowedClasses'], true);
                             // CR has a very disturbing effect, so just remove all CR and rely on LF
@@ -202,7 +196,7 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                             $value = str_replace('<p></p>', '<p>&nbsp;</p>', $value);
                             // Double any trailing spacing paragraph so that it does not get removed by divideIntoLines()
                             $value = preg_replace('/<p>&nbsp;<\/p>$/', '<p>&nbsp;</p>' . '<p>&nbsp;</p>', $value);
-                            $value = $this->TS_transform_db($value, $cmd == 'css_transform');
+                            $value = $this->TS_transform_db($value);
                             break;
                         default:
                             // Do nothing
@@ -231,12 +225,10 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                         case 'ts_preserve':
                             $value = $this->TS_preserve_rte($value);
                             break;
-                        case 'ts_transform':
-
                         case 'css_transform':
                             // Has a very disturbing effect, so just remove all '13' - depend on '10'
                             $value = str_replace(CR, '', $value);
-                            $value = $this->TS_transform_rte($value, $cmd == 'css_transform');
+                            $value = $this->TS_transform_rte($value);
                             break;
                         default:
                             // Do nothing
@@ -792,15 +784,14 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
     }
 
     /**
-     * Transformation handler: 'ts_transform' + 'css_transform' / direction: "db"
+     * Transformation handler: 'css_transform' / direction: "db"
      * Cleaning (->db) for standard content elements (ts)
      *
      * @param string $value Content input
-     * @param bool $css If TRUE, the transformation was "css_transform", otherwise "ts_transform
      * @return string Content output
      * @see TS_transform_rte()
      */
-    public function TS_transform_db($value, $css = false)
+    public function TS_transform_db($value)
     {
         // Safety... so forever loops are avoided (they should not occur, but an error would potentially do this...)
         $this->TS_transform_db_safecounter--;
@@ -836,14 +827,12 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                     case 'nav':
                     case 'article':
                     case 'aside':
-                        $blockSplit[$k] = $tag . $this->TS_transform_db($this->removeFirstAndLastTag($blockSplit[$k]), $css) . '</' . $tagName . '>' . $lastBR;
+                        $blockSplit[$k] = $tag . $this->TS_transform_db($this->removeFirstAndLastTag($blockSplit[$k])) . '</' . $tagName . '>' . $lastBR;
                         break;
                     case 'ol':
                     case 'ul':
                     case 'table':
-                        if ($css) {
-                            $blockSplit[$k] = preg_replace(('/[' . LF . CR . ']+/'), ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
-                        }
+                        $blockSplit[$k] = preg_replace(('/[' . LF . CR . ']+/'), ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
                         break;
                     case 'h1':
                     case 'h2':
@@ -851,18 +840,8 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                     case 'h4':
                     case 'h5':
                     case 'h6':
-                        if (!$css) {
-                            list($attribArray) = $this->get_tag_attributes($tag);
-                            // Processing inner content here:
-                            $innerContent = $this->HTMLcleaner_db($this->removeFirstAndLastTag($blockSplit[$k]));
-                            $blockSplit[$k] = '<' . $tagName . ($attribArray['align'] ? ' align="' . htmlspecialchars($attribArray['align']) . '"' : '') . ($attribArray['class'] ? ' class="' . htmlspecialchars($attribArray['class']) . '"' : '') . '>' . $innerContent . '</' . $tagName . '>' . $lastBR;
-                        } else {
-                            // Eliminate true linebreaks inside Hx tags
-                            $blockSplit[$k] = preg_replace(('/[' . LF . CR . ']+/'), ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
-                        }
-                        break;
                     default:
-                        // Eliminate true linebreaks inside other headlist tags
+                        // Eliminate true linebreaks inside Hx and other headlist tags
                         $blockSplit[$k] = preg_replace(('/[' . LF . CR . ']+/'), ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
                 }
             } else {
@@ -913,15 +892,14 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
     }
 
     /**
-     * Transformation handler: 'ts_transform' + 'css_transform' / direction: "rte"
+     * Transformation handler: css_transform / direction: "rte"
      * Set (->rte) for standard content elements (ts)
      *
      * @param string $value Content input
-     * @param bool $css If TRUE, the transformation was "css_transform", otherwise "ts_transform
      * @return string Content output
      * @see TS_transform_db()
      */
-    public function TS_transform_rte($value, $css = false)
+    public function TS_transform_rte($value)
     {
         // Split the content from database by the occurrence of the block elements
         $blockElementList = 'TABLE,BLOCKQUOTE,' . ($this->procOptions['preserveDIVSections'] ? 'DIV,' : '') . $this->blockElementList;
@@ -944,7 +922,7 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                     case 'nav':
                     case 'article':
                     case 'aside':
-                        $blockSplit[$k] = $tag . $this->TS_transform_rte($this->removeFirstAndLastTag($blockSplit[$k]), $css) . '</' . $tagName . '>';
+                        $blockSplit[$k] = $tag . $this->TS_transform_rte($this->removeFirstAndLastTag($blockSplit[$k])) . '</' . $tagName . '>';
                         break;
                 }
                 $blockSplit[$k + 1] = preg_replace('/^[ ]*' . LF . '/', '', $blockSplit[$k + 1]);
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-72830-RemovedDeprecatedRTETransformationsTsTs_transform.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-72830-RemovedDeprecatedRTETransformationsTsTs_transform.rst
new file mode 100644
index 000000000000..2987bdfa78d8
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-72830-RemovedDeprecatedRTETransformationsTsTs_transform.rst
@@ -0,0 +1,30 @@
+===========================================================================
+Breaking: #72830 - Removed deprecated RTE transformations ts & ts_transform
+===========================================================================
+
+Description
+===========
+
+The transformation option "ts" and "ts_transform" are outdated since the introduction of CSS Styled Content and were
+removed from the TYPO3 Core.
+
+The two related PHP methods ``TS_transform_rte`` and ``TS_transform_db`` have the second method parameter dropped.
+
+
+Impact
+======
+
+Setting the TSconfig option ``RTE.proc.overruleMethod = ts`` or ``RTE.proc.overruleMethod = ts_transform`` will result
+in not having any transformation applied to the content anymore.
+
+
+Affected Installations
+======================
+
+Any installation with custom RTE transformation options to render legacy HTML code.
+
+
+Migration
+=========
+
+Use ``ts_css`` instead, which is set by default since TYPO3 4.0.
\ No newline at end of file
-- 
GitLab