[BUGFIX] Empty clear cache command logged
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / SimpleDataHandlerController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Script Class, creating object of \TYPO3\CMS\Core\DataHandling\DataHandler and
32 * sending the posted data to the object.
33 *
34 * Used by many smaller forms/links in TYPO3, including the QuickEdit module.
35 * Is not used by alt_doc.php though (main form rendering script) - that uses the same class (TCEmain) but makes its own initialization (to save the redirect request).
36 * For all other cases than alt_doc.php it is recommended to use this script for submitting your editing forms - but the best solution in any case would probably be to link your application to alt_doc.php, that will give you easy form-rendering as well.
37 *
38 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
39 */
40 class SimpleDataHandlerController {
41
42 // Internal, static: GPvar
43 // Array. Accepts options to be set in TCE object. Currently it supports "reverseOrder" (boolean).
44 /**
45 * @todo Define visibility
46 */
47 public $flags;
48
49 // Data array on the form [tablename][uid][fieldname] = value
50 /**
51 * @todo Define visibility
52 */
53 public $data;
54
55 // Command array on the form [tablename][uid][command] = value. This array may get additional data set internally based on clipboard commands send in CB var!
56 /**
57 * @todo Define visibility
58 */
59 public $cmd;
60
61 // Array passed to ->setMirror.
62 /**
63 * @todo Define visibility
64 */
65 public $mirror;
66
67 // Cache command sent to ->clear_cacheCmd
68 /**
69 * @todo Define visibility
70 */
71 public $cacheCmd;
72
73 // Redirect URL. Script will redirect to this location after performing operations (unless errors has occured)
74 /**
75 * @todo Define visibility
76 */
77 public $redirect;
78
79 // Boolean. If set, errors will be printed on screen instead of redirection. Should always be used, otherwise you will see no errors if they happen.
80 /**
81 * @todo Define visibility
82 */
83 public $prErr;
84
85 // Clipboard command array. May trigger changes in "cmd"
86 /**
87 * @todo Define visibility
88 */
89 public $CB;
90
91 // Verification code
92 /**
93 * @todo Define visibility
94 */
95 public $vC;
96
97 // Boolean. Update Page Tree Trigger. If set and the manipulated records are pages then the update page tree signal will be set.
98 /**
99 * @todo Define visibility
100 */
101 public $uPT;
102
103 // String, general comment (for raising stages of workspace versions)
104 /**
105 * @todo Define visibility
106 */
107 public $generalComment;
108
109 // Internal, dynamic:
110 // Files to include after init() function is called:
111 /**
112 * @todo Define visibility
113 */
114 public $include_once = array();
115
116 /**
117 * TYPO3 Core Engine
118 *
119 * @var \TYPO3\CMS\Core\DataHandling\DataHandler
120 * @todo Define visibility
121 */
122 public $tce;
123
124 /**
125 * Initialization of the class
126 *
127 * @return void
128 * @todo Define visibility
129 */
130 public function init() {
131 // GPvars:
132 $this->flags = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('flags');
133 $this->data = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('data');
134 $this->cmd = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cmd');
135 $this->mirror = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('mirror');
136 $this->cacheCmd = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cacheCmd');
137 $this->redirect = \TYPO3\CMS\Core\Utility\GeneralUtility::sanitizeLocalUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('redirect'));
138 $this->prErr = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('prErr');
139 $this->_disableRTE = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('_disableRTE');
140 $this->CB = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('CB');
141 $this->vC = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('vC');
142 $this->uPT = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('uPT');
143 $this->generalComment = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('generalComment');
144 // Creating TCEmain object
145 $this->tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
146 $this->tce->stripslashes_values = 0;
147 $this->tce->generalComment = $this->generalComment;
148 // Configuring based on user prefs.
149 if ($GLOBALS['BE_USER']->uc['recursiveDelete']) {
150 // TRUE if the delete Recursive flag is set.
151 $this->tce->deleteTree = 1;
152 }
153 if ($GLOBALS['BE_USER']->uc['copyLevels']) {
154 // Set to number of page-levels to copy.
155 $this->tce->copyTree = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($GLOBALS['BE_USER']->uc['copyLevels'], 0, 100);
156 }
157 if ($GLOBALS['BE_USER']->uc['neverHideAtCopy']) {
158 $this->tce->neverHideAtCopy = 1;
159 }
160 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
161 if (is_array($TCAdefaultOverride)) {
162 $this->tce->setDefaultsFromUserTS($TCAdefaultOverride);
163 }
164 // Reverse order.
165 if ($this->flags['reverseOrder']) {
166 $this->tce->reverseOrder = 1;
167 }
168 }
169
170 /**
171 * Clipboard pasting and deleting.
172 *
173 * @return void
174 * @todo Define visibility
175 */
176 public function initClipboard() {
177 if (is_array($this->CB)) {
178 $clipObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
179 $clipObj->initializeClipboard();
180 if ($this->CB['paste']) {
181 $clipObj->setCurrentPad($this->CB['pad']);
182 $this->cmd = $clipObj->makePasteCmdArray($this->CB['paste'], $this->cmd);
183 }
184 if ($this->CB['delete']) {
185 $clipObj->setCurrentPad($this->CB['pad']);
186 $this->cmd = $clipObj->makeDeleteCmdArray($this->cmd);
187 }
188 }
189 }
190
191 /**
192 * Executing the posted actions ...
193 *
194 * @return void
195 * @todo Define visibility
196 */
197 public function main() {
198 // LOAD TCEmain with data and cmd arrays:
199 $this->tce->start($this->data, $this->cmd);
200 if (is_array($this->mirror)) {
201 $this->tce->setMirror($this->mirror);
202 }
203 // Checking referer / executing
204 $refInfo = parse_url(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_REFERER'));
205 $httpHost = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
206 if ($httpHost != $refInfo['host'] && $this->vC != $GLOBALS['BE_USER']->veriCode() && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) {
207 $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));
208 } else {
209 // Register uploaded files
210 $this->tce->process_uploads($_FILES);
211 // Execute actions:
212 $this->tce->process_datamap();
213 $this->tce->process_cmdmap();
214 // Clearing cache:
215 if (!empty($this->cacheCmd)) {
216 $this->tce->clear_cacheCmd($this->cacheCmd);
217 }
218 // Update page tree?
219 if ($this->uPT && (isset($this->data['pages']) || isset($this->cmd['pages']))) {
220 \TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('updatePageTree');
221 }
222 }
223 }
224
225 /**
226 * Redirecting the user after the processing has been done.
227 * Might also display error messages directly, if any.
228 *
229 * @return void
230 * @todo Define visibility
231 */
232 public function finish() {
233 // Prints errors, if...
234 if ($this->prErr) {
235 $this->tce->printLogErrorMessages($this->redirect);
236 }
237 if ($this->redirect && !$this->tce->debug) {
238 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($this->redirect);
239 }
240 }
241
242 }
243
244
245 ?>