[TASK] Fix dummy parameter and return texts in phpDoc
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / Controller / ParseHtmlController.php
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19 /**
20 * Content parsing for htmlArea RTE
21 *
22 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
23 */
24 class ParseHtmlController {
25
26 /**
27 * @var string
28 */
29 public $content;
30
31 /**
32 * @var array
33 */
34 public $modData;
35
36 /**
37 * document template object
38 *
39 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
40 */
41 public $doc;
42
43 /**
44 * @var string
45 */
46 public $extKey = 'rtehtmlarea';
47
48 /**
49 * @var string
50 */
51 public $prefixId = 'TYPO3HtmlParser';
52
53 /**
54 * @return void
55 */
56 public function init() {
57 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
58 $this->doc->backPath = $GLOBALS['BACK_PATH'];
59 $this->doc->JScode = '';
60 $this->modData = $GLOBALS['BE_USER']->getModuleData($GLOBALS['MCONF']['name'], 'ses');
61 if (GeneralUtility::_GP('OC_key')) {
62 $parts = explode('|', GeneralUtility::_GP('OC_key'));
63 $this->modData['openKeys'][$parts[1]] = $parts[0] == 'O' ? 1 : 0;
64 $GLOBALS['BE_USER']->pushModuleData($GLOBALS['MCONF']['name'], $this->modData);
65 }
66 }
67
68 /**
69 * Main function
70 *
71 * @return void
72 */
73 public function main() {
74 $this->content .= $this->main_parse_html($this->modData['openKeys']);
75 header('Content-Type: text/plain; charset=utf-8');
76 }
77
78 /**
79 * Print content
80 *
81 * @return void
82 */
83 public function printContent() {
84 echo $this->content;
85 }
86
87 /**
88 * Rich Text Editor (RTE) html parser
89 *
90 * @param array $openKeys Unused
91 * @return string
92 */
93 public function main_parse_html($openKeys) {
94 $editorNo = GeneralUtility::_GP('editorNo');
95 $html = GeneralUtility::_GP('content');
96 $RTEtsConfigParts = explode(':', GeneralUtility::_GP('RTEtsConfigParams'));
97 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
98 $thisConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
99 $HTMLParser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Html\HtmlParser::class);
100 if (is_array($thisConfig['enableWordClean.'])) {
101 $HTMLparserConfig = $thisConfig['enableWordClean.']['HTMLparser.'];
102 if (is_array($HTMLparserConfig)) {
103 $this->keepSpanTagsWithId($HTMLparserConfig);
104 $HTMLparserConfig = $HTMLParser->HTMLparserConfig($HTMLparserConfig);
105 }
106 }
107 if (is_array($HTMLparserConfig)) {
108 $html = $HTMLParser->HTMLcleaner($html, $HTMLparserConfig[0], $HTMLparserConfig[1], $HTMLparserConfig[2], $HTMLparserConfig[3]);
109 }
110 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey][$this->prefixId]['cleanPastedContent'])) {
111 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey][$this->prefixId]['cleanPastedContent'] as $classRef) {
112 $hookObj = GeneralUtility::getUserObj($classRef);
113 if (method_exists($hookObj, 'cleanPastedContent_afterCleanWord')) {
114 $html = $hookObj->cleanPastedContent_afterCleanWord($html, $thisConfig);
115 }
116 }
117 }
118 return $html;
119 }
120
121 /**
122 * Modify incoming HTMLparser config in an attempt to keep span tags with id
123 * Such tags are used by the RTE in order to restore the cursor position when the cleaning operation is completed.
124 *
125 * @param array $HTMLparserConfig: incoming HTMLParser configuration (wil be modified)
126 * @return void
127 */
128 protected function keepSpanTagsWithId(&$HTMLparserConfig) {
129 // Allow span tag
130 if (isset($HTMLparserConfig['allowTags'])) {
131 if (!GeneralUtility::inList($HTMLparserConfig['allowTags'], 'span')) {
132 $HTMLparserConfig['allowTags'] .= ',span';
133 }
134 } else {
135 $HTMLparserConfig['allowTags'] = 'span';
136 }
137 // Allow attributes on span tags
138 if (isset($HTMLparserConfig['noAttrib']) && GeneralUtility::inList($HTMLparserConfig['noAttrib'], 'span')) {
139 $HTMLparserConfig['noAttrib'] = GeneralUtility::rmFromList('span', $HTMLparserConfig['noAttrib']);
140 }
141 // Do not remove span tags
142 if (isset($HTMLparserConfig['removeTags']) && GeneralUtility::inList($HTMLparserConfig['removeTags'], 'span')) {
143 $HTMLparserConfig['removeTags'] = GeneralUtility::rmFromList('span', $HTMLparserConfig['removeTags']);
144 }
145 // Review the tags array
146 if (is_array($HTMLparserConfig['tags.'])) {
147 // Allow span tag
148 if (isset($HTMLparserConfig['tags.']['span']) && !$HTMLparserConfig['tags.']['span']) {
149 $HTMLparserConfig['tags.']['span'] = 1;
150 }
151 if (is_array($HTMLparserConfig['tags.']['span.'])) {
152 if (isset($HTMLparserConfig['tags.']['span.']['allowedAttribs'])) {
153 if (!$HTMLparserConfig['tags.']['span.']['allowedAttribs']) {
154 $HTMLparserConfig['tags.']['span.']['allowedAttribs'] = 'id';
155 } elseif (!GeneralUtility::inList($HTMLparserConfig['tags.']['span.']['allowedAttribs'], 'id')) {
156 $HTMLparserConfig['tags.']['span.']['allowedAttribs'] .= ',id';
157 }
158 }
159 if (isset($HTMLparserConfig['tags.']['span.']['fixAttrib.']['id.']['unset'])) {
160 unset($HTMLparserConfig['tags.']['span.']['fixAttrib.']['id.']['unset']);
161 }
162 }
163 }
164 }
165
166 }