TYPO3  7.6
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 
27 
37 {
43  public $flags;
44 
50  public $data;
51 
58  public $cmd;
59 
65  public $mirror;
66 
72  public $cacheCmd;
73 
79  public $redirect;
80 
86  public $prErr;
87 
93  public $CB;
94 
100  public $vC;
101 
107  public $uPT;
108 
114  public $tce;
115 
119  public function __construct()
120  {
121  $GLOBALS['SOBE'] = $this;
122  $this->init();
123  }
124 
130  public function init()
131  {
132  $beUser = $this->getBackendUser();
133  // GPvars:
134  $this->flags = GeneralUtility::_GP('flags');
135  $this->data = GeneralUtility::_GP('data');
136  $this->cmd = GeneralUtility::_GP('cmd');
137  $this->mirror = GeneralUtility::_GP('mirror');
138  $this->cacheCmd = GeneralUtility::_GP('cacheCmd');
139  $this->redirect = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('redirect'));
140  $this->prErr = GeneralUtility::_GP('prErr');
141  $this->CB = GeneralUtility::_GP('CB');
142  $this->vC = GeneralUtility::_GP('vC');
143  $this->uPT = GeneralUtility::_GP('uPT');
144  // Creating TCEmain object
145  $this->tce = GeneralUtility::makeInstance(DataHandler::class);
146  $this->tce->stripslashes_values = 0;
147  // Configuring based on user prefs.
148  if ($beUser->uc['recursiveDelete']) {
149  // TRUE if the delete Recursive flag is set.
150  $this->tce->deleteTree = 1;
151  }
152  if ($beUser->uc['copyLevels']) {
153  // Set to number of page-levels to copy.
154  $this->tce->copyTree = MathUtility::forceIntegerInRange($beUser->uc['copyLevels'], 0, 100);
155  }
156  if ($beUser->uc['neverHideAtCopy']) {
157  $this->tce->neverHideAtCopy = 1;
158  }
159  $TCAdefaultOverride = $beUser->getTSConfigProp('TCAdefaults');
160  if (is_array($TCAdefaultOverride)) {
161  $this->tce->setDefaultsFromUserTS($TCAdefaultOverride);
162  }
163  // Reverse order.
164  if ($this->flags['reverseOrder']) {
165  $this->tce->reverseOrder = 1;
166  }
167  }
168 
174  public function initClipboard()
175  {
176  if (is_array($this->CB)) {
177  $clipObj = GeneralUtility::makeInstance(Clipboard::class);
178  $clipObj->initializeClipboard();
179  if ($this->CB['paste']) {
180  $clipObj->setCurrentPad($this->CB['pad']);
181  $this->cmd = $clipObj->makePasteCmdArray(
182  $this->CB['paste'],
183  $this->cmd,
184  isset($this->CB['update']) ? $this->CB['update'] : null
185  );
186  }
187  if ($this->CB['delete']) {
188  $clipObj->setCurrentPad($this->CB['pad']);
189  $this->cmd = $clipObj->makeDeleteCmdArray($this->cmd);
190  }
191  }
192  }
193 
199  public function main()
200  {
201  // LOAD TCEmain with data and cmd arrays:
202  $this->tce->start($this->data, $this->cmd);
203  if (is_array($this->mirror)) {
204  $this->tce->setMirror($this->mirror);
205  }
206  // Checking referer / executing
207  $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER'));
208  $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
209  if ($httpHost != $refInfo['host'] && $this->vC != $this->getBackendUser()->veriCode() && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) {
210  $this->tce->log('', 0, 0, 0, 1, 'Referer host "%s" and server host "%s" did not match and veriCode was not valid either!', 1, array($refInfo['host'], $httpHost));
211  } else {
212  // Register uploaded files
213  $this->tce->process_uploads($_FILES);
214  // Execute actions:
215  $this->tce->process_datamap();
216  $this->tce->process_cmdmap();
217  // Clearing cache:
218  if (!empty($this->cacheCmd)) {
219  $this->tce->clear_cacheCmd($this->cacheCmd);
220  }
221  // Update page tree?
222  if ($this->uPT && (isset($this->data['pages']) || isset($this->cmd['pages']))) {
223  BackendUtility::setUpdateSignal('updatePageTree');
224  }
225  }
226  }
227 
235  public function finish()
236  {
238  // Prints errors, if...
239  if ($this->prErr) {
240  $this->tce->printLogErrorMessages($this->redirect);
241  }
242  if ($this->redirect) {
243  HttpUtility::redirect($this->redirect);
244  }
245  }
246 
256  {
257  $this->initClipboard();
258  $this->main();
259 
260  // Write errors to flash message queue
261  if ($this->prErr) {
262  $this->tce->printLogErrorMessages($this->redirect);
263  }
264  if ($this->redirect) {
265  $response = $response
266  ->withHeader('Location', GeneralUtility::locationHeaderUrl($this->redirect))
267  ->withStatus(303);
268  }
269  return $response;
270  }
271 
279  public function processAjaxRequest(ServerRequestInterface $request, ResponseInterface $response)
280  {
281  // do the regular / main logic
282  $this->initClipboard();
283  $this->main();
284 
286  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
287 
288  $content = array(
289  'redirect' => $this->redirect,
290  'messages' => array(),
291  'hasErrors' => false
292  );
293 
294  // Prints errors (= write them to the message queue)
295  if ($this->prErr) {
296  $content['hasErrors'] = true;
297  $this->tce->printLogErrorMessages($this->redirect);
298  }
299 
300  $messages = $flashMessageService->getMessageQueueByIdentifier()->getAllMessagesAndFlush();
301  if (!empty($messages)) {
302  foreach ($messages as $message) {
303  $content['messages'][] = array(
304  'title' => $message->getTitle(),
305  'message' => $message->getMessage(),
306  'severity' => $message->getSeverity()
307  );
308  if ($message->getSeverity() === AbstractMessage::ERROR) {
309  $content['hasErrors'] = true;
310  }
311  }
312  }
313 
314  $response->getBody()->write(json_encode($content));
315  return $response;
316  }
317 
323  protected function getBackendUser()
324  {
325  return $GLOBALS['BE_USER'];
326  }
327 }