[TASK] Set a flash msg if no subpages available
[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-2011 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 textfile 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 * Content parsing for htmlArea RTE
31 *
32 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
33 */
34 class ContentParser {
35
36 /**
37 * @todo Define visibility
38 */
39 public $content;
40
41 /**
42 * @todo Define visibility
43 */
44 public $modData;
45
46 /**
47 * document template object
48 *
49 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
50 * @todo Define visibility
51 */
52 public $doc;
53
54 /**
55 * @todo Define visibility
56 */
57 public $extKey = 'rtehtmlarea';
58
59 /**
60 * @todo Define visibility
61 */
62 public $prefixId = 'TYPO3HtmlParser';
63
64 /**
65 * @return [type] ...
66 * @todo Define visibility
67 */
68 public function init() {
69 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
70 $this->doc->backPath = $GLOBALS['BACK_PATH'];
71 $this->doc->JScode = '';
72 $this->modData = $GLOBALS['BE_USER']->getModuleData($GLOBALS['MCONF']['name'], 'ses');
73 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('OC_key')) {
74 $parts = explode('|', \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('OC_key'));
75 $this->modData['openKeys'][$parts[1]] = $parts[0] == 'O' ? 1 : 0;
76 $GLOBALS['BE_USER']->pushModuleData($GLOBALS['MCONF']['name'], $this->modData);
77 }
78 }
79
80 /**
81 * [Describe function...]
82 *
83 * @return [type] ...
84 * @todo Define visibility
85 */
86 public function main() {
87 $this->content .= $this->main_parse_html($this->modData['openKeys']);
88 header('Content-Type: text/plain; charset=utf-8');
89 }
90
91 /**
92 * [Describe function...]
93 *
94 * @return [type] ...
95 * @todo Define visibility
96 */
97 public function printContent() {
98 echo $this->content;
99 }
100
101 /**
102 * Rich Text Editor (RTE) html parser
103 *
104 * @param [type] $openKeys: ...
105 * @return [type] ...
106 * @todo Define visibility
107 */
108 public function main_parse_html($openKeys) {
109 global $TYPO3_CONF_VARS;
110 $editorNo = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('editorNo');
111 $html = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('content');
112 $RTEtsConfigParts = explode(':', \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('RTEtsConfigParams'));
113 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
114 $thisConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
115 $HTMLParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Html\\HtmlParser');
116 if (is_array($thisConfig['enableWordClean.'])) {
117 $HTMLparserConfig = $thisConfig['enableWordClean.']['HTMLparser.'];
118 if (is_array($HTMLparserConfig)) {
119 $this->keepSpanTagsWithId($HTMLparserConfig);
120 $HTMLparserConfig = $HTMLParser->HTMLparserConfig($HTMLparserConfig);
121 }
122 }
123 if (is_array($HTMLparserConfig)) {
124 $html = $HTMLParser->HTMLcleaner($html, $HTMLparserConfig[0], $HTMLparserConfig[1], $HTMLparserConfig[2], $HTMLparserConfig[3]);
125 }
126 if (is_array($TYPO3_CONF_VARS['EXTCONF'][$this->extKey][$this->prefixId]['cleanPastedContent'])) {
127 foreach ($TYPO3_CONF_VARS['EXTCONF'][$this->extKey][$this->prefixId]['cleanPastedContent'] as $classRef) {
128 $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
129 if (method_exists($hookObj, 'cleanPastedContent_afterCleanWord')) {
130 $html = $hookObj->cleanPastedContent_afterCleanWord($html, $thisConfig);
131 }
132 }
133 }
134 return $html;
135 }
136
137 /**
138 * Modify incoming HTMLparser config in an attempt to keep span tags with id
139 * Such tags are used by the RTE in order to restore the cursor position when the cleaning operation is completed.
140 *
141 * @param array $HTMLparserConfig: incoming HTMLParser configuration (wil be modified)
142 * @return void
143 */
144 protected function keepSpanTagsWithId(&$HTMLparserConfig) {
145 // Allow span tag
146 if (isset($HTMLparserConfig['allowTags'])) {
147 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($HTMLparserConfig['allowTags'], 'span')) {
148 $HTMLparserConfig['allowTags'] .= ',span';
149 }
150 } else {
151 $HTMLparserConfig['allowTags'] = 'span';
152 }
153 // Allow attributes on span tags
154 if (isset($HTMLparserConfig['noAttrib']) && \TYPO3\CMS\Core\Utility\GeneralUtility::inList($HTMLparserConfig['noAttrib'], 'span')) {
155 $HTMLparserConfig['noAttrib'] = \TYPO3\CMS\Core\Utility\GeneralUtility::rmFromList('span', $HTMLparserConfig['noAttrib']);
156 }
157 // Do not remove span tags
158 if (isset($HTMLparserConfig['removeTags']) && \TYPO3\CMS\Core\Utility\GeneralUtility::inList($HTMLparserConfig['removeTags'], 'span')) {
159 $HTMLparserConfig['removeTags'] = \TYPO3\CMS\Core\Utility\GeneralUtility::rmFromList('span', $HTMLparserConfig['removeTags']);
160 }
161 // Review the tags array
162 if (is_array($HTMLparserConfig['tags.'])) {
163 // Allow span tag
164 if (isset($HTMLparserConfig['tags.']['span']) && !$HTMLparserConfig['tags.']['span']) {
165 $HTMLparserConfig['tags.']['span'] = 1;
166 }
167 if (is_array($HTMLparserConfig['tags.']['span.'])) {
168 if (isset($HTMLparserConfig['tags.']['span.']['allowedAttribs'])) {
169 if (!$HTMLparserConfig['tags.']['span.']['allowedAttribs']) {
170 $HTMLparserConfig['tags.']['span.']['allowedAttribs'] = 'id';
171 } elseif (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($HTMLparserConfig['tags.']['span.']['allowedAttribs'], 'id')) {
172 $HTMLparserConfig['tags.']['span.']['allowedAttribs'] .= ',id';
173 }
174 }
175 if (isset($HTMLparserConfig['tags.']['span.']['fixAttrib.']['id.']['unset'])) {
176 unset($HTMLparserConfig['tags.']['span.']['fixAttrib.']['id.']['unset']);
177 }
178 }
179 }
180 }
181
182 }
183
184
185 ?>