[FEATURE] stdWrap caching
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_fetce.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 * Form-data processing
29 * Included from index_ts.php
30 *
31 * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 /**
55 * Form-data processing class.
56 * Used by the FE_DATA object found in TSref. Quite old fashioned and used only by a few extensions, like good old 'tt_guest' and 'tt_board'
57 *
58 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
59 * @package TYPO3
60 * @subpackage tslib
61 * @deprecated since TYPO3 3.6, will be removed in TYPO3 4.8
62 */
63 class tslib_feTCE {
64
65 var $extScripts=array();
66 var $extScriptsConf=array();
67 var $newData=array();
68 var $extraList = 'pid';
69
70 public function __construct() {
71 t3lib_div::logDeprecatedFunction();
72 }
73
74 /**
75 * Starting the processing of user input.
76 * Traverses the input data and fills in the array, $this->extScripts with references to files which are then included by includeScripts() (called AFTER start() in tslib_fe)
77 * These scripts will then put the content into the database.
78 *
79 * @param array Input data coming from typ. $_POST['data'] vars
80 * @param array TypoScript configuration for the FEDATA object, $this->config['FEData.']
81 * @return void
82 * @see tslib_fe::fe_tce(), includeScripts()
83 */
84 function start($data,$FEData) {
85 foreach ($data as $table => $id_arr) {
86 t3lib_div::loadTCA($table);
87 if (is_array($id_arr)) {
88 $sep=$FEData[$table.'.']['separator']?$FEData[$table.'.']['separator']:LF;
89 foreach ($id_arr as $id => $field_arr) {
90 $this->newData[$table][$id]=Array();
91 if (strstr($id,'NEW')) { // NEW
92 // Defaults:
93 if ($FEData[$table.'.']['default.']) {
94 $this->newData[$table][$id] = $FEData[$table.'.']['default.'];
95 }
96 if ($FEData[$table.'.']['autoInsertPID']) {
97 $this->newData[$table][$id]['pid'] = intval($GLOBALS['TSFE']->page['uid']);
98 }
99 // Insert external data:
100 if (is_array($field_arr)) {
101 foreach ($field_arr as $field => $value) {
102 if ($FEData[$table.'.']['allowNew.'][$field]) {
103 if (is_array($value)) {
104 $this->newData[$table][$id][$field] = implode($sep,$value);
105 } else {
106 $this->newData[$table][$id][$field] = $value;
107 }
108 }
109 }
110 }
111 // Double post check
112 $dPC_field = $FEData[$table.'.']['doublePostCheck'];
113 if (is_array($this->newData[$table][$id]) && $dPC_field) {
114 $doublePostCheckKey = $this->calcDoublePostKey($this->newData[$table][$id]);
115 if ($this->checkDoublePostExist($table,$dPC_field,$doublePostCheckKey)) {
116 unset($this->newData[$table][$id]); // Unsetting the whole thing, because it's not going to be saved.
117 $GLOBALS['TT']->setTSlogMessage('"FEData": Submitted record to table $table was doublePosted (key: $doublePostCheckKey). Nothing saved.',2);
118 } else {
119 $this->newData[$table][$id][$dPC_field] = $doublePostCheckKey; // Setting key value
120 $this->extraList.=','.$dPC_field;
121 }
122 }
123 } else { // EDIT
124 // Insert external data:
125 if (is_array($field_arr)) {
126 foreach ($field_arr as $field => $value) {
127 if ($FEData[$table.'.']['allowEdit.'][$field]) {
128 if (is_array($value)) {
129 $this->newData[$table][$id][$field] = implode($sep,$value);
130 } else {
131 $this->newData[$table][$id][$field] = $value;
132 }
133 }
134 }
135 }
136 // Internal Override
137 if (is_array($FEData[$table.'.']['overrideEdit.'])) {
138 foreach ($FEData[$table.'.']['overrideEdit.'] as $field => $value) {
139 $this->newData[$table][$id][$field] = $value;
140 }
141 }
142 }
143 if ($FEData[$table.'.']['userIdColumn']) {
144 $this->newData[$table][$id][$FEData[$table.'.']['userIdColumn']] = intval($GLOBALS['TSFE']->fe_user->user['uid']);
145 }
146 }
147 $incFile = $GLOBALS['TSFE']->tmpl->getFileName($FEData[$table.'.']['processScript']);
148 if ($incFile) {
149 $this->extScripts[$table]=$incFile;
150 $this->extScriptsConf[$table]=$FEData[$table.'.']['processScript.'];
151 }
152 }
153 }
154 }
155
156 /**
157 * Checking if a "double-post" exists already.
158 * "Double-posting" is if someone refreshes a page with a form for the message board or guestbook and thus submits the element twice. Checking for double-posting prevents the second submission from being stored. This is done by saving the first record with a MD5 hash of the content - if this hash exists already, the record cannot be saved.
159 *
160 * @param string The database table to check
161 * @param string The fieldname from the database table to search
162 * @param integer The hash value to search for.
163 * @return integer The number of found rows. If zero then no "double-post" was found and its all OK.
164 * @access private
165 */
166 function checkDoublePostExist($table,$doublePostField,$key) {
167 return $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
168 '*',
169 $table,
170 $doublePostField . '=' . intval($key)
171 );
172 }
173
174 /**
175 * Creates the double-post hash value from the input array
176 *
177 * @param array The array with key/values to hash
178 * @return integer And unsigned 32bit integer hash
179 * @access private
180 */
181 function calcDoublePostKey($array) {
182 ksort($array); // Sorting by key
183 $doublePostCheckKey = hexdec(substr(md5(serialize($array)),0,8)); // Making key
184 return $doublePostCheckKey;
185 }
186
187 /**
188 * Includes the submit scripts found in ->extScripts (filled in by the start() function)
189 *
190 * @return void
191 * @see tslib_fe::fe_tce(), includeScripts()
192 */
193 function includeScripts() {
194 foreach ($this->extScripts as $incFile_table => $incFile) {
195 if (@is_file($incFile) && $GLOBALS['TSFE']->checkFileInclude($incFile)) {
196 include($incFile); // Always start the incFiles with a check of the object fe_tce. is_object($this);
197 $GLOBALS['TT']->setTSlogMessage('Included '.$incFile,0);
198 } else $GLOBALS['TT']->setTSlogMessage('"'.$incFile.'" was not found!',2);
199 }
200 }
201
202 /**
203 * Method available to the submit scripts for creating insert queries.
204 * Automatically adds tstamp, crdate, cruser_id field/value pairs.
205 * Will allow only field names which are either found in $GLOBALS['TCA'][...][columns] OR in the $this->extraList
206 * Executes an insert query!
207 *
208 * @param string The table name for which to create the insert statement
209 * @param array Array with key/value pairs being field/values (already escaped)
210 * @return void
211 */
212 function execNEWinsert($table, $dataArr) {
213 $extraList=$this->extraList;
214 if ($GLOBALS['TCA'][$table]['ctrl']['tstamp']) {
215 $field = $GLOBALS['TCA'][$table]['ctrl']['tstamp'];
216 $dataArr[$field] = $GLOBALS['EXEC_TIME'];
217 $extraList .= ',' . $field;
218 }
219 if ($GLOBALS['TCA'][$table]['ctrl']['crdate']) {
220 $field = $GLOBALS['TCA'][$table]['ctrl']['crdate'];
221 $dataArr[$field] = $GLOBALS['EXEC_TIME'];
222 $extraList .= ',' . $field;
223 }
224 if ($GLOBALS['TCA'][$table]['ctrl']['cruser_id']) {
225 $field = $GLOBALS['TCA'][$table]['ctrl']['cruser_id'];
226 $dataArr[$field] = 0;
227 $extraList .= ',' . $field;
228 }
229
230 unset($dataArr['uid']); // uid can never be set
231 $insertFields = array();
232
233 foreach($dataArr as $f => $v) {
234 if (t3lib_div::inList($extraList,$f) || isset($GLOBALS['TCA'][$table]['columns'][$f])) {
235 $insertFields[$f] = $v;
236 }
237 }
238
239 $GLOBALS['TYPO3_DB']->exec_INSERTquery($table, $insertFields);
240 }
241
242 /**
243 * Clear cache for page id.
244 * If the page id is the current page, then set_no_cache() is called (so page caching is disabled)
245 *
246 * @param integer The page id for which to clear the cache
247 * @return void
248 * @see tslib_fe::set_no_cache()
249 */
250 function clear_cacheCmd($cacheCmd) {
251 $cacheCmd = intval($cacheCmd);
252
253 if ($cacheCmd) {
254 $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages')->flushByTag('pageId_' . $cacheCmd);
255
256 if ($cacheCmd == intval($GLOBALS['TSFE']->id)) {
257 // Setting no_cache TRUE if the cleared-cache page is the current page!
258 $GLOBALS['TSFE']->set_no_cache();
259 }
260 }
261 }
262
263 /**
264 * Return TypoScript configuration for a table name
265 *
266 * @param string The table name for which to return TypoScript configuration (From TS: FEData.[table])
267 * @return array TypoScript properties from FEData.[table] - if exists.
268 */
269 function getConf($table) {
270 return $this->extScriptsConf[$table];
271 }
272 }
273
274
275
276 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/class.tslib_fetce.php'])) {
277 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/class.tslib_fetce.php']);
278 }
279
280 ?>