TYPO3 CMS  TYPO3_7-6
ParseHtmlController.php
Go to the documentation of this file.
1 <?php
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 
20 
25 {
29  public $content;
30 
34  public $modData;
35 
41  public $doc;
42 
46  public $extKey = 'rtehtmlarea';
47 
51  public $prefixId = 'TYPO3HtmlParser';
52 
58  protected $moduleName = 'rtehtmlarea_wizard_parse_html';
59 
63  public function __construct()
64  {
65  $this->init();
66  }
67 
71  public function init()
72  {
73  $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
74  $this->doc->JScode = '';
75  $this->modData = $GLOBALS['BE_USER']->getModuleData($this->moduleName, '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($this->moduleName, $this->modData);
80  }
81  }
82 
91  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
92  {
93  $this->content .= $this->main_parse_html($this->modData['openKeys']);
94 
95  $response->getBody()->write($this->content);
96  $response = $response->withHeader('Content-Type', 'text/plain; charset=utf-8');
97  return $response;
98  }
99 
106  public function main()
107  {
109  $this->content .= $this->main_parse_html($this->modData['openKeys']);
110  header('Content-Type: text/plain; charset=utf-8');
111  }
112 
119  public function printContent()
120  {
122  echo $this->content;
123  }
124 
131  public function main_parse_html($openKeys)
132  {
133  $editorNo = GeneralUtility::_GP('editorNo');
134  $html = GeneralUtility::_GP('content');
135  $RTEtsConfigParts = explode(':', GeneralUtility::_GP('RTEtsConfigParams'));
136  $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
137  $thisConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
138  $HTMLParser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Html\HtmlParser::class);
139  if (is_array($thisConfig['enableWordClean.'])) {
140  $HTMLparserConfig = $thisConfig['enableWordClean.']['HTMLparser.'];
141  if (is_array($HTMLparserConfig)) {
142  $this->keepSpanTagsWithId($HTMLparserConfig);
143  $HTMLparserConfig = $HTMLParser->HTMLparserConfig($HTMLparserConfig);
144  }
145  }
146  if (is_array($HTMLparserConfig)) {
147  $html = $HTMLParser->HTMLcleaner($html, $HTMLparserConfig[0], $HTMLparserConfig[1], $HTMLparserConfig[2], $HTMLparserConfig[3]);
148  }
149  if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey][$this->prefixId]['cleanPastedContent'])) {
150  foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey][$this->prefixId]['cleanPastedContent'] as $classRef) {
151  $hookObj = GeneralUtility::getUserObj($classRef);
152  if (method_exists($hookObj, 'cleanPastedContent_afterCleanWord')) {
153  $html = $hookObj->cleanPastedContent_afterCleanWord($html, $thisConfig);
154  }
155  }
156  }
157  return $html;
158  }
159 
167  protected function keepSpanTagsWithId(&$HTMLparserConfig)
168  {
169  // Allow span tag
170  if (isset($HTMLparserConfig['allowTags'])) {
171  if (!GeneralUtility::inList($HTMLparserConfig['allowTags'], 'span')) {
172  $HTMLparserConfig['allowTags'] .= ',span';
173  }
174  } else {
175  $HTMLparserConfig['allowTags'] = 'span';
176  }
177  // Allow attributes on span tags
178  if (isset($HTMLparserConfig['noAttrib']) && GeneralUtility::inList($HTMLparserConfig['noAttrib'], 'span')) {
179  $HTMLparserConfig['noAttrib'] = GeneralUtility::rmFromList('span', $HTMLparserConfig['noAttrib']);
180  }
181  // Do not remove span tags
182  if (isset($HTMLparserConfig['removeTags']) && GeneralUtility::inList($HTMLparserConfig['removeTags'], 'span')) {
183  $HTMLparserConfig['removeTags'] = GeneralUtility::rmFromList('span', $HTMLparserConfig['removeTags']);
184  }
185  // Review the tags array
186  if (is_array($HTMLparserConfig['tags.'])) {
187  // Allow span tag
188  if (isset($HTMLparserConfig['tags.']['span']) && !$HTMLparserConfig['tags.']['span']) {
189  $HTMLparserConfig['tags.']['span'] = 1;
190  }
191  if (is_array($HTMLparserConfig['tags.']['span.'])) {
192  if (isset($HTMLparserConfig['tags.']['span.']['allowedAttribs'])) {
193  if (!$HTMLparserConfig['tags.']['span.']['allowedAttribs']) {
194  $HTMLparserConfig['tags.']['span.']['allowedAttribs'] = 'id';
195  } elseif (!GeneralUtility::inList($HTMLparserConfig['tags.']['span.']['allowedAttribs'], 'id')) {
196  $HTMLparserConfig['tags.']['span.']['allowedAttribs'] .= ',id';
197  }
198  }
199  if (isset($HTMLparserConfig['tags.']['span.']['fixAttrib.']['id.']['unset'])) {
200  unset($HTMLparserConfig['tags.']['span.']['fixAttrib.']['id.']['unset']);
201  }
202  }
203  }
204  }
205 }
static getPagesTSconfig($id, $rootLine=null, $returnPartArray=false)
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static RTEsetup($RTEprop, $table, $field, $type='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']