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