TYPO3 CMS  TYPO3_7-6
RteController.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 
29 
34 {
40  public $content;
41 
47  public $P;
48 
54  public $popView;
55 
61  public $R_URI;
62 
68  public $MCONF = [];
69 
73  public function __construct()
74  {
75  parent::__construct();
76  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
77  $this->getLanguageService()->includeLLFile('EXT:lang/locallang_wizards.xlf');
78  $GLOBALS['SOBE'] = $this;
79 
80  $this->init();
81  }
82 
88  protected function init()
89  {
90  // Setting GPvars:
91  $this->P = GeneralUtility::_GP('P');
92  $this->popView = GeneralUtility::_GP('popView');
93  $this->R_URI = GeneralUtility::linkThisScript(['popView' => '']);
94  // "Module name":
95  $this->MCONF['name'] = 'wizard_rte';
96  // Need to NOT have the page wrapped in DIV since if we do that we destroy
97  // the feature that the RTE spans the whole height of the page!!!
98  }
99 
108  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
109  {
110  $this->main();
111 
112  $response->getBody()->write($this->moduleTemplate->renderContent());
113  return $response;
114  }
115 
121  public function main()
122  {
123  $this->content .= '<form action="'
124  . htmlspecialchars(BackendUtility::getModuleUrl('tce_db'))
125  . '" method="post" enctype="multipart/form-data" id="RteController" name="editform" '
126  . ' onsubmit="return TBE_EDITOR.checkSubmit(1);">';
127  // Translate id to the workspace version:
128  if ($versionedRecord = BackendUtility::getWorkspaceVersionOfRecord(
129  $this->getBackendUserAuthentication()->workspace,
130  $this->P['table'],
131  $this->P['uid'],
132  'uid'
133  )) {
134  $this->P['uid'] = $versionedRecord['uid'];
135  }
136  // If all parameters are available:
137  if ($this->P['table']
138  && $this->P['field']
139  && $this->P['uid']
140  && $this->checkEditAccess($this->P['table'], $this->P['uid'])) {
142  $formDataGroup = GeneralUtility::makeInstance(TcaDatabaseRecord::class);
144  $formDataCompiler = GeneralUtility::makeInstance(FormDataCompiler::class, $formDataGroup);
146  $nodeFactory = GeneralUtility::makeInstance(NodeFactory::class);
147 
148  $formDataCompilerInput = [
149  'vanillaUid' => (int)$this->P['uid'],
150  'tableName' => $this->P['table'],
151  'command' => 'edit',
152  'disabledWizards' => true,
153  ];
154 
155  $formData = $formDataCompiler->compile($formDataCompilerInput);
156 
157  $formData['fieldListToRender'] = $this->P['field'];
158  $formData['renderType'] = 'outerWrapContainer';
159  $formResult = $nodeFactory->create($formData)->render();
160 
162  $formResultCompiler = GeneralUtility::makeInstance(FormResultCompiler::class);
163  $formResultCompiler->mergeResult($formResult);
164 
165  // override the default jumpToUrl
166  $this->moduleTemplate->addJavaScriptCode(
167  'RteWizardInlineCode',
168  'function jumpToUrl(URL,formEl) {
169  if (document.editform) {
170  if (!TBE_EDITOR.isFormChanged()) {
171  window.location.href = URL;
172  } else if (formEl) {
173  if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
174  }
175  } else {
176  window.location.href = URL;
177  }
178  }
179  '
180  );
181 
182  // Setting JavaScript of the pid value for viewing:
183  if ($this->popView) {
184  $this->moduleTemplate->addJavaScriptCode(
185  'PopupViewInlineJS',
187  $formData['databaseRow']['pid'],
188  '',
189  BackendUtility::BEgetRootLine($formData['databaseRow']['pid'])
190  )
191  );
192  }
193 
194  $pageTsConfigMerged = $formData['pageTsConfigMerged'];
195  if ((string)$pageTsConfigMerged['TCEFORM.'][$this->P['table'] . '.'][$this->P['field'] . '.']['RTEfullScreenWidth'] !== '') {
196  $width = (string)$pageTsConfigMerged['TCEFORM.'][$this->P['table'] . '.'][$this->P['field'] . '.']['RTEfullScreenWidth'];
197  } else {
198  $width = '100%';
199  }
200  // Get the form field and wrap it in the table with the buttons:
201  $formContent = $formResult['html'];
202  $formContent = '
203  <table border="0" cellpadding="0" cellspacing="0" width="' . $width . '" id="typo3-rtewizard">
204  <tr>
205  <td width="' . $width . '" colspan="2" id="c-formContent">' . $formContent . '</td>
206  <td></td>
207  </tr>
208  </table>';
209 
210  // Adding hidden fields:
211  $formContent .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($this->R_URI) . '" />
212  <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />';
213  // Finally, add the whole setup:
214  $this->content .= $formResultCompiler->JStop()
215  . $formContent
216  . $formResultCompiler->printNeededJSFunctions();
217  } else {
218  // ERROR:
219  $this->content .= '<h2>' . $this->getLanguageService()->getLL('forms_title', true) . '</h2>'
220  . '<div><span class="text-danger">'
221  . $this->getLanguageService()->getLL('table_noData', true)
222  . '</span></div>';
223  }
224  // Setting up the buttons and markers for docHeader
225  $this->getButtons();
226  // Build the <body> for the module
227 
228  $this->content .= '</form>';
229  $this->moduleTemplate->setContent($this->content);
230  }
231 
238  public function printContent()
239  {
241  echo $this->content;
242  }
243 
249  protected function getButtons()
250  {
251  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
252  if ($this->P['table']
253  && $this->P['field']
254  && $this->P['uid']
255  && $this->checkEditAccess($this->P['table'], $this->P['uid'])) {
256  $closeUrl = GeneralUtility::sanitizeLocalUrl($this->P['returnUrl']);
257  // Getting settings for the undo button:
258  $undoButton = 0;
259  $databaseConnection = $this->getDatabaseConnection();
260  $undoRes = $databaseConnection->exec_SELECTquery(
261  'tstamp',
262  'sys_history',
263  'tablename=' . $databaseConnection->fullQuoteStr(
264  $this->P['table'],
265  'sys_history'
266  ) . ' AND recuid=' . (int)$this->P['uid'],
267  '',
268  'tstamp DESC',
269  '1'
270  );
271  if ($undoButtonR = $databaseConnection->sql_fetch_assoc($undoRes)) {
272  $undoButton = 1;
273  }
274 
275  // Close
276  $closeButton = $buttonBar->makeLinkButton()
277  ->setHref($closeUrl)
278  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc'))
279  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-close', Icon::SIZE_SMALL));
280  $buttonBar->addButton($closeButton, ButtonBar::BUTTON_POSITION_LEFT, 10);
281 
282  // Save
283  $saveButton = $buttonBar->makeInputButton()
284  ->setName('_savedok_x')
285  ->setValue('1')
286  ->setForm('RteController')
287  ->setOnClick('TBE_EDITOR.checkAndDoSubmit(1); return false;')
288  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc'))
289  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-save', Icon::SIZE_SMALL));
290  // Save & View
291  $saveAndViewButton = $buttonBar->makeInputButton()
292  ->setName('_savedokview_x')
293  ->setValue('1')
294  ->setForm('RteController')
295  ->setOnClick('document.editform.redirect.value+= ' . GeneralUtility::quoteJSvalue('&popView=1') . '; '
296  . ' TBE_EDITOR.checkAndDoSubmit(1); return false;')
297  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDocShow'))
298  ->setIcon(
299  $this->moduleTemplate->getIconFactory()->getIcon('actions-document-save-view', Icon::SIZE_SMALL)
300  );
301 
302  // Save & Close
303  $saveAndCloseButton = $buttonBar->makeInputButton()
304  ->setName('_saveandclosedok_x')
305  ->setValue('1')
306  ->setForm('RteController')
307  ->setOnClick('document.editform.redirect.value=' . GeneralUtility::quoteJSvalue($closeUrl)
308  . '; TBE_EDITOR.checkAndDoSubmit(1); return false;')
309  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc'))
310  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
311  'actions-document-save-close',
313  ));
314 
315  // Save SplitButton
316  $saveSplitButton = $buttonBar->makeSplitButton()
317  ->addItem($saveButton)
318  ->addItem($saveAndViewButton)
319  ->addItem($saveAndCloseButton);
320  $buttonBar->addButton($saveSplitButton, ButtonBar::BUTTON_POSITION_LEFT, 20);
321 
322  // Undo/Revert:
323  if ($undoButton) {
324  $aOnClick = 'window.location.href=' .
326  BackendUtility::getModuleUrl(
327  'record_history',
328  [
329  'element' => $this->P['table'] . ':' . $this->P['uid'],
330  'revert' => 'field:' . $this->P['field'],
331  'sumUp' => -1,
332  'returnUrl' => $this->R_URI,
333  ]
334  )
335  ) . '; return false;';
336 
337  $undoText = $this->getLanguageService()->sL(
338  'LLL:EXT:lang/locallang_wizards.xlf:rte_undoLastChange'
339  );
340  $lastChangeLabel = sprintf(
341  $undoText,
343  ($GLOBALS['EXEC_TIME'] - $undoButtonR['tstamp']),
344  $this->getLanguageService()->sL(
345  'LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears'
346  )
347  )
348  );
349 
350  $undoRevertButton = $buttonBar->makeLinkButton()
351  ->setHref('#')
352  ->setOnClick($aOnClick)
353  ->setTitle($lastChangeLabel)
354  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-edit-undo', Icon::SIZE_SMALL));
355  $buttonBar->addButton($undoRevertButton, ButtonBar::BUTTON_POSITION_LEFT, 30);
356  }
357  // Shortcut
358  $shortButton = $buttonBar->makeShortcutButton()
359  ->setModuleName($this->MCONF['name'])
360  ->setGetVariables(['P']);
361  $buttonBar->addButton($shortButton);
362  }
363  }
364 }
static getWorkspaceVersionOfRecord($workspace, $table, $uid, $fields=' *')
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static BEgetRootLine($uid, $clause='', $workspaceOL=false)
static linkThisScript(array $getParams=[])
static calcAge($seconds, $labels=' min|hrs|days|yrs|min|hour|day|year')
static viewOnClick($pageUid, $backPath='', $rootLine=null, $anchorSection='', $alternativeUrl='', $additionalGetVars='', $switchFocus=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']