TYPO3 CMS  TYPO3_7-6
SimpleDataHandlerController.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 
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  // Register uploaded files
207  $this->tce->process_uploads($_FILES);
208  // Execute actions:
209  $this->tce->process_datamap();
210  $this->tce->process_cmdmap();
211  // Clearing cache:
212  if (!empty($this->cacheCmd)) {
213  $this->tce->clear_cacheCmd($this->cacheCmd);
214  }
215  // Update page tree?
216  if ($this->uPT && (isset($this->data['pages']) || isset($this->cmd['pages']))) {
217  BackendUtility::setUpdateSignal('updatePageTree');
218  }
219  }
220 
228  public function finish()
229  {
231  // Prints errors, if...
232  if ($this->prErr) {
233  $this->tce->printLogErrorMessages($this->redirect);
234  }
235  if ($this->redirect) {
236  HttpUtility::redirect($this->redirect);
237  }
238  }
239 
248  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
249  {
250  $this->initClipboard();
251  $this->main();
252 
253  // Write errors to flash message queue
254  if ($this->prErr) {
255  $this->tce->printLogErrorMessages($this->redirect);
256  }
257  if ($this->redirect) {
258  $response = $response
259  ->withHeader('Location', GeneralUtility::locationHeaderUrl($this->redirect))
260  ->withStatus(303);
261  }
262  return $response;
263  }
264 
272  public function processAjaxRequest(ServerRequestInterface $request, ResponseInterface $response)
273  {
274  // do the regular / main logic
275  $this->initClipboard();
276  $this->main();
277 
279  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
280 
281  $content = [
282  'redirect' => $this->redirect,
283  'messages' => [],
284  'hasErrors' => false
285  ];
286 
287  // Prints errors (= write them to the message queue)
288  if ($this->prErr) {
289  $content['hasErrors'] = true;
290  $this->tce->printLogErrorMessages($this->redirect);
291  }
292 
293  $messages = $flashMessageService->getMessageQueueByIdentifier()->getAllMessagesAndFlush();
294  if (!empty($messages)) {
295  foreach ($messages as $message) {
296  $content['messages'][] = [
297  'title' => $message->getTitle(),
298  'message' => $message->getMessage(),
299  'severity' => $message->getSeverity()
300  ];
301  if ($message->getSeverity() === AbstractMessage::ERROR) {
302  $content['hasErrors'] = true;
303  }
304  }
305  }
306 
307  $response->getBody()->write(json_encode($content));
308  return $response;
309  }
310 
316  protected function getBackendUser()
317  {
318  return $GLOBALS['BE_USER'];
319  }
320 }
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static setUpdateSignal($set='', $params='')
static redirect($url, $httpStatus=self::HTTP_STATUS_303)
Definition: HttpUtility.php:76
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']