[TASK] Remove SVN auto properties $Id$
[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 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 78: class SC_tce_db
42 * 106: function init()
43 * 162: function initClipboard()
44 * 182: function main()
45 * 218: function finish()
46 *
47 * TOTAL FUNCTIONS: 4
48 * (This index is automatically created/updated by the extension "extdeveval")
49 *
50 */
51
52
53 require ('init.php');
54 require ('template.php');
55
56
57
58
59
60
61
62
63
64
65
66 /**
67 * Script Class, creating object of t3lib_TCEmain and sending the posted data to the object.
68 * Used by many smaller forms/links in TYPO3, including the QuickEdit module.
69 * 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).
70 * 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.
71 *
72 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
73 * @package TYPO3
74 * @subpackage core
75 */
76 class SC_tce_db {
77
78 // Internal, static: GPvar
79 var $flags; // Array. Accepts options to be set in TCE object. Currently it supports "reverseOrder" (boolean).
80 var $data; // Data array on the form [tablename][uid][fieldname] = value
81 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!
82 var $mirror; // Array passed to ->setMirror.
83 var $cacheCmd; // Cache command sent to ->clear_cacheCmd
84 var $redirect; // Redirect URL. Script will redirect to this location after performing operations (unless errors has occured)
85 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.
86 # var $_disableRTE;
87 var $CB; // Clipboard command array. May trigger changes in "cmd"
88 var $vC; // Verification code
89 var $uPT; // Boolean. Update Page Tree Trigger. If set and the manipulated records are pages then the update page tree signal will be set.
90 var $generalComment; // String, general comment (for raising stages of workspace versions)
91
92 // Internal, dynamic:
93 var $include_once=array(); // Files to include after init() function is called:
94
95 /**
96 * TYPO3 Core Engine
97 *
98 * @var t3lib_TCEmain
99 */
100 var $tce;
101
102
103
104
105 /**
106 * Initialization of the class
107 *
108 * @return void
109 */
110 function init() {
111 global $BE_USER;
112
113 // GPvars:
114 $this->flags = t3lib_div::_GP('flags');
115 $this->data = t3lib_div::_GP('data');
116 $this->cmd = t3lib_div::_GP('cmd');
117 $this->mirror = t3lib_div::_GP('mirror');
118 $this->cacheCmd = t3lib_div::_GP('cacheCmd');
119 $this->redirect = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('redirect'));
120 $this->prErr = t3lib_div::_GP('prErr');
121 $this->_disableRTE = t3lib_div::_GP('_disableRTE');
122 $this->CB = t3lib_div::_GP('CB');
123 $this->vC = t3lib_div::_GP('vC');
124 $this->uPT = t3lib_div::_GP('uPT');
125 $this->generalComment = t3lib_div::_GP('generalComment');
126
127 // Creating TCEmain object
128 $this->tce = t3lib_div::makeInstance('t3lib_TCEmain');
129 $this->tce->stripslashes_values=0;
130 $this->tce->generalComment = $this->generalComment;
131
132 // Configuring based on user prefs.
133 if ($BE_USER->uc['recursiveDelete']) {
134 $this->tce->deleteTree = 1; // True if the delete Recursive flag is set.
135 }
136 if ($BE_USER->uc['copyLevels']) {
137 $this->tce->copyTree = t3lib_div::intInRange($BE_USER->uc['copyLevels'],0,100); // Set to number of page-levels to copy.
138 }
139 if ($BE_USER->uc['neverHideAtCopy']) {
140 $this->tce->neverHideAtCopy = 1;
141 }
142
143 $TCAdefaultOverride = $BE_USER->getTSConfigProp('TCAdefaults');
144 if (is_array($TCAdefaultOverride)) {
145 $this->tce->setDefaultsFromUserTS($TCAdefaultOverride);
146 }
147
148 // Reverse order.
149 if ($this->flags['reverseOrder']) {
150 $this->tce->reverseOrder=1;
151 }
152
153 # $this->tce->disableRTE = $this->_disableRTE;
154
155 // Clipboard?
156 if (is_array($this->CB)) {
157 $this->include_once[]=PATH_t3lib.'class.t3lib_clipboard.php';
158 }
159 }
160
161 /**
162 * Clipboard pasting and deleting.
163 *
164 * @return void
165 */
166 function initClipboard() {
167 if (is_array($this->CB)) {
168 $clipObj = t3lib_div::makeInstance('t3lib_clipboard');
169 $clipObj->initializeClipboard();
170 if ($this->CB['paste']) {
171 $clipObj->setCurrentPad($this->CB['pad']);
172 $this->cmd = $clipObj->makePasteCmdArray($this->CB['paste'],$this->cmd);
173 }
174 if ($this->CB['delete']) {
175 $clipObj->setCurrentPad($this->CB['pad']);
176 $this->cmd = $clipObj->makeDeleteCmdArray($this->cmd);
177 }
178 }
179 }
180
181 /**
182 * Executing the posted actions ...
183 *
184 * @return void
185 */
186 function main() {
187 global $BE_USER,$TYPO3_CONF_VARS;
188
189 // LOAD TCEmain with data and cmd arrays:
190 $this->tce->start($this->data,$this->cmd);
191 if (is_array($this->mirror)) {$this->tce->setMirror($this->mirror);}
192
193 // Checking referer / executing
194 $refInfo=parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
195 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
196 if ($httpHost!=$refInfo['host'] && $this->vC!=$BE_USER->veriCode() && !$TYPO3_CONF_VARS['SYS']['doNotCheckReferer']) {
197 $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));
198 } else {
199 // Register uploaded files
200 $this->tce->process_uploads($_FILES);
201
202 // Execute actions:
203 $this->tce->process_datamap();
204 $this->tce->process_cmdmap();
205
206 // Clearing cache:
207 $this->tce->clear_cacheCmd($this->cacheCmd);
208
209 // Update page tree?
210 if ($this->uPT && (isset($this->data['pages'])||isset($this->cmd['pages']))) {
211 t3lib_BEfunc::setUpdateSignal('updatePageTree');
212 }
213 }
214 }
215
216 /**
217 * Redirecting the user after the processing has been done.
218 * Might also display error messages directly, if any.
219 *
220 * @return void
221 */
222 function finish() {
223 // Prints errors, if...
224 if ($this->prErr) {
225 $this->tce->printLogErrorMessages($this->redirect);
226 }
227
228 if ($this->redirect && !$this->tce->debug) {
229 t3lib_utility_Http::redirect($this->redirect);
230 }
231 }
232 }
233
234
235 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/tce_db.php'])) {
236 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/tce_db.php']);
237 }
238
239
240
241 // Make instance:
242 $SOBE = t3lib_div::makeInstance('SC_tce_db');
243 $SOBE->init();
244
245 // Include files?
246 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
247
248 $formprotection = t3lib_formprotection_Factory::get();
249
250 if ($formprotection->validateToken(t3lib_div::_GP('formToken'), 'tceAction')) {
251 $SOBE->initClipboard();
252 $SOBE->main();
253
254 // This is done for the clear cache menu, so that it gets a new token
255 // making it possible to clear cache several times.
256 if (t3lib_div::_GP('ajaxCall')) {
257 $token = array();
258 $token['value'] = $formprotection->generateToken('tceAction');
259 $token['name'] = 'formToken';
260 // This will be used by clearcachemenu.js to replace the token for the next call
261 echo t3lib_BEfunc::getUrlToken('tceAction');
262 }
263 }
264 $formprotection->persistTokens();
265 $SOBE->finish();
266
267 ?>