[TASK] Cosmetic cleanup in RteHtmlParser 52/46152/4
authorBenni Mack <benni@typo3.org>
Fri, 22 Jan 2016 12:31:10 +0000 (13:31 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 22 Jan 2016 15:29:22 +0000 (16:29 +0100)
Resolves: #72891
Releases: master
Change-Id: Ibdce616a78a770f874c9a1dc5831c53c1e03f44b
Reviewed-on: https://review.typo3.org/46152
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Html/RteHtmlParser.php
typo3/sysext/rtehtmlarea/Configuration/PageTSconfig/Proc/pageTSConfig.txt

index f35e214..b29b85c 100644 (file)
@@ -125,12 +125,12 @@ class RteHtmlParser extends HtmlParser
         if ($this->procOptions['blockElementList']) {
             $this->blockElementList = $this->procOptions['blockElementList'];
         }
-        // Get parameters for rte_transformation:
-        $specialFieldConfiguration = BackendUtility::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
         // Setting modes:
         if ((string)$this->procOptions['overruleMode'] !== '') {
             $modes = array_unique(GeneralUtility::trimExplode(',', $this->procOptions['overruleMode']));
         } else {
+            // Get parameters for rte_transformation:
+            $specialFieldConfiguration = BackendUtility::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
             $modes = array_unique(GeneralUtility::trimExplode('-', $specialFieldConfiguration['mode']));
         }
         $revmodes = array_flip($modes);
@@ -767,25 +767,15 @@ class RteHtmlParser extends HtmlParser
                     case 'aside':
                         $blockSplit[$k] = $tag . $this->TS_transform_db($this->removeFirstAndLastTag($blockSplit[$k])) . '</' . $tagName . '>' . $lastBR;
                         break;
-                    case 'ol':
-                    case 'ul':
-                    case 'table':
-                        $blockSplit[$k] = preg_replace(('/[' . LF . CR . ']+/'), ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
-                        break;
-                    case 'h1':
-                    case 'h2':
-                    case 'h3':
-                    case 'h4':
-                    case 'h5':
-                    case 'h6':
                     default:
-                        // Eliminate true linebreaks inside Hx and other headlist tags
+                        // usually <hx> tags and <table> tags where no other block elements are within the tags
+                        // Eliminate true linebreaks inside block element tags
                         $blockSplit[$k] = preg_replace(('/[' . LF . CR . ']+/'), ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
                 }
             } else {
                 // NON-block:
                 if (trim($blockSplit[$k]) !== '') {
-                    $blockSplit[$k] = preg_replace('/<hr\\/>/', '<hr />', $blockSplit[$k]);
+                    $blockSplit[$k] = str_replace('<hr/>', '<hr />', $blockSplit[$k]);
                     // Remove linebreaks preceding hr tags
                     $blockSplit[$k] = preg_replace('/[' . LF . CR . ']+<(hr)(\\s[^>\\/]*)?[[:space:]]*\\/?>/', '<$1$2/>', $blockSplit[$k]);
                     // Remove linebreaks following hr tags
@@ -1042,28 +1032,28 @@ class RteHtmlParser extends HtmlParser
                         $subLines[$sk] = $this->HTMLcleaner_db($subLines[$sk]);
                         // Get first tag, attributes etc:
                         $fTag = $this->getFirstTag($divSplit[$k]);
-                        $attribs = $this->get_tag_attributes($fTag);
+                        list($tagAttributes) = $this->get_tag_attributes($fTag);
                         // Keep attributes (lowercase)
                         $newAttribs = array();
                         if (!empty($keepAttribListArr)) {
                             foreach ($keepAttribListArr as $keepA) {
-                                if (isset($attribs[0][$keepA])) {
-                                    $newAttribs[$keepA] = $attribs[0][$keepA];
+                                if (isset($tagAttributes[$keepA])) {
+                                    $newAttribs[$keepA] = $tagAttributes[$keepA];
                                 }
                             }
                         }
                         // ALIGN attribute:
-                        if (!$this->procOptions['skipAlign'] && trim($attribs[0]['align']) !== '' && strtolower($attribs[0]['align']) != 'left') {
+                        if (!$this->procOptions['skipAlign'] && trim($tagAttributes['align']) !== '' && strtolower($tagAttributes['align']) != 'left') {
                             // Set to value, but not 'left'
-                            $newAttribs['align'] = strtolower($attribs[0]['align']);
+                            $newAttribs['align'] = strtolower($tagAttributes['align']);
                         }
                         // CLASS attribute:
                         // Set to whatever value
-                        if (!$this->procOptions['skipClass'] && trim($attribs[0]['class']) !== '') {
-                            if (empty($this->allowedClasses) || in_array($attribs[0]['class'], $this->allowedClasses)) {
-                                $newAttribs['class'] = $attribs[0]['class'];
+                        if (!$this->procOptions['skipClass'] && trim($tagAttributes['class']) !== '') {
+                            if (empty($this->allowedClasses) || in_array($tagAttributes['class'], $this->allowedClasses)) {
+                                $newAttribs['class'] = $tagAttributes['class'];
                             } else {
-                                $classes = GeneralUtility::trimExplode(' ', $attribs[0]['class'], true);
+                                $classes = GeneralUtility::trimExplode(' ', $tagAttributes['class'], true);
                                 $newClasses = array();
                                 foreach ($classes as $class) {
                                     if (in_array($class, $this->allowedClasses)) {
index 0d4754b..f2760cf 100644 (file)
@@ -19,8 +19,8 @@ RTE.default.proc {
                ## br tags in the content are assumed to be intentional.
        dontConvBRtoParagraph = 1
 
-               ## TAGS ALLOWED OUTSIDE P & DIV
-       allowTagsOutside = address, article, aside, blockquote, footer, header, hr, nav, section
+               ## TAGS ALLOWED OUTSIDE P
+       allowTagsOutside = address, article, aside, blockquote, footer, header, hr, nav, section, div
 
                ## TAGS ALLOWED
                ## Added to the default internal list: b,i,u,a,img,br,div,center,pre,font,hr,sub,sup,p,strong,em,li,ul,ol,blockquote,strike,span
@@ -36,7 +36,7 @@ RTE.default.proc {
                ## Make sure we can set rules on any tag listed in allowTags.
        denyTags >
 
-               ## ALLOWED P & DIV ATTRIBUTES
+               ## ALLOWED P ATTRIBUTES
                ## Attributes class and align are always preserved
                ## Align attribute will be unset on entry (see below)
                ## This is a list of additional attributes to keep