Main Page | Directories | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages | Examples

class.tslib_fetce.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2004 Kasper Skaarhoj (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 ***************************************************************/
00083 class tslib_feTCE {
00084 
00085    var $extScripts=array();
00086    var $extScriptsConf=array();
00087    var $newData=array();
00088    var $extraList = 'pid';
00089 
00100    function start($data,$FEData) {
00101       reset($data);
00102       while(list($table,$id_arr)=each($data))   {
00103          t3lib_div::loadTCA($table);
00104          if (is_array($id_arr))  {
00105             $sep=$FEData[$table.'.']['separator']?$FEData[$table.'.']['separator']:chr(10);
00106             reset($id_arr);
00107             while(list($id,$field_arr)=each($id_arr)) {
00108                $this->newData[$table][$id]=Array();
00109                if (strstr($id,'NEW'))  {     // NEW
00110                      // Defaults:
00111                   if ($FEData[$table.'.']['default.'])   {
00112                      $this->newData[$table][$id] = $FEData[$table.'.']['default.'];
00113                   }
00114                   if ($FEData[$table.'.']['autoInsertPID']) {
00115                      $this->newData[$table][$id]['pid'] = intval($GLOBALS['TSFE']->page['uid']);
00116                   }
00117                      // Insert external data:
00118                   if (is_array($field_arr))  {
00119                      reset($field_arr);
00120                      while(list($field,$value)=each($field_arr))  {
00121                         if ($FEData[$table.'.']['allowNew.'][$field])   {
00122                            if (is_array($value)) {
00123                               $this->newData[$table][$id][$field] = implode($sep,$value);
00124                            } else {
00125                               $this->newData[$table][$id][$field] = $value;
00126                            }
00127                         }
00128                      }
00129                   }
00130                      // Double post check
00131                   $dPC_field = $FEData[$table.'.']['doublePostCheck'];
00132                   if (is_array($this->newData[$table][$id]) && $dPC_field) {
00133                      $doublePostCheckKey = $this->calcDoublePostKey($this->newData[$table][$id]);
00134                      if ($this->checkDoublePostExist($table,$dPC_field,$doublePostCheckKey)) {
00135                         unset($this->newData[$table][$id]); // Unsetting the whole thing, because it's not going to be saved.
00136                         $GLOBALS['TT']->setTSlogMessage('"FEData": Submitted record to table $table was doublePosted (key: $doublePostCheckKey). Nothing saved.',2);
00137                      } else {
00138                         $this->newData[$table][$id][$dPC_field] = $doublePostCheckKey; // Setting key value
00139                         $this->extraList.=','.$dPC_field;
00140                      }
00141                   }
00142                } else {    // EDIT
00143                      // Insert external data:
00144                   if (is_array($field_arr))  {
00145                      reset($field_arr);
00146                      while(list($field,$value)=each($field_arr))  {
00147                         if ($FEData[$table.'.']['allowEdit.'][$field])  {
00148                            if (is_array($value)) {
00149                               $this->newData[$table][$id][$field] = implode($sep,$value);
00150                            } else {
00151                               $this->newData[$table][$id][$field] = $value;
00152                            }
00153                         }
00154                      }
00155                   }
00156                      // Internal Override
00157                   if (is_array($FEData[$table.'.']['overrideEdit.']))   {
00158                      reset($FEData[$table.'.']['overrideEdit.']);
00159                      while(list($field,$value)=each($FEData[$table.'.']['overrideEdit.']))   {
00160                         $this->newData[$table][$id][$field] = $value;
00161                      }
00162                   }
00163                }
00164                if ($FEData[$table.'.']['userIdColumn']) {
00165                   $this->newData[$table][$id][$FEData[$table.'.']['userIdColumn']] = intval($GLOBALS['TSFE']->fe_user->user['uid']);
00166                }
00167             }
00168             $incFile = $GLOBALS['TSFE']->tmpl->getFileName($FEData[$table.'.']['processScript']);
00169             if ($incFile)  {
00170                $this->extScripts[$table]=$incFile;
00171                $this->extScriptsConf[$table]=$FEData[$table.'.']['processScript.'];
00172             }
00173          }
00174       }
00175    }
00176 
00187    function checkDoublePostExist($table,$doublePostField,$key) {
00188       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $table, $doublePostField.'='.intval($key));
00189       $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00190       return $row[0];
00191    }
00192 
00200    function calcDoublePostKey($array)  {
00201       ksort($array); // Sorting by key
00202       $doublePostCheckKey = hexdec(substr(md5(serialize($array)),0,8)); // Making key
00203       return $doublePostCheckKey;
00204    }
00205 
00212    function includeScripts()  {
00213       reset($this->extScripts);
00214       while(list($incFile_table,$incFile)=each($this->extScripts))   {
00215          if (@is_file($incFile) && $GLOBALS['TSFE']->checkFileInclude($incFile)) {
00216             include($incFile);   // Always start the incFiles with a check of the object fe_tce.  is_object($this);
00217             $GLOBALS['TT']->setTSlogMessage('Included '.$incFile,0);
00218          } else $GLOBALS['TT']->setTSlogMessage('"'.$incFile.'" was not found!',2);
00219       }
00220    }
00221 
00232    function execNEWinsert($table, $dataArr)  {
00233       $extraList=$this->extraList;
00234       if ($GLOBALS['TCA'][$table]['ctrl']['tstamp'])  {$field=$GLOBALS['TCA'][$table]['ctrl']['tstamp']; $dataArr[$field]=time(); $extraList.=','.$field;}
00235       if ($GLOBALS['TCA'][$table]['ctrl']['crdate'])  {$field=$GLOBALS['TCA'][$table]['ctrl']['crdate']; $dataArr[$field]=time(); $extraList.=','.$field;}
00236       if ($GLOBALS['TCA'][$table]['ctrl']['cruser_id'])  {$field=$GLOBALS['TCA'][$table]['ctrl']['cruser_id']; $dataArr[$field]=0; $extraList.=','.$field;}
00237 
00238       unset($dataArr['uid']); // uid can never be set
00239       $insertFields = array();
00240 
00241       foreach($dataArr as $f => $v) {
00242          if (t3lib_div::inList($extraList,$f) || isset($GLOBALS['TCA'][$table]['columns'][$f])) {
00243             $insertFields[$f] = $v;
00244          }
00245       }
00246 
00247       $GLOBALS['TYPO3_DB']->exec_INSERTquery($table, $insertFields);
00248    }
00249 
00258    function clear_cacheCmd($cacheCmd)  {
00259       $cacheCmd = intval($cacheCmd);
00260       if ($cacheCmd) {
00261          $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages', 'page_id='.intval($cacheCmd));
00262          if ($cacheCmd == intval($GLOBALS['TSFE']->id))  {  // Setting no_cache true if the cleared-cache page is the current page!
00263             $GLOBALS['TSFE']->set_no_cache();
00264          }
00265       }
00266    }
00267 
00274    function getConf($table)   {
00275       return $this->extScriptsConf[$table];
00276    }
00277 }
00278 
00279 
00280 
00281 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_fetce.php'])   {
00282    include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_fetce.php']);
00283 }
00284 
00285 ?>

Generated on Sun Oct 3 01:05:59 2004 for TYPO3core 3.7.0 dev by  doxygen 1.3.8-20040913