[!!!][TASK] Drop TYPO3_CONF_VARS['SYS]['form_enctype']
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / Wizard / RteController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\Wizard;
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\Backend\Form\DataPreprocessor;
18 use TYPO3\CMS\Backend\Form\FormEngine;
19 use TYPO3\CMS\Backend\Form\Utility\FormEngineUtility;
20 use TYPO3\CMS\Backend\Template\DocumentTemplate;
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
22 use TYPO3\CMS\Backend\Utility\IconUtility;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24
25 /**
26 * Script class for rendering the full screen RTE display
27 */
28 class RteController extends AbstractWizardController {
29
30 /**
31 * Document template object
32 *
33 * @var DocumentTemplate
34 */
35 public $doc;
36
37 /**
38 * Content accumulation for the module.
39 *
40 * @var string
41 */
42 public $content;
43
44 /**
45 * Wizard parameters, coming from FormEngine linking to the wizard.
46 *
47 * @var array
48 */
49 public $P;
50
51 /**
52 * If set, launch a new window with the current records pid.
53 *
54 * @var string
55 */
56 public $popView;
57
58 /**
59 * Set to the URL of this script including variables which is needed to re-display the form. See main()
60 *
61 * @var string
62 */
63 public $R_URI;
64
65 /**
66 * Module configuration
67 *
68 * @var array
69 */
70 public $MCONF = array();
71
72 /**
73 * Constructor
74 */
75 public function __construct() {
76 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_wizards.xlf');
77 $GLOBALS['SOBE'] = $this;
78
79 $this->init();
80 }
81
82 /**
83 * Initialization of the class
84 *
85 * @return void
86 */
87 protected function init() {
88 // Setting GPvars:
89 $this->P = GeneralUtility::_GP('P');
90 $this->popView = GeneralUtility::_GP('popView');
91 $this->R_URI = GeneralUtility::linkThisScript(array('popView' => ''));
92 // "Module name":
93 $this->MCONF['name'] = 'wizard_rte';
94 // Starting the document template object:
95 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
96 $this->doc->backPath = $this->getBackPath();
97 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/wizard_rte.html');
98 // Need to NOT have the page wrapped in DIV since if we do that we destroy
99 // the feature that the RTE spans the whole height of the page!!!
100 $this->doc->divClass = '';
101 $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_db')) . '" method="post" enctype="multipart/form-data" name="editform" onsubmit="return TBE_EDITOR.checkSubmit(1);">';
102 }
103
104 /**
105 * Main function, rendering the document with the iFrame with the RTE in.
106 *
107 * @return void
108 */
109 public function main() {
110 // Translate id to the workspace version:
111 if ($versionedRecord = BackendUtility::getWorkspaceVersionOfRecord($this->getBackendUserAuthentication()->workspace, $this->P['table'], $this->P['uid'], 'uid')) {
112 $this->P['uid'] = $versionedRecord['uid'];
113 }
114 // If all parameters are available:
115 if ($this->P['table'] && $this->P['field'] && $this->P['uid'] && $this->checkEditAccess($this->P['table'], $this->P['uid'])) {
116 // Getting the raw record (we need only the pid-value from here...)
117 $rawRecord = BackendUtility::getRecord($this->P['table'], $this->P['uid']);
118 BackendUtility::fixVersioningPid($this->P['table'], $rawRecord);
119
120 // override the default jumpToUrl
121 $this->doc->JScodeArray['jumpToUrl'] = '
122 function jumpToUrl(URL,formEl) {
123 if (document.editform) {
124 if (!TBE_EDITOR.isFormChanged()) {
125 window.location.href = URL;
126 } else if (formEl) {
127 if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
128 }
129 } else {
130 window.location.href = URL;
131 }
132 }
133 ';
134
135 // Setting JavaScript of the pid value for viewing:
136 if ($this->popView) {
137 $this->doc->JScode = $this->doc->wrapScriptTags(BackendUtility::viewOnClick($rawRecord['pid'], '', BackendUtility::BEgetRootLine($rawRecord['pid'])));
138 }
139 // Initialize FormEngine - for rendering the field:
140 /** @var FormEngine $formEngine */
141 $formEngine = GeneralUtility::makeInstance(FormEngine::class);
142 // SPECIAL: Disables all wizards - we are NOT going to need them.
143 $formEngine->disableWizards = 1;
144 // Fetching content of record:
145 /** @var DataPreprocessor $dataPreprocessor */
146 $dataPreprocessor = GeneralUtility::makeInstance(DataPreprocessor::class);
147 $dataPreprocessor->lockRecords = 1;
148 $dataPreprocessor->fetchRecord($this->P['table'], $this->P['uid'], '');
149 // Getting the processed record content out:
150 $processedRecord = reset($dataPreprocessor->regTableItems_data);
151 $processedRecord['uid'] = $this->P['uid'];
152 $processedRecord['pid'] = $rawRecord['pid'];
153 // TSconfig, setting width:
154 $fieldTSConfig = FormEngineUtility::getTSconfigForTableRow($this->P['table'], $processedRecord, $this->P['field']);
155 if ((string)$fieldTSConfig['RTEfullScreenWidth'] !== '') {
156 $width = $fieldTSConfig['RTEfullScreenWidth'];
157 } else {
158 $width = '100%';
159 }
160 // Get the form field and wrap it in the table with the buttons:
161 $formContent = $formEngine->getSoloField($this->P['table'], $processedRecord, $this->P['field']);
162 $formContent = '
163
164 <!-- RTE wizard: -->
165 <table border="0" cellpadding="0" cellspacing="0" width="' . $width . '" id="typo3-rtewizard">
166 <tr>
167 <td width="' . $width . '" colspan="2" id="c-formContent">' . $formContent . '</td>
168 <td></td>
169 </tr>
170 </table>';
171 // Adding hidden fields:
172 $formContent .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($this->R_URI) . '" />
173 <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />' . FormEngine::getHiddenTokenField('tceAction');
174 // Finally, add the whole setup:
175 $this->content .= $formEngine->printNeededJSFunctions_top() . $formContent . $formEngine->printNeededJSFunctions();
176 } else {
177 // ERROR:
178 $this->content .= $this->doc->section($this->getLanguageService()->getLL('forms_title'), '<span class="text-danger">' . $this->getLanguageService()->getLL('table_noData', TRUE) . '</span>', 0, 1);
179 }
180 // Setting up the buttons and markers for docHeader
181 $docHeaderButtons = $this->getButtons();
182 $markers['CONTENT'] = $this->content;
183 // Build the <body> for the module
184 $this->content = $this->doc->startPage('');
185 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markers);
186 $this->content .= $this->doc->endPage();
187 $this->content = $this->doc->insertStylesAndJS($this->content);
188 }
189
190 /**
191 * Outputting the accumulated content to screen
192 *
193 * @return void
194 */
195 public function printContent() {
196 $this->content .= $this->doc->endPage();
197 $this->content = $this->doc->insertStylesAndJS($this->content);
198 echo $this->content;
199 }
200
201 /**
202 * Create the panel of buttons for submitting the form or otherwise perform operations.
203 *
204 * @return array All available buttons as an assoc. array
205 */
206 protected function getButtons() {
207 $buttons = array(
208 'close' => '',
209 'save' => '',
210 'save_view' => '',
211 'save_close' => '',
212 'shortcut' => '',
213 'undo' => ''
214 );
215 if ($this->P['table'] && $this->P['field'] && $this->P['uid'] && $this->checkEditAccess($this->P['table'], $this->P['uid'])) {
216 $closeUrl = GeneralUtility::sanitizeLocalUrl($this->P['returnUrl']);
217 // Getting settings for the undo button:
218 $undoButton = 0;
219 $databaseConnection = $this->getDatabaseConnection();
220 $undoRes = $databaseConnection->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $databaseConnection->fullQuoteStr($this->P['table'], 'sys_history') . ' AND recuid=' . (int)$this->P['uid'], '', 'tstamp DESC', '1');
221 if ($undoButtonR = $databaseConnection->sql_fetch_assoc($undoRes)) {
222 $undoButton = 1;
223 }
224 // Close
225 $buttons['close'] = '<a href="#" onclick="' . htmlspecialchars('jumpToUrl(' . GeneralUtility::quoteJSvalue($closeUrl) . '); return false;') . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-close') . '</a>';
226 // Save
227 $buttons['save'] = IconUtility::getSpriteIcon('actions-document-save', array('html' => '<input type="image" name="_savedok" class="c-inputButton" src="clear.gif" onclick="TBE_EDITOR.checkAndDoSubmit(1); return false;" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" />'));
228 // Save & View
229 $buttons['save_view'] = IconUtility::getSpriteIcon('actions-document-save-view', array('html' => '<input type="image" class="c-inputButton" name="_savedokview" src="clear.gif" onclick="' . htmlspecialchars('document.editform.redirect.value+=\'&popView=1\'; TBE_EDITOR.checkAndDoSubmit(1); return false;') . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDocShow', TRUE) . '" />'));
230 // Save & Close
231 $buttons['save_close'] = IconUtility::getSpriteIcon('actions-document-save-close', array('html' => '<input type="image" class="c-inputButton" name="_saveandclosedok" src="clear.gif" onclick="' . htmlspecialchars('document.editform.redirect.value=' . GeneralUtility::quoteJSvalue($closeUrl) . '; TBE_EDITOR.checkAndDoSubmit(1); return false;') . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '" />'));
232 // Undo/Revert:
233 if ($undoButton) {
234 $aOnClick = 'window.location.href=' .
235 GeneralUtility::quoteJSvalue(
236 BackendUtility::getModuleUrl(
237 'record_history',
238 array(
239 'element' => $this->P['table'] . ':' . $this->P['uid'],
240 'revert' => 'field:' . $this->P['field'],
241 'sumUp' => -1,
242 'returnUrl' => $this->R_URI,
243 )
244 )
245 ) . '; return false;';
246 $buttons['undo'] = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '"' . ' title="' . htmlspecialchars(sprintf($this->getLanguageService()->getLL('undoLastChange'), BackendUtility::calcAge(($GLOBALS['EXEC_TIME'] - $undoButtonR['tstamp']), $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')))) . '">' . IconUtility::getSpriteIcon('actions-edit-undo') . '</a>';
247 }
248 // Shortcut
249 if ($this->getBackendUserAuthentication()->mayMakeShortcut()) {
250 $buttons['shortcut'] = $this->doc->makeShortcutIcon('P', '', $this->MCONF['name'], 1);
251 }
252 }
253 return $buttons;
254 }
255
256 }