[BUGFIX] Fix wrong JS function name in RTE
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / ContentParser.php
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2005-2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32 /**
33 * Content parsing for htmlArea RTE
34 *
35 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
36 */
37 class ContentParser {
38
39 /**
40 * @todo Define visibility
41 */
42 public $content;
43
44 /**
45 * @todo Define visibility
46 */
47 public $modData;
48
49 /**
50 * document template object
51 *
52 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
53 * @todo Define visibility
54 */
55 public $doc;
56
57 /**
58 * @todo Define visibility
59 */
60 public $extKey = 'rtehtmlarea';
61
62 /**
63 * @todo Define visibility
64 */
65 public $prefixId = 'TYPO3HtmlParser';
66
67 /**
68 * @return [type] ...
69 * @todo Define visibility
70 */
71 public function init() {
72 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
73 $this->doc->backPath = $GLOBALS['BACK_PATH'];
74 $this->doc->JScode = '';
75 $this->modData = $GLOBALS['BE_USER']->getModuleData($GLOBALS['MCONF']['name'], 'ses');
76 if (GeneralUtility::_GP('OC_key')) {
77 $parts = explode('|', GeneralUtility::_GP('OC_key'));
78 $this->modData['openKeys'][$parts[1]] = $parts[0] == 'O' ? 1 : 0;
79 $GLOBALS['BE_USER']->pushModuleData($GLOBALS['MCONF']['name'], $this->modData);
80 }
81 }
82
83 /**
84 * [Describe function...]
85 *
86 * @return [type] ...
87 * @todo Define visibility
88 */
89 public function main() {
90 $this->content .= $this->main_parse_html($this->modData['openKeys']);
91 header('Content-Type: text/plain; charset=utf-8');
92 }
93
94 /**
95 * [Describe function...]
96 *
97 * @return [type] ...
98 * @todo Define visibility
99 */
100 public function printContent() {
101 echo $this->content;
102 }
103
104 /**
105 * Rich Text Editor (RTE) html parser
106 *
107 * @param [type] $openKeys: ...
108 * @return [type] ...
109 * @todo Define visibility
110 */
111 public function main_parse_html($openKeys) {
112 global $TYPO3_CONF_VARS;
113 $editorNo = GeneralUtility::_GP('editorNo');
114 $html = GeneralUtility::_GP('content');
115 $RTEtsConfigParts = explode(':', GeneralUtility::_GP('RTEtsConfigParams'));
116 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
117 $thisConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
118 $HTMLParser = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Html\\HtmlParser');
119 if (is_array($thisConfig['enableWordClean.'])) {
120 $HTMLparserConfig = $thisConfig['enableWordClean.']['HTMLparser.'];
121 if (is_array($HTMLparserConfig)) {
122 $this->keepSpanTagsWithId($HTMLparserConfig);
123 $HTMLparserConfig = $HTMLParser->HTMLparserConfig($HTMLparserConfig);
124 }
125 }
126 if (is_array($HTMLparserConfig)) {
127 $html = $HTMLParser->HTMLcleaner($html, $HTMLparserConfig[0], $HTMLparserConfig[1], $HTMLparserConfig[2], $HTMLparserConfig[3]);
128 }
129 if (is_array($TYPO3_CONF_VARS['EXTCONF'][$this->extKey][$this->prefixId]['cleanPastedContent'])) {
130 foreach ($TYPO3_CONF_VARS['EXTCONF'][$this->extKey][$this->prefixId]['cleanPastedContent'] as $classRef) {
131 $hookObj = GeneralUtility::getUserObj($classRef);
132 if (method_exists($hookObj, 'cleanPastedContent_afterCleanWord')) {
133 $html = $hookObj->cleanPastedContent_afterCleanWord($html, $thisConfig);
134 }
135 }
136 }
137 return $html;
138 }
139
140 /**
141 * Modify incoming HTMLparser config in an attempt to keep span tags with id
142 * Such tags are used by the RTE in order to restore the cursor position when the cleaning operation is completed.
143 *
144 * @param array $HTMLparserConfig: incoming HTMLParser configuration (wil be modified)
145 * @return void
146 */
147 protected function keepSpanTagsWithId(&$HTMLparserConfig) {
148 // Allow span tag
149 if (isset($HTMLparserConfig['allowTags'])) {
150 if (!GeneralUtility::inList($HTMLparserConfig['allowTags'], 'span')) {
151 $HTMLparserConfig['allowTags'] .= ',span';
152 }
153 } else {
154 $HTMLparserConfig['allowTags'] = 'span';
155 }
156 // Allow attributes on span tags
157 if (isset($HTMLparserConfig['noAttrib']) && GeneralUtility::inList($HTMLparserConfig['noAttrib'], 'span')) {
158 $HTMLparserConfig['noAttrib'] = GeneralUtility::rmFromList('span', $HTMLparserConfig['noAttrib']);
159 }
160 // Do not remove span tags
161 if (isset($HTMLparserConfig['removeTags']) && GeneralUtility::inList($HTMLparserConfig['removeTags'], 'span')) {
162 $HTMLparserConfig['removeTags'] = GeneralUtility::rmFromList('span', $HTMLparserConfig['removeTags']);
163 }
164 // Review the tags array
165 if (is_array($HTMLparserConfig['tags.'])) {
166 // Allow span tag
167 if (isset($HTMLparserConfig['tags.']['span']) && !$HTMLparserConfig['tags.']['span']) {
168 $HTMLparserConfig['tags.']['span'] = 1;
169 }
170 if (is_array($HTMLparserConfig['tags.']['span.'])) {
171 if (isset($HTMLparserConfig['tags.']['span.']['allowedAttribs'])) {
172 if (!$HTMLparserConfig['tags.']['span.']['allowedAttribs']) {
173 $HTMLparserConfig['tags.']['span.']['allowedAttribs'] = 'id';
174 } elseif (!GeneralUtility::inList($HTMLparserConfig['tags.']['span.']['allowedAttribs'], 'id')) {
175 $HTMLparserConfig['tags.']['span.']['allowedAttribs'] .= ',id';
176 }
177 }
178 if (isset($HTMLparserConfig['tags.']['span.']['fixAttrib.']['id.']['unset'])) {
179 unset($HTMLparserConfig['tags.']['span.']['fixAttrib.']['id.']['unset']);
180 }
181 }
182 }
183 }
184
185 }