From 76706f572ce1f0848342de1b553dcc006c150052 Mon Sep 17 00:00:00 2001
From: Stanislas Rolland <typo3@sjbr.ca>
Date: Fri, 21 Feb 2014 10:54:53 -0500
Subject: [PATCH] [BUGFIX] RTE cannot run in IE 11+ with ExtJS 3.4.1

Solution: Configure a hook in frontend to add a meta tag just after
the head tag whenever rtehtmlarea is in use on the page and the user
agent is IE 11+. The meta tag instructs IE to emulate IE 10.

Resolves: #56192
Releases: 6.2
Change-Id: Icc81f14c107360a47a34403032e5fe7890f1d784
Reviewed-on: https://review.typo3.org/27776
Reviewed-by: Markus Klein
Reviewed-by: Wouter Wolters
Reviewed-by: Stanislas Rolland
Tested-by: Stanislas Rolland
---
 .../TypoScriptFrontendControllerHook.php      | 50 +++++++++++++++++++
 .../Frontend/Controller/ext_localconf.php     |  8 +++
 typo3/sysext/rtehtmlarea/ext_localconf.php    |  2 +
 3 files changed, 60 insertions(+)
 create mode 100644 typo3/sysext/rtehtmlarea/Classes/Hook/Frontend/Controller/TypoScriptFrontendControllerHook.php
 create mode 100644 typo3/sysext/rtehtmlarea/Configuration/Hook/Frontend/Controller/ext_localconf.php

diff --git a/typo3/sysext/rtehtmlarea/Classes/Hook/Frontend/Controller/TypoScriptFrontendControllerHook.php b/typo3/sysext/rtehtmlarea/Classes/Hook/Frontend/Controller/TypoScriptFrontendControllerHook.php
new file mode 100644
index 000000000000..04f63ef283dc
--- /dev/null
+++ b/typo3/sysext/rtehtmlarea/Classes/Hook/Frontend/Controller/TypoScriptFrontendControllerHook.php
@@ -0,0 +1,50 @@
+<?php
+namespace TYPO3\CMS\Rtehtmlarea\Hook\Frontend\Controller;
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2014 Stanislas Rolland <stanislas.rolland@typo3.org>
+ *  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 text file 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!
+ ***************************************************************/
+/**
+ * Frontend hook to add meta tag when rtehtmlarea is present and user agent is IE 11+
+ *
+ */
+class TypoScriptFrontendControllerHook {
+
+	/**
+	 * Add meta tag when rtehtmlarea is present and user agent is IE 11+
+	 *
+	 * @param array $params
+	 * @param \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $controller
+	 * @return void
+	 */
+	public function contentPostProcOutput(array $params, \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $controller) {
+		if (strpos($controller->content, 'textarea id="RTEarea') !== FALSE) {
+			$userAgent = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_USER_AGENT');
+			$browserInfo = \TYPO3\CMS\Core\Utility\ClientUtility::getBrowserInfo($userAgent);
+			if ($browserInfo['browser'] === 'msie' && $browserInfo['version'] > 10) {
+				$controller->content = preg_replace('/<head([^>]*)>/', '<head$1>' . LF . '<meta http-equiv="X-UA-Compatible" content="IE=10" />', $controller->content);
+			}
+		}
+	}
+}
diff --git a/typo3/sysext/rtehtmlarea/Configuration/Hook/Frontend/Controller/ext_localconf.php b/typo3/sysext/rtehtmlarea/Configuration/Hook/Frontend/Controller/ext_localconf.php
new file mode 100644
index 000000000000..bd35116a6375
--- /dev/null
+++ b/typo3/sysext/rtehtmlarea/Configuration/Hook/Frontend/Controller/ext_localconf.php
@@ -0,0 +1,8 @@
+<?php
+if (!defined('TYPO3_MODE')) {
+	die('Access denied.');
+}
+if (TYPO3_MODE === 'FE') {
+	// Register frontend hook to add meta tag when rtehtmlarea is present and user agent is IE 11+
+	$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-output']['rtehtmlarea'] = 'TYPO3\\CMS\\Rtehtmlarea\\Hook\\Frontend\\Controller\\TypoScriptFrontendControllerHook->contentPostProcOutput';
+}
diff --git a/typo3/sysext/rtehtmlarea/ext_localconf.php b/typo3/sysext/rtehtmlarea/ext_localconf.php
index 32e8d5de55bb..4b5d6555d310 100644
--- a/typo3/sysext/rtehtmlarea/ext_localconf.php
+++ b/typo3/sysext/rtehtmlarea/ext_localconf.php
@@ -67,6 +67,8 @@ if (strstr($_EXTCONF['defaultConfiguration'], 'Minimal')) {
 require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'hooks/softref/ext_localconf.php';
 // Add Status Report about Conflicting Extensions
 require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'hooks/statusreport/ext_localconf.php';
+// Add frontend hook to add meta tag when rtehtmlarea is present and user agent is IE 11+
+require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Configuration/Hook/Frontend/Controller/ext_localconf.php';
 
 // Configure Lorem Ipsum hook to insert nonsense in wysiwyg mode
 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('lorem_ipsum') && TYPO3_MODE == 'BE') {
-- 
GitLab