TYPO3 API  SVNRelease
tce_db.php
Go to the documentation of this file.
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  * TCE gateway (TYPO3 Core Engine) for database handling
00029  * This script is a gateway for POST forms to class.t3lib_TCEmain that manipulates all information in the database!!
00030  * For syntax and API information, see the document 'TYPO3 Core APIs'
00031  *
00032  * $Id: tce_db.php 10306 2011-01-25 19:12:05Z baschny $
00033  * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
00034  *
00035  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00036  */
00037 /**
00038  * [CLASS/FUNCTION INDEX of SCRIPT]
00039  *
00040  *
00041  *
00042  *   78: class SC_tce_db
00043  *  106:     function init()
00044  *  162:     function initClipboard()
00045  *  182:     function main()
00046  *  218:     function finish()
00047  *
00048  * TOTAL FUNCTIONS: 4
00049  * (This index is automatically created/updated by the extension "extdeveval")
00050  *
00051  */
00052 
00053 
00054 require ('init.php');
00055 require ('template.php');
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 /**
00068  * Script Class, creating object of t3lib_TCEmain and sending the posted data to the object.
00069  * Used by many smaller forms/links in TYPO3, including the QuickEdit module.
00070  * 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).
00071  * 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.
00072  *
00073  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00074  * @package TYPO3
00075  * @subpackage core
00076  */
00077 class SC_tce_db {
00078 
00079         // Internal, static: GPvar
00080     var $flags;         // Array. Accepts options to be set in TCE object. Currently it supports "reverseOrder" (boolean).
00081     var $data;          // Data array on the form [tablename][uid][fieldname] = value
00082     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!
00083     var $mirror;        // Array passed to ->setMirror.
00084     var $cacheCmd;      // Cache command sent to ->clear_cacheCmd
00085     var $redirect;      // Redirect URL. Script will redirect to this location after performing operations (unless errors has occured)
00086     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.
00087 #   var $_disableRTE;
00088     var $CB;            // Clipboard command array. May trigger changes in "cmd"
00089     var $vC;            // Verification code
00090     var $uPT;           // Boolean. Update Page Tree Trigger. If set and the manipulated records are pages then the update page tree signal will be set.
00091     var $generalComment;    // String, general comment (for raising stages of workspace versions)
00092 
00093         // Internal, dynamic:
00094     var $include_once=array();      // Files to include after init() function is called:
00095 
00096     /**
00097      * TYPO3 Core Engine
00098      *
00099      * @var t3lib_TCEmain
00100      */
00101     var $tce;
00102 
00103 
00104 
00105 
00106     /**
00107      * Initialization of the class
00108      *
00109      * @return  void
00110      */
00111     function init() {
00112         global $BE_USER;
00113 
00114             // GPvars:
00115         $this->flags = t3lib_div::_GP('flags');
00116         $this->data = t3lib_div::_GP('data');
00117         $this->cmd = t3lib_div::_GP('cmd');
00118         $this->mirror = t3lib_div::_GP('mirror');
00119         $this->cacheCmd = t3lib_div::_GP('cacheCmd');
00120         $this->redirect = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('redirect'));
00121         $this->prErr = t3lib_div::_GP('prErr');
00122         $this->_disableRTE = t3lib_div::_GP('_disableRTE');
00123         $this->CB = t3lib_div::_GP('CB');
00124         $this->vC = t3lib_div::_GP('vC');
00125         $this->uPT = t3lib_div::_GP('uPT');
00126         $this->generalComment = t3lib_div::_GP('generalComment');
00127 
00128             // Creating TCEmain object
00129         $this->tce = t3lib_div::makeInstance('t3lib_TCEmain');
00130         $this->tce->stripslashes_values=0;
00131         $this->tce->generalComment = $this->generalComment;
00132 
00133             // Configuring based on user prefs.
00134         if ($BE_USER->uc['recursiveDelete'])    {
00135             $this->tce->deleteTree = 1; // True if the delete Recursive flag is set.
00136         }
00137         if ($BE_USER->uc['copyLevels']) {
00138             $this->tce->copyTree = t3lib_div::intInRange($BE_USER->uc['copyLevels'],0,100); // Set to number of page-levels to copy.
00139         }
00140         if ($BE_USER->uc['neverHideAtCopy'])    {
00141             $this->tce->neverHideAtCopy = 1;
00142         }
00143 
00144         $TCAdefaultOverride = $BE_USER->getTSConfigProp('TCAdefaults');
00145         if (is_array($TCAdefaultOverride))  {
00146             $this->tce->setDefaultsFromUserTS($TCAdefaultOverride);
00147         }
00148 
00149             // Reverse order.
00150         if ($this->flags['reverseOrder'])   {
00151             $this->tce->reverseOrder=1;
00152         }
00153 
00154 #       $this->tce->disableRTE = $this->_disableRTE;
00155 
00156             // Clipboard?
00157         if (is_array($this->CB))    {
00158             $this->include_once[]=PATH_t3lib.'class.t3lib_clipboard.php';
00159         }
00160     }
00161 
00162     /**
00163      * Clipboard pasting and deleting.
00164      *
00165      * @return  void
00166      */
00167     function initClipboard()    {
00168         if (is_array($this->CB))    {
00169             $clipObj = t3lib_div::makeInstance('t3lib_clipboard');
00170             $clipObj->initializeClipboard();
00171             if ($this->CB['paste']) {
00172                 $clipObj->setCurrentPad($this->CB['pad']);
00173                 $this->cmd = $clipObj->makePasteCmdArray($this->CB['paste'],$this->cmd);
00174             }
00175             if ($this->CB['delete'])    {
00176                 $clipObj->setCurrentPad($this->CB['pad']);
00177                 $this->cmd = $clipObj->makeDeleteCmdArray($this->cmd);
00178             }
00179         }
00180     }
00181 
00182     /**
00183      * Executing the posted actions ...
00184      *
00185      * @return  void
00186      */
00187     function main() {
00188         global $BE_USER,$TYPO3_CONF_VARS;
00189 
00190             // LOAD TCEmain with data and cmd arrays:
00191         $this->tce->start($this->data,$this->cmd);
00192         if (is_array($this->mirror))    {$this->tce->setMirror($this->mirror);}
00193 
00194             // Checking referer / executing
00195         $refInfo=parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
00196         $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
00197         if ($httpHost!=$refInfo['host'] && $this->vC!=$BE_USER->veriCode() && !$TYPO3_CONF_VARS['SYS']['doNotCheckReferer'])    {
00198             $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));
00199         } else {
00200                 // Register uploaded files
00201             $this->tce->process_uploads($_FILES);
00202 
00203                 // Execute actions:
00204             $this->tce->process_datamap();
00205             $this->tce->process_cmdmap();
00206 
00207                 // Clearing cache:
00208             $this->tce->clear_cacheCmd($this->cacheCmd);
00209 
00210                 // Update page tree?
00211             if ($this->uPT && (isset($this->data['pages'])||isset($this->cmd['pages'])))    {
00212                 t3lib_BEfunc::setUpdateSignal('updatePageTree');
00213             }
00214         }
00215     }
00216 
00217     /**
00218      * Redirecting the user after the processing has been done.
00219      * Might also display error messages directly, if any.
00220      *
00221      * @return  void
00222      */
00223     function finish()   {
00224             // Prints errors, if...
00225         if ($this->prErr)   {
00226             $this->tce->printLogErrorMessages($this->redirect);
00227         }
00228 
00229         if ($this->redirect && !$this->tce->debug) {
00230             t3lib_utility_Http::redirect($this->redirect);
00231         }
00232     }
00233 }
00234 
00235 
00236 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/tce_db.php'])) {
00237     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/tce_db.php']);
00238 }
00239 
00240 
00241 
00242 // Make instance:
00243 $SOBE = t3lib_div::makeInstance('SC_tce_db');
00244 $SOBE->init();
00245 
00246 // Include files?
00247 foreach($SOBE->include_once as $INC_FILE)   include_once($INC_FILE);
00248 
00249 $formprotection = t3lib_formprotection_Factory::get();
00250 
00251 if ($formprotection->validateToken(t3lib_div::_GP('formToken'), 'tceAction')) {
00252     $SOBE->initClipboard();
00253     $SOBE->main();
00254 
00255         // This is done for the clear cache menu, so that it gets a new token
00256         // making it possible to clear cache several times.
00257     if (t3lib_div::_GP('ajaxCall')) {
00258         $token = array();
00259         $token['value'] = $formprotection->generateToken('tceAction');
00260         $token['name'] = 'formToken';
00261             // This will be used by clearcachemenu.js to replace the token for the next call
00262         echo t3lib_BEfunc::getUrlToken('tceAction');
00263     }
00264 }
00265 $formprotection->persistTokens();
00266 $SOBE->finish();
00267 
00268 ?>