TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ParseHtmlController.php
Go to the documentation of this file.
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 Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
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_parse_html($openKeys)
107  {
108  $html = GeneralUtility::_GP('content');
109  $RTEtsConfigParts = explode(':', GeneralUtility::_GP('RTEtsConfigParams'));
110  $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
111  $thisConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
112  $HTMLParser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Html\HtmlParser::class);
113  if (is_array($thisConfig['enableWordClean.'])) {
114  $HTMLparserConfig = $thisConfig['enableWordClean.']['HTMLparser.'];
115  if (is_array($HTMLparserConfig)) {
116  $this->keepSpanTagsWithId($HTMLparserConfig);
117  $HTMLparserConfig = $HTMLParser->HTMLparserConfig($HTMLparserConfig);
118  }
119  }
120  if (is_array($HTMLparserConfig)) {
121  $html = $HTMLParser->HTMLcleaner($html, $HTMLparserConfig[0], $HTMLparserConfig[1], $HTMLparserConfig[2], $HTMLparserConfig[3]);
122  }
123  if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey][$this->prefixId]['cleanPastedContent'])) {
124  foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey][$this->prefixId]['cleanPastedContent'] as $classRef) {
125  $hookObj = GeneralUtility::getUserObj($classRef);
126  if (method_exists($hookObj, 'cleanPastedContent_afterCleanWord')) {
127  $html = $hookObj->cleanPastedContent_afterCleanWord($html, $thisConfig);
128  }
129  }
130  }
131  return $html;
132  }
133 
141  protected function keepSpanTagsWithId(&$HTMLparserConfig)
142  {
143  // Allow span tag
144  if (isset($HTMLparserConfig['allowTags'])) {
145  if (!GeneralUtility::inList($HTMLparserConfig['allowTags'], 'span')) {
146  $HTMLparserConfig['allowTags'] .= ',span';
147  }
148  } else {
149  $HTMLparserConfig['allowTags'] = 'span';
150  }
151  // Allow attributes on span tags
152  if (isset($HTMLparserConfig['noAttrib']) && GeneralUtility::inList($HTMLparserConfig['noAttrib'], 'span')) {
153  $HTMLparserConfig['noAttrib'] = GeneralUtility::rmFromList('span', $HTMLparserConfig['noAttrib']);
154  }
155  // Do not remove span tags
156  if (isset($HTMLparserConfig['removeTags']) && GeneralUtility::inList($HTMLparserConfig['removeTags'], 'span')) {
157  $HTMLparserConfig['removeTags'] = GeneralUtility::rmFromList('span', $HTMLparserConfig['removeTags']);
158  }
159  // Review the tags array
160  if (is_array($HTMLparserConfig['tags.'])) {
161  // Allow span tag
162  if (isset($HTMLparserConfig['tags.']['span']) && !$HTMLparserConfig['tags.']['span']) {
163  $HTMLparserConfig['tags.']['span'] = 1;
164  }
165  if (is_array($HTMLparserConfig['tags.']['span.'])) {
166  if (isset($HTMLparserConfig['tags.']['span.']['allowedAttribs'])) {
167  if (!$HTMLparserConfig['tags.']['span.']['allowedAttribs']) {
168  $HTMLparserConfig['tags.']['span.']['allowedAttribs'] = 'id';
169  } elseif (!GeneralUtility::inList($HTMLparserConfig['tags.']['span.']['allowedAttribs'], 'id')) {
170  $HTMLparserConfig['tags.']['span.']['allowedAttribs'] .= ',id';
171  }
172  }
173  if (isset($HTMLparserConfig['tags.']['span.']['fixAttrib.']['id.']['unset'])) {
174  unset($HTMLparserConfig['tags.']['span.']['fixAttrib.']['id.']['unset']);
175  }
176  }
177  }
178  }
179 }
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static getPagesTSconfig($id, $rootLine=null, $returnPartArray=false)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static RTEsetup($RTEprop, $table, $field, $type= '')
static makeInstance($className,...$constructorArguments)