[BUGFIX] RTE: Link to disabled page doesn't show in FE, link icon does
authorStanislas Rolland <typo3@sjbr.ca>
Tue, 16 Oct 2012 14:45:24 +0000 (10:45 -0400)
committerStanislas Rolland <typo3@sjbr.ca>
Thu, 18 Oct 2012 22:04:06 +0000 (00:04 +0200)
Problem: When linking from a piece of content in the RTE to a disabled
page in the tree, the link isn't shown in the final frontend rendering.
However, the small arrow icon that you can have in front of the link to
denote its type, does get shown.
Solution: Remove the icon if no link is generated

Change-Id: If2f5af7ef81578571ed0a1255a53d9373f14bfed
Resolves: #36087
Releases: 4.5, 4.6, 4.7, 6.0
Reviewed-on: http://review.typo3.org/15802
Reviewed-by: Stanislas Rolland
Tested-by: Stanislas Rolland
typo3/sysext/rtehtmlarea/Classes/Controller/AccessibilityLinkController.php [new file with mode: 0644]
typo3/sysext/rtehtmlarea/ext_autoload.php
typo3/sysext/rtehtmlarea/ext_localconf.php
typo3/sysext/rtehtmlarea/res/accessibilityicons/setup.txt [new file with mode: 0644]

diff --git a/typo3/sysext/rtehtmlarea/Classes/Controller/AccessibilityLinkController.php b/typo3/sysext/rtehtmlarea/Classes/Controller/AccessibilityLinkController.php
new file mode 100644 (file)
index 0000000..3629cae
--- /dev/null
@@ -0,0 +1,125 @@
+<?php
+namespace TYPO3\CMS\Rtehtmlarea\Controller;
+
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  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.
+*  A copy is found in the textfile GPL.txt and important notices to the license
+*  from the author is found in LICENSE.txt distributed with these scripts.
+*
+*
+*  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!
+***************************************************************/
+/**
+ * Remove accessibility icon when no link was rendered
+ *
+ * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
+ */
+class AccessibilityLinkController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
+
+       /**
+        * Same as class name
+        */
+       public $prefixId = 'AccessibilityLinkController';
+
+       /**
+        * Path to this script relative to the extension dir
+        */
+       public $scriptRelPath = 'Classes/Controller/AccessibilityLinkController.php';
+
+       /**
+        * The extension key
+        */
+       public $extKey = 'rtehtmlarea';
+
+       /**
+        * Configuration
+        */
+       public $conf = array();
+
+       /**
+        * cObj object
+        *
+        * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
+        */
+       public $cObj;
+
+       /**
+        * Remove accessibility icon when no link was rendered, called from TypoScript
+        *
+        * @param       string          Content input. Not used, ignore.
+        * @param       array           TypoScript configuration
+        * @return      string          HTML output.
+        * @access private
+        */
+       public function removeAccessibilityIcon ($content, $conf) {
+               // If the link was not rendered
+               if (substr($content, 0, 3) !== '<a ' && substr($content, 0, 5) === '<img ') {
+                       // Let's remove the accessibility icon, if there is one
+                       $matches = array();
+                       if (preg_match('/^<img .*>/', $content, $matches) === 1) {
+                               $attributes = \TYPO3\CMS\Core\Utility\GeneralUtility::get_tag_attributes($matches[0]);
+                               if ($attributes['src']) {
+                                       // Get RTE Configconfiguration
+                                       $pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
+                                       if (is_array($pageTSConfig) && is_array($pageTSConfig['RTE.'])) {
+                                               $classesAnchorConfiguration = $pageTSConfig['RTE.']['classesAnchor.'];
+                                               if (is_array($classesAnchorConfiguration)) {
+                                                       // Make the url of the source relative
+                                                       $siteUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
+                                                       if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($attributes['src'], $siteUrl)) {
+                                                               $attributes['src'] = substr($attributes['src'], strlen($siteUrl));
+                                                       }
+                                                       // Lookup the RTE.classesAnchor array
+                                                       foreach ($classesAnchorConfiguration as $item => $conf) {
+                                                               if ($conf['image']) {
+                                                                       $imagePath = $this->getFullFileName(trim(str_replace('\'', '', str_replace('"', '', $conf['image']))));
+                                                                       if ($attributes['src'] === $imagePath) {
+                                                                               // If found, remove the img tag and break
+                                                                               $content = substr($content, strlen($matches[0]));
+                                                                               break;
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+               return $content;
+       }
+       /*
+        * Returns the full name of a file referenced in Page TSConfig
+        */
+       protected function getFullFileName($filename) {
+               if (substr($filename, 0, 4) == 'EXT:') {
+                       list($extKey, $local) = explode('/', substr($filename, 4), 2);
+                       $newFilename = '';
+                       if (strcmp($extKey, '') && \TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded($extKey) && strcmp($local, '')) {
+                               $newFilename = \TYPO3\CMS\Core\Extension\ExtensionManager::siteRelPath($extKey) . $local;
+                       }
+               } elseif (substr($filename, 0, 1) != '/') {
+                       $newFilename = $filename;
+               } else {
+                       $newFilename = substr($filename, 1);
+               }
+               return  \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath($newFilename);
+       }
+}
+?>
\ No newline at end of file
index b795266..a6a282c 100644 (file)
@@ -11,6 +11,7 @@ return array(
        'tx_rtehtmlarea_pi1' => $rtehtmlareaExtensionPath . 'pi1/class.tx_rtehtmlarea_pi1.php',
        'tx_rtehtmlarea_pi2' => $rtehtmlareaExtensionPath . 'pi2/class.tx_rtehtmlarea_pi2.php',
        'tx_rtehtmlarea_pi3' => $rtehtmlareaExtensionPath . 'pi3/class.tx_rtehtmlarea_pi3.php',
+       'AccessibilityLinkController' => $rtehtmlareaExtensionPath . 'Classes/Controller/AccessibilityLinkController.php',
        'tx_rtehtmlarea_browse_links' => $rtehtmlareaExtensionPath . 'mod3/class.tx_rtehtmlarea_browse_links.php',
        'tx_rtehtmlarea_select_image' => $rtehtmlareaExtensionPath . 'mod4/class.tx_rtehtmlarea_select_image.php',
        'tx_rtehtmlarea_user' => $rtehtmlareaExtensionPath . 'mod5/class.tx_rtehtmlarea_user.php',
index 38409a8..7dedab5 100644 (file)
@@ -161,6 +161,7 @@ $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['TYPO3Link']['additionalAttribu
 $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['enableAccessibilityIcons'] = $_EXTCONF['enableAccessibilityIcons'] ? $_EXTCONF['enableAccessibilityIcons'] : 0;
 if ($TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['enableAccessibilityIcons']) {
        \TYPO3\CMS\Core\Extension\ExtensionManager::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:' . $_EXTKEY . '/res/accessibilityicons/pageTSConfig.txt">');
+       \TYPO3\CMS\Core\Extension\ExtensionManager::addTypoScript($_EXTKEY, 'setup', '<INCLUDE_TYPOSCRIPT: source="FILE:EXT:' . $_EXTKEY . '/res/accessibilityicons/setup.txt">', 43);
 }
 // Register features that use the style attribute
 $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['allowStyleAttribute'] = isset($_EXTCONF['allowStyleAttribute']) && !$_EXTCONF['allowStyleAttribute'] ? 0 : 1;
diff --git a/typo3/sysext/rtehtmlarea/res/accessibilityicons/setup.txt b/typo3/sysext/rtehtmlarea/res/accessibilityicons/setup.txt
new file mode 100644 (file)
index 0000000..0c42bc0
--- /dev/null
@@ -0,0 +1,3 @@
+## TS setup for accessibility icons feature
+
+lib.parseFunc_RTE.tags.link.postUserFunc = TYPO3\CMS\Rtehtmlarea\Controller\AccessibilityLinkController->removeAccessibilityIcon
\ No newline at end of file