TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
SimpleDataHandlerController.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\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;
26 
36 {
42  public $flags;
43 
49  public $data;
50 
57  public $cmd;
58 
64  public $mirror;
65 
71  public $cacheCmd;
72 
78  public $redirect;
79 
85  public $prErr;
86 
92  public $CB;
93 
99  public $vC;
100 
106  public $uPT;
107 
113  public $tce;
114 
118  public function __construct()
119  {
120  $GLOBALS['SOBE'] = $this;
121  $this->init();
122  }
123 
129  public function init()
130  {
131  $beUser = $this->getBackendUser();
132  // GPvars:
133  $this->flags = GeneralUtility::_GP('flags');
134  $this->data = GeneralUtility::_GP('data');
135  $this->cmd = GeneralUtility::_GP('cmd');
136  $this->mirror = GeneralUtility::_GP('mirror');
137  $this->cacheCmd = GeneralUtility::_GP('cacheCmd');
138  $this->redirect = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('redirect'));
139  $this->prErr = GeneralUtility::_GP('prErr');
140  $this->CB = GeneralUtility::_GP('CB');
141  $this->vC = GeneralUtility::_GP('vC');
142  $this->uPT = GeneralUtility::_GP('uPT');
143  // Creating DataHandler object
144  $this->tce = GeneralUtility::makeInstance(DataHandler::class);
145  // Configuring based on user prefs.
146  if ($beUser->uc['recursiveDelete']) {
147  // TRUE if the delete Recursive flag is set.
148  $this->tce->deleteTree = 1;
149  }
150  if ($beUser->uc['copyLevels']) {
151  // Set to number of page-levels to copy.
152  $this->tce->copyTree = MathUtility::forceIntegerInRange($beUser->uc['copyLevels'], 0, 100);
153  }
154  if ($beUser->uc['neverHideAtCopy']) {
155  $this->tce->neverHideAtCopy = 1;
156  }
157  $TCAdefaultOverride = $beUser->getTSConfigProp('TCAdefaults');
158  if (is_array($TCAdefaultOverride)) {
159  $this->tce->setDefaultsFromUserTS($TCAdefaultOverride);
160  }
161  // Reverse order.
162  if ($this->flags['reverseOrder']) {
163  $this->tce->reverseOrder = 1;
164  }
165  }
166 
172  public function initClipboard()
173  {
174  if (is_array($this->CB)) {
175  $clipObj = GeneralUtility::makeInstance(Clipboard::class);
176  $clipObj->initializeClipboard();
177  if ($this->CB['paste']) {
178  $clipObj->setCurrentPad($this->CB['pad']);
179  $this->cmd = $clipObj->makePasteCmdArray(
180  $this->CB['paste'],
181  $this->cmd,
182  isset($this->CB['update']) ? $this->CB['update'] : null
183  );
184  }
185  if ($this->CB['delete']) {
186  $clipObj->setCurrentPad($this->CB['pad']);
187  $this->cmd = $clipObj->makeDeleteCmdArray($this->cmd);
188  }
189  }
190  }
191 
197  public function main()
198  {
199  // LOAD DataHandler with data and cmd arrays:
200  $this->tce->start($this->data, $this->cmd);
201  if (is_array($this->mirror)) {
202  $this->tce->setMirror($this->mirror);
203  }
204  // Checking referer / executing
205  $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER'));
206  $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
207  if ($httpHost != $refInfo['host'] && $this->vC != $this->getBackendUser()->veriCode() && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) {
208  $this->tce->log('', 0, 0, 0, 1, 'Referer host "%s" and server host "%s" did not match and veriCode was not valid either!', 1, [$refInfo['host'], $httpHost]);
209  } else {
210  // Register uploaded files
211  $this->tce->process_uploads($_FILES);
212  // Execute actions:
213  $this->tce->process_datamap();
214  $this->tce->process_cmdmap();
215  // Clearing cache:
216  if (!empty($this->cacheCmd)) {
217  $this->tce->clear_cacheCmd($this->cacheCmd);
218  }
219  // Update page tree?
220  if ($this->uPT && (isset($this->data['pages']) || isset($this->cmd['pages']))) {
221  BackendUtility::setUpdateSignal('updatePageTree');
222  }
223  }
224  }
225 
234  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
235  {
236  $this->initClipboard();
237  $this->main();
238 
239  // Write errors to flash message queue
240  if ($this->prErr) {
241  $this->tce->printLogErrorMessages($this->redirect);
242  }
243  if ($this->redirect) {
244  $response = $response
245  ->withHeader('Location', GeneralUtility::locationHeaderUrl($this->redirect))
246  ->withStatus(303);
247  }
248  return $response;
249  }
250 
258  public function processAjaxRequest(ServerRequestInterface $request, ResponseInterface $response)
259  {
260  // do the regular / main logic
261  $this->initClipboard();
262  $this->main();
263 
265  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
266 
267  $content = [
268  'redirect' => $this->redirect,
269  'messages' => [],
270  'hasErrors' => false
271  ];
272 
273  // Prints errors (= write them to the message queue)
274  if ($this->prErr) {
275  $content['hasErrors'] = true;
276  $this->tce->printLogErrorMessages($this->redirect);
277  }
278 
279  $messages = $flashMessageService->getMessageQueueByIdentifier()->getAllMessagesAndFlush();
280  if (!empty($messages)) {
281  foreach ($messages as $message) {
282  $content['messages'][] = [
283  'title' => $message->getTitle(),
284  'message' => $message->getMessage(),
285  'severity' => $message->getSeverity()
286  ];
287  if ($message->getSeverity() === AbstractMessage::ERROR) {
288  $content['hasErrors'] = true;
289  }
290  }
291  }
292 
293  $response->getBody()->write(json_encode($content));
294  return $response;
295  }
296 
302  protected function getBackendUser()
303  {
304  return $GLOBALS['BE_USER'];
305  }
306 }
mainAction(ServerRequestInterface $request, ResponseInterface $response)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31