From 2c5bfc4811a858a5a7ae10c6d90458093ed2f95f Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Thu, 14 Jan 2016 08:03:16 +0100 Subject: [PATCH] [!!!][TASK] Remove obsolete RteHtmlParser logic and methods Removed: - RteHtmlParser->siteUrl() - RteHtmlParser->getUrl() - RteHtmlParser->HTMLcleaner_db() second parameter unused - RteHtmlParser->getKeepTags() second parameter unused Resolves: #72686 Releases: master Change-Id: I0c4b4b6d17e3310218f9affc6d46418c1722ab68 Reviewed-on: https://review.typo3.org/45870 Reviewed-by: Andreas Fernandez <typo3@scripting-base.de> Tested-by: Andreas Fernandez <typo3@scripting-base.de> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Tested-by: Wouter Wolters <typo3@wouterwolters.nl> --- .../core/Classes/Html/RteHtmlParser.php | 83 +++++-------------- ...king-72686-RemovedRteHtmlParserMethods.rst | 38 +++++++++ 2 files changed, 61 insertions(+), 60 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Breaking-72686-RemovedRteHtmlParserMethods.rst diff --git a/typo3/sysext/core/Classes/Html/RteHtmlParser.php b/typo3/sysext/core/Classes/Html/RteHtmlParser.php index 7600c5c24b95..91f6fb77d45e 100644 --- a/typo3/sysext/core/Classes/Html/RteHtmlParser.php +++ b/typo3/sysext/core/Classes/Html/RteHtmlParser.php @@ -272,7 +272,7 @@ class RteHtmlParser extends HtmlParser // Split content by <img> tags and traverse the resulting array for processing: $imgSplit = $this->splitTags('img', $value); if (count($imgSplit) > 1) { - $siteUrl = $this->siteUrl(); + $siteUrl = GeneralUtility::getIndpEnv('TYPO3_SITE_URL'); $sitePath = str_replace(GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST'), '', $siteUrl); /** @var $resourceFactory Resource\ResourceFactory */ $resourceFactory = Resource\ResourceFactory::getInstance(); @@ -344,7 +344,7 @@ class RteHtmlParser extends HtmlParser } elseif (!GeneralUtility::isFirstPartOfStr($absoluteUrl, $siteUrl) && !$this->procOptions['dontFetchExtPictures'] && TYPO3_MODE === 'BE') { // External image from another URL: in that case, fetch image, unless the feature is disabled or we are not in backend mode // Fetch the external image - $externalFile = $this->getUrl($absoluteUrl); + $externalFile = GeneralUtility::getUrl($absoluteUrl); if ($externalFile) { $pU = parse_url($absoluteUrl); $pI = pathinfo($pU['path']); @@ -426,7 +426,7 @@ class RteHtmlParser extends HtmlParser // Split content by <img> tags and traverse the resulting array for processing: $imgSplit = $this->splitTags('img', $value); if (count($imgSplit) > 1) { - $siteUrl = $this->siteUrl(); + $siteUrl = GeneralUtility::getIndpEnv('TYPO3_SITE_URL'); $sitePath = str_replace(GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST'), '', $siteUrl); foreach ($imgSplit as $k => $v) { // Image found @@ -468,7 +468,7 @@ class RteHtmlParser extends HtmlParser $retVal = $this->TS_AtagToAbs($value, 1); break; case 'db': - $siteURL = $this->siteUrl(); + $siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL'); $blockSplit = $this->splitIntoBlock('A', $value); foreach ($blockSplit as $k => $v) { // Block @@ -564,7 +564,7 @@ class RteHtmlParser extends HtmlParser // Unsetting 'rtekeep' attribute if that had been set. unset($attribArray['rtekeep']); if (!$attribArray['data-htmlarea-external']) { - $siteURL = $this->siteUrl(); + $siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL'); // If the url is local, remove url-prefix if ($siteURL && substr($attribArray['href'], 0, strlen($siteURL)) == $siteURL) { $attribArray['href'] = substr($attribArray['href'], strlen($siteURL)); @@ -606,7 +606,7 @@ class RteHtmlParser extends HtmlParser $value = $this->TS_AtagToAbs($value); // Split content by the TYPO3 pseudo tag "<link>": $blockSplit = $this->splitIntoBlock('link', $value, 1); - $siteUrl = $this->siteUrl(); + $siteUrl = GeneralUtility::getIndpEnv('TYPO3_SITE_URL'); foreach ($blockSplit as $k => $v) { $error = ''; $external = false; @@ -955,17 +955,6 @@ class RteHtmlParser extends HtmlParser * Generic RTE transformation, analysis and helper functions * **************************************************************/ - /** - * Reads the file or url $url and returns the content - * - * @param string $url Filepath/URL to read - * @return string The content from the resource given as input. - * @see \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl() - */ - public function getUrl($url) - { - return GeneralUtility::getUrl($url); - } /** * Function for cleaning content going into the database. @@ -973,22 +962,17 @@ class RteHtmlParser extends HtmlParser * It is basically calling HTMLcleaner from the parent class with some preset configuration specifically set up for cleaning content going from the RTE into the db * * @param string $content Content to clean up - * @param string $tagList Comma list of tags to specifically allow. Default comes from getKeepTags and is * @return string Clean content * @see getKeepTags() */ - public function HTMLcleaner_db($content, $tagList = '') + public function HTMLcleaner_db($content) { - if (!$tagList) { - $keepTags = $this->getKeepTags('db'); - } else { - $keepTags = $this->getKeepTags('db', $tagList); - } + $keepTags = $this->getKeepTags('db'); // Default: remove unknown tags. - $kUknown = $this->procOptions['dontRemoveUnknownTags_db'] ? 1 : 0; + $keepUnknownTags = (bool)$this->procOptions['dontRemoveUnknownTags_db']; // Default: re-convert literals to characters (that is < to <) $hSC = $this->procOptions['dontUndoHSC_db'] ? 0 : -1; - return $this->HTMLcleaner($content, $keepTags, $kUknown, $hSC); + return $this->HTMLcleaner($content, $keepTags, $keepUnknownTags, $hSC); } /** @@ -996,26 +980,20 @@ class RteHtmlParser extends HtmlParser * Unless "tagList" is given, the function will cache the configuration for next time processing goes on. (In this class that is the case only if we are processing a bulletlist) * * @param string $direction The direction of the content being processed by the output configuration; "db" (content going into the database FROM the rte) or "rte" (content going into the form) - * @param string $tagList Comma list of tags to keep (overriding default which is to keep all + take notice of internal configuration) * @return array Configuration array * @see HTMLcleaner_db() */ - public function getKeepTags($direction = 'rte', $tagList = '') + public function getKeepTags($direction = 'rte') { - if (!is_array($this->getKeepTags_cache[$direction]) || $tagList) { + if (!is_array($this->getKeepTags_cache[$direction])) { // Setting up allowed tags: - // If the $tagList input var is set, this will take precedence - if ((string)$tagList !== '') { - $keepTags = array_flip(GeneralUtility::trimExplode(',', $tagList, true)); - } else { - // Default is to get allowed/denied tags from internal array of processing options: - // Construct default list of tags to keep: - $keepTags = array_flip(GeneralUtility::trimExplode(',', $this->defaultAllowedTagsList . ',' . strtolower($this->procOptions['allowTags']), true)); - // For tags to deny, remove them from $keepTags array: - $denyTags = GeneralUtility::trimExplode(',', $this->procOptions['denyTags'], true); - foreach ($denyTags as $dKe) { - unset($keepTags[$dKe]); - } + // Default is to get allowed/denied tags from internal array of processing options: + // Construct default list of tags to keep: + $keepTags = array_flip(GeneralUtility::trimExplode(',', $this->defaultAllowedTagsList . ',' . strtolower($this->procOptions['allowTags']), true)); + // For tags to deny, remove them from $keepTags array: + $denyTags = GeneralUtility::trimExplode(',', $this->procOptions['denyTags'], true); + foreach ($denyTags as $dKe) { + unset($keepTags[$dKe]); } // Based on the direction of content, set further options: switch ($direction) { @@ -1070,11 +1048,7 @@ class RteHtmlParser extends HtmlParser break; } // Caching (internally, in object memory) the result unless tagList is set: - if (!$tagList) { - $this->getKeepTags_cache[$direction] = $keepTags; - } else { - return $keepTags; - } + $this->getKeepTags_cache[$direction] = $keepTags; } // Return result: return $this->getKeepTags_cache[$direction]; @@ -1118,7 +1092,7 @@ class RteHtmlParser extends HtmlParser $v = $this->removeFirstAndLastTag($v); // Fetching 'sub-lines' - which will explode any further p nesting... $subLines = $this->divideIntoLines($v, $count - 1, true); - // So, if there happend to be sub-nesting of p, this is written directly as the new content of THIS section. (This would be considered 'an error') + // So, if there happened to be sub-nesting of p, this is written directly as the new content of THIS section. (This would be considered 'an error') if (!is_array($subLines)) { //... but if NO subsection was found, we process it as a TRUE line without erronous content: $subLines = array($subLines); @@ -1244,17 +1218,6 @@ class RteHtmlParser extends HtmlParser return implode(LF, $parts); } - /** - * Returns SiteURL based on thisScript. - * - * @return string Value of GeneralUtility::getIndpEnv('TYPO3_SITE_URL'); - * @see \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv() - */ - public function siteUrl() - { - return GeneralUtility::getIndpEnv('TYPO3_SITE_URL'); - } - /** * Default tag mapping for TS * @@ -1329,7 +1292,7 @@ class RteHtmlParser extends HtmlParser $info['type'] = 'file'; $info['url'] = rawurldecode(substr($url, strpos($url, '?file:') + 1)); } else { - $curURL = $this->siteUrl(); + $curURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL'); $urlLength = strlen($url); for ($a = 0; $a < $urlLength; $a++) { if ($url[$a] != $curURL[$a]) { @@ -1394,7 +1357,7 @@ class RteHtmlParser extends HtmlParser if ($attribArray['href'] !== '') { $uP = parse_url(strtolower($attribArray['href'])); if (!$uP['scheme']) { - $attribArray['href'] = $this->siteUrl() . $attribArray['href']; + $attribArray['href'] = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $attribArray['href']; } elseif ($uP['scheme'] != 'mailto') { $attribArray['data-htmlarea-external'] = 1; } diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-72686-RemovedRteHtmlParserMethods.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-72686-RemovedRteHtmlParserMethods.rst new file mode 100644 index 000000000000..fc97490daab9 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-72686-RemovedRteHtmlParserMethods.rst @@ -0,0 +1,38 @@ +================================================ +Breaking: #72686 - Removed RteHtmlParser methods +================================================ + +Description +=========== + +The following methods within ``RteHtmlParser`` were removed without substitution: + + * ``RteHtmlParser->siteUrl()`` + * ``RteHtmlParser->getUrl()`` + +The second method parameter of the following methods were removed as they have no effect anymore: + + * ``RteHtmlParser->HTMLcleaner_db()`` + * ``RteHtmlParser->getKeepTags()`` + + +Impact +====== + +Calling either ``RteHtmlParser->siteUrl()`` or ``RteHtmlParser->getUrl()`` will result in a PHP fatal error. + +Calling ``RteHtmlParser->HTMLcleaner_db()`` or ``RteHtmlParser->getKeepTags()`` with a second parameter will have no effect anymore. + + +Affected Installations +====================== + +TYPO3 instances which use RteHtmlParser methods directly within a third-party extension for HTML transformation. + + +Migration +========= + +Use ``GeneralUtility::getUrl()`` instead of ``RteHtmlParser->getUrl()``. + +Use ``GeneralUtility::getIndpEnv('TYPO3_SITE_URL')`` instead of ``RteHtmlParser->siteUrl()``. \ No newline at end of file -- GitLab