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