|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 /** 00028 * Form-data processing 00029 * included from index_ts.php 00030 * 00031 * $Id: class.tslib_fetce.php 10317 2011-01-26 00:56:49Z baschny $ 00032 * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj 00033 * 00034 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00035 */ 00036 /** 00037 * [CLASS/FUNCTION INDEX of SCRIPT] 00038 * 00039 * 00040 * 00041 * 83: class tslib_feTCE 00042 * 100: function start($data,$FEData) 00043 * 187: function checkDoublePostExist($table,$doublePostField,$key) 00044 * 200: function calcDoublePostKey($array) 00045 * 212: function includeScripts() 00046 * 232: function execNEWinsert($table, $dataArr) 00047 * 258: function clear_cacheCmd($cacheCmd) 00048 * 274: function getConf($table) 00049 * 00050 * TOTAL FUNCTIONS: 7 00051 * (This index is automatically created/updated by the extension "extdeveval") 00052 * 00053 */ 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 /** 00074 * Form-data processing class. 00075 * 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' 00076 * 00077 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00078 * @package TYPO3 00079 * @subpackage tslib 00080 * @deprecated since TYPO3 3.6 00081 */ 00082 class tslib_feTCE { 00083 00084 var $extScripts=array(); 00085 var $extScriptsConf=array(); 00086 var $newData=array(); 00087 var $extraList = 'pid'; 00088 00089 /** 00090 * Starting the processing of user input. 00091 * 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) 00092 * These scripts will then put the content into the database. 00093 * 00094 * @param array Input data coming from typ. $_POST['data'] vars 00095 * @param array TypoScript configuration for the FEDATA object, $this->config['FEData.'] 00096 * @return void 00097 * @see tslib_fe::fe_tce(), includeScripts() 00098 */ 00099 function start($data,$FEData) { 00100 foreach ($data as $table => $id_arr) { 00101 t3lib_div::loadTCA($table); 00102 if (is_array($id_arr)) { 00103 $sep=$FEData[$table.'.']['separator']?$FEData[$table.'.']['separator']:LF; 00104 foreach ($id_arr as $id => $field_arr) { 00105 $this->newData[$table][$id]=Array(); 00106 if (strstr($id,'NEW')) { // NEW 00107 // Defaults: 00108 if ($FEData[$table.'.']['default.']) { 00109 $this->newData[$table][$id] = $FEData[$table.'.']['default.']; 00110 } 00111 if ($FEData[$table.'.']['autoInsertPID']) { 00112 $this->newData[$table][$id]['pid'] = intval($GLOBALS['TSFE']->page['uid']); 00113 } 00114 // Insert external data: 00115 if (is_array($field_arr)) { 00116 foreach ($field_arr as $field => $value) { 00117 if ($FEData[$table.'.']['allowNew.'][$field]) { 00118 if (is_array($value)) { 00119 $this->newData[$table][$id][$field] = implode($sep,$value); 00120 } else { 00121 $this->newData[$table][$id][$field] = $value; 00122 } 00123 } 00124 } 00125 } 00126 // Double post check 00127 $dPC_field = $FEData[$table.'.']['doublePostCheck']; 00128 if (is_array($this->newData[$table][$id]) && $dPC_field) { 00129 $doublePostCheckKey = $this->calcDoublePostKey($this->newData[$table][$id]); 00130 if ($this->checkDoublePostExist($table,$dPC_field,$doublePostCheckKey)) { 00131 unset($this->newData[$table][$id]); // Unsetting the whole thing, because it's not going to be saved. 00132 $GLOBALS['TT']->setTSlogMessage('"FEData": Submitted record to table $table was doublePosted (key: $doublePostCheckKey). Nothing saved.',2); 00133 } else { 00134 $this->newData[$table][$id][$dPC_field] = $doublePostCheckKey; // Setting key value 00135 $this->extraList.=','.$dPC_field; 00136 } 00137 } 00138 } else { // EDIT 00139 // Insert external data: 00140 if (is_array($field_arr)) { 00141 foreach ($field_arr as $field => $value) { 00142 if ($FEData[$table.'.']['allowEdit.'][$field]) { 00143 if (is_array($value)) { 00144 $this->newData[$table][$id][$field] = implode($sep,$value); 00145 } else { 00146 $this->newData[$table][$id][$field] = $value; 00147 } 00148 } 00149 } 00150 } 00151 // Internal Override 00152 if (is_array($FEData[$table.'.']['overrideEdit.'])) { 00153 foreach ($FEData[$table.'.']['overrideEdit.'] as $field => $value) { 00154 $this->newData[$table][$id][$field] = $value; 00155 } 00156 } 00157 } 00158 if ($FEData[$table.'.']['userIdColumn']) { 00159 $this->newData[$table][$id][$FEData[$table.'.']['userIdColumn']] = intval($GLOBALS['TSFE']->fe_user->user['uid']); 00160 } 00161 } 00162 $incFile = $GLOBALS['TSFE']->tmpl->getFileName($FEData[$table.'.']['processScript']); 00163 if ($incFile) { 00164 $this->extScripts[$table]=$incFile; 00165 $this->extScriptsConf[$table]=$FEData[$table.'.']['processScript.']; 00166 } 00167 } 00168 } 00169 } 00170 00171 /** 00172 * Checking if a "double-post" exists already. 00173 * "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. 00174 * 00175 * @param string The database table to check 00176 * @param string The fieldname from the database table to search 00177 * @param integer The hash value to search for. 00178 * @return integer The number of found rows. If zero then no "double-post" was found and its all OK. 00179 * @access private 00180 */ 00181 function checkDoublePostExist($table,$doublePostField,$key) { 00182 return $GLOBALS['TYPO3_DB']->exec_SELECTcountRows( 00183 '*', 00184 $table, 00185 $doublePostField . '=' . intval($key) 00186 ); 00187 } 00188 00189 /** 00190 * Creates the double-post hash value from the input array 00191 * 00192 * @param array The array with key/values to hash 00193 * @return integer And unsigned 32bit integer hash 00194 * @access private 00195 */ 00196 function calcDoublePostKey($array) { 00197 ksort($array); // Sorting by key 00198 $doublePostCheckKey = hexdec(substr(md5(serialize($array)),0,8)); // Making key 00199 return $doublePostCheckKey; 00200 } 00201 00202 /** 00203 * Includes the submit scripts found in ->extScripts (filled in by the start() function) 00204 * 00205 * @return void 00206 * @see tslib_fe::fe_tce(), includeScripts() 00207 */ 00208 function includeScripts() { 00209 foreach ($this->extScripts as $incFile_table => $incFile) { 00210 if (@is_file($incFile) && $GLOBALS['TSFE']->checkFileInclude($incFile)) { 00211 include($incFile); // Always start the incFiles with a check of the object fe_tce. is_object($this); 00212 $GLOBALS['TT']->setTSlogMessage('Included '.$incFile,0); 00213 } else $GLOBALS['TT']->setTSlogMessage('"'.$incFile.'" was not found!',2); 00214 } 00215 } 00216 00217 /** 00218 * Method available to the submit scripts for creating insert queries. 00219 * Automatically adds tstamp, crdate, cruser_id field/value pairs. 00220 * Will allow only field names which are either found in $TCA[...][columns] OR in the $this->extraList 00221 * Executes an insert query! 00222 * 00223 * @param string The table name for which to create the insert statement 00224 * @param array Array with key/value pairs being field/values (already escaped) 00225 * @return void 00226 */ 00227 function execNEWinsert($table, $dataArr) { 00228 $extraList=$this->extraList; 00229 if ($GLOBALS['TCA'][$table]['ctrl']['tstamp']) { 00230 $field = $GLOBALS['TCA'][$table]['ctrl']['tstamp']; 00231 $dataArr[$field] = $GLOBALS['EXEC_TIME']; 00232 $extraList .= ',' . $field; 00233 } 00234 if ($GLOBALS['TCA'][$table]['ctrl']['crdate']) { 00235 $field = $GLOBALS['TCA'][$table]['ctrl']['crdate']; 00236 $dataArr[$field] = $GLOBALS['EXEC_TIME']; 00237 $extraList .= ',' . $field; 00238 } 00239 if ($GLOBALS['TCA'][$table]['ctrl']['cruser_id']) {$field=$GLOBALS['TCA'][$table]['ctrl']['cruser_id']; $dataArr[$field]=0; $extraList.=','.$field;} 00240 00241 unset($dataArr['uid']); // uid can never be set 00242 $insertFields = array(); 00243 00244 foreach($dataArr as $f => $v) { 00245 if (t3lib_div::inList($extraList,$f) || isset($GLOBALS['TCA'][$table]['columns'][$f])) { 00246 $insertFields[$f] = $v; 00247 } 00248 } 00249 00250 $GLOBALS['TYPO3_DB']->exec_INSERTquery($table, $insertFields); 00251 } 00252 00253 /** 00254 * Clear cache for page id. 00255 * If the page id is the current page, then set_no_cache() is called (so page caching is disabled) 00256 * 00257 * @param integer The page id for which to clear the cache 00258 * @return void 00259 * @see tslib_fe::set_no_cache() 00260 */ 00261 function clear_cacheCmd($cacheCmd) { 00262 $cacheCmd = intval($cacheCmd); 00263 00264 if ($cacheCmd) { 00265 if (TYPO3_UseCachingFramework) { 00266 $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages'); 00267 $pageCache->flushByTag('pageId_' . $cacheCmd); 00268 } else { 00269 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages', 'page_id = ' . $cacheCmd); 00270 } 00271 00272 if ($cacheCmd == intval($GLOBALS['TSFE']->id)) { 00273 // Setting no_cache true if the cleared-cache page is the current page! 00274 $GLOBALS['TSFE']->set_no_cache(); 00275 } 00276 } 00277 } 00278 00279 /** 00280 * Return TypoScript configuration for a table name 00281 * 00282 * @param string The table name for which to return TypoScript configuration (From TS: FEData.[table]) 00283 * @return array TypoScript properties from FEData.[table] - if exists. 00284 */ 00285 function getConf($table) { 00286 return $this->extScriptsConf[$table]; 00287 } 00288 } 00289 00290 00291 00292 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/class.tslib_fetce.php'])) { 00293 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/class.tslib_fetce.php']); 00294 } 00295 00296 ?>
1.8.0