[FEATURE] Improve livesearch results
[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 use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32 /**
33 * Script Class, creating object of \TYPO3\CMS\Core\DataHandling\DataHandler and
34 * sending the posted data to the object.
35 *
36 * Used by many smaller forms/links in TYPO3, including the QuickEdit module.
37 * 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).
38 * 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.
39 *
40 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
41 */
42 class SimpleDataHandlerController {
43
44 // Internal, static: GPvar
45 // Array. Accepts options to be set in TCE object. Currently it supports "reverseOrder" (boolean).
46 /**
47 * @todo Define visibility
48 */
49 public $flags;
50
51 // Data array on the form [tablename][uid][fieldname] = value
52 /**
53 * @todo Define visibility
54 */
55 public $data;
56
57 // 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!
58 /**
59 * @todo Define visibility
60 */
61 public $cmd;
62
63 // Array passed to ->setMirror.
64 /**
65 * @todo Define visibility
66 */
67 public $mirror;
68
69 // Cache command sent to ->clear_cacheCmd
70 /**
71 * @todo Define visibility
72 */
73 public $cacheCmd;
74
75 // Redirect URL. Script will redirect to this location after performing operations (unless errors has occured)
76 /**
77 * @todo Define visibility
78 */
79 public $redirect;
80
81 // 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.
82 /**
83 * @todo Define visibility
84 */
85 public $prErr;
86
87 // Clipboard command array. May trigger changes in "cmd"
88 /**
89 * @todo Define visibility
90 */
91 public $CB;
92
93 // Verification code
94 /**
95 * @todo Define visibility
96 */
97 public $vC;
98
99 // Boolean. Update Page Tree Trigger. If set and the manipulated records are pages then the update page tree signal will be set.
100 /**
101 * @todo Define visibility
102 */
103 public $uPT;
104
105 // String, general comment (for raising stages of workspace versions)
106 /**
107 * @todo Define visibility
108 */
109 public $generalComment;
110
111 // Internal, dynamic:
112 // Files to include after init() function is called:
113 /**
114 * @todo Define visibility
115 */
116 public $include_once = array();
117
118 /**
119 * TYPO3 Core Engine
120 *
121 * @var \TYPO3\CMS\Core\DataHandling\DataHandler
122 * @todo Define visibility
123 */
124 public $tce;
125
126 /**
127 * Initialization of the class
128 *
129 * @return void
130 * @todo Define visibility
131 */
132 public function init() {
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->_disableRTE = GeneralUtility::_GP('_disableRTE');
142 $this->CB = GeneralUtility::_GP('CB');
143 $this->vC = GeneralUtility::_GP('vC');
144 $this->uPT = GeneralUtility::_GP('uPT');
145 $this->generalComment = GeneralUtility::_GP('generalComment');
146 // Creating TCEmain object
147 $this->tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
148 $this->tce->stripslashes_values = 0;
149 $this->tce->generalComment = $this->generalComment;
150 // Configuring based on user prefs.
151 if ($GLOBALS['BE_USER']->uc['recursiveDelete']) {
152 // TRUE if the delete Recursive flag is set.
153 $this->tce->deleteTree = 1;
154 }
155 if ($GLOBALS['BE_USER']->uc['copyLevels']) {
156 // Set to number of page-levels to copy.
157 $this->tce->copyTree = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($GLOBALS['BE_USER']->uc['copyLevels'], 0, 100);
158 }
159 if ($GLOBALS['BE_USER']->uc['neverHideAtCopy']) {
160 $this->tce->neverHideAtCopy = 1;
161 }
162 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
163 if (is_array($TCAdefaultOverride)) {
164 $this->tce->setDefaultsFromUserTS($TCAdefaultOverride);
165 }
166 // Reverse order.
167 if ($this->flags['reverseOrder']) {
168 $this->tce->reverseOrder = 1;
169 }
170 }
171
172 /**
173 * Clipboard pasting and deleting.
174 *
175 * @return void
176 * @todo Define visibility
177 */
178 public function initClipboard() {
179 if (is_array($this->CB)) {
180 $clipObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
181 $clipObj->initializeClipboard();
182 if ($this->CB['paste']) {
183 $clipObj->setCurrentPad($this->CB['pad']);
184 $this->cmd = $clipObj->makePasteCmdArray($this->CB['paste'], $this->cmd);
185 }
186 if ($this->CB['delete']) {
187 $clipObj->setCurrentPad($this->CB['pad']);
188 $this->cmd = $clipObj->makeDeleteCmdArray($this->cmd);
189 }
190 }
191 }
192
193 /**
194 * Executing the posted actions ...
195 *
196 * @return void
197 * @todo Define visibility
198 */
199 public function main() {
200 // LOAD TCEmain with data and cmd arrays:
201 $this->tce->start($this->data, $this->cmd);
202 if (is_array($this->mirror)) {
203 $this->tce->setMirror($this->mirror);
204 }
205 // Checking referer / executing
206 $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER'));
207 $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
208 if ($httpHost != $refInfo['host'] && $this->vC != $GLOBALS['BE_USER']->veriCode() && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) {
209 $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));
210 } else {
211 // Register uploaded files
212 $this->tce->process_uploads($_FILES);
213 // Execute actions:
214 $this->tce->process_datamap();
215 $this->tce->process_cmdmap();
216 // Clearing cache:
217 if (!empty($this->cacheCmd)) {
218 $this->tce->clear_cacheCmd($this->cacheCmd);
219 }
220 // Update page tree?
221 if ($this->uPT && (isset($this->data['pages']) || isset($this->cmd['pages']))) {
222 \TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('updatePageTree');
223 }
224 }
225 }
226
227 /**
228 * Redirecting the user after the processing has been done.
229 * Might also display error messages directly, if any.
230 *
231 * @return void
232 * @todo Define visibility
233 */
234 public function finish() {
235 // Prints errors, if...
236 if ($this->prErr) {
237 $this->tce->printLogErrorMessages($this->redirect);
238 }
239 if ($this->redirect && !$this->tce->debug) {
240 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($this->redirect);
241 }
242 }
243
244 }
245
246 ?>