Skip to content

Commit

Permalink
[BUGFIX] Prevent data-htmlarea-external link attribute
Browse files Browse the repository at this point in the history
A hook was implemented for the RteHtmlParser class to
prevent the attribute from being re-inserted by the parser because
it does not recognize the link type.
  • Loading branch information
astehlik committed Feb 17, 2014
1 parent 75e5525 commit 41d29fd
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
80 changes: 80 additions & 0 deletions Classes/RteParserHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
namespace Aoe\Linkhandler;

/***************************************************************
* Copyright notice
*
* Copyright (c) 2014, Alexander Stehlik <astehlik.deleteme@intera.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
* Hook for the RTE link parser.
*
* Makes sure that the "data-htmlarea-external" tag is not set for linkhandler links.
*/
class RteParserHook {

/**
* @var \TYPO3\CMS\Core\Html\RteHtmlParser
*/
protected $rteHtmlParser;

/**
* Will be called by RteHtmlParser.
*
* @param array $parameters
* @param \TYPO3\CMS\Core\Html\RteHtmlParser $rteHtmlParser
* @return string
*/
public function modifyParamsLinksRte($parameters, $rteHtmlParser) {

$this->rteHtmlParser = $rteHtmlParser;

$currentBlock = $parameters['currentBlock'];
$url = $parameters['url'];
$tagCode = $parameters['tagCode'];
$external = $parameters['external'];
$error = $parameters['error'];

if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($url, 'record:')) {
$external = FALSE;
}

return $this->buildOriginalLink($url, $tagCode, $external, $error, $currentBlock);
}

/**
* Builds the the link. The code is the same as in
* \TYPO3\CMS\Core\Html\RteHtmlParser::TS_links_rte()
*
* @param string $url
* @param array $tagCode
* @param bool $external
* @param string $error
* @param string $currentBlock
* @return string
* @see \TYPO3\CMS\Core\Html\RteHtmlParser::TS_links_rte()
*/
protected function buildOriginalLink($url, $tagCode, $external, $error, $currentBlock) {
$bTag = '<a href="' . htmlspecialchars($url) . '"' . ($tagCode[2] && $tagCode[2] != '-' ? ' target="' . htmlspecialchars($tagCode[2]) . '"' : '') . ($tagCode[3] && $tagCode[3] != '-' ? ' class="' . htmlspecialchars($tagCode[3]) . '"' : '') . ($tagCode[4] ? ' title="' . htmlspecialchars($tagCode[4]) . '"' : '') . ($external ? ' data-htmlarea-external="1"' : '') . ($error ? ' rteerror="' . htmlspecialchars($error) . '" style="background-color: yellow; border:2px red solid; color: black;"' : '') . '>';
$eTag = '</a>';
return $bTag . $this->rteHtmlParser->TS_links_rte($this->rteHtmlParser->removeFirstAndLastTag($currentBlock)) . $eTag;
}
}
1 change: 1 addition & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

//register hook
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php']['browseLinksHook'][] = 'Aoe\\Linkhandler\\Browser\\ElementBrowserHook';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['modifyParams_LinksRte_PostProc'][] = 'Aoe\\Linkhandler\\RteParserHook';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'][] = 'Aoe\\Linkhandler\\Browser\\ElementBrowserHook';

$linkhandlerExtConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['linkhandler']);
Expand Down

0 comments on commit 41d29fd

Please sign in to comment.