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