[ Index ]
 

Code source de Typo3 4.1.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/t3lib/ -> class.t3lib_transferdata.php (source)

   1  <?php
   2  /***************************************************************
   3  *  Copyright notice
   4  *
   5  *  (c) 1999-2006 Kasper Skaarhoj (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   * Contains class for getting and transforming data for display in backend forms (TCEforms)
  29   *
  30   * $Id: class.t3lib_transferdata.php 2404 2007-07-13 15:44:21Z mundaun $
  31   * Revised for TYPO3 3.6 September/2003 by Kasper Skaarhoj
  32   *
  33   * @author    Kasper Skaarhoj <kasperYYYY@typo3.com>
  34   */
  35  /**
  36   * [CLASS/FUNCTION INDEX of SCRIPT]
  37   *
  38   *
  39   *
  40   *   99: class t3lib_transferData
  41   *
  42   *              SECTION: Getting record content, ready for display in TCEforms
  43   *  138:     function fetchRecord($table,$idList,$operation)
  44   *  225:     function renderRecord($table, $id, $pid, $row)
  45   *  269:     function renderRecordRaw($table, $id, $pid, $row, $TSconfig='', $tscPID=0)
  46   *  327:     function renderRecord_SW($data,$fieldConfig,$TSconfig,$table,$row,$field)
  47   *  359:     function renderRecord_groupProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
  48   *  410:     function renderRecord_selectProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
  49   *  473:     function renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
  50   *  504:     function renderRecord_typesProc($totalRecordContent,$types_fieldConfig,$tscPID,$table,$pid)
  51   *  545:     function renderRecord_inlineProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
  52   *
  53   *              SECTION: FlexForm processing functions
  54   *  632:     function renderRecord_flexProc_procInData($dataPart,$dataStructArray,$pParams)
  55   *  661:     function renderRecord_flexProc_procInData_travDS(&$dataValues,$DSelements,$pParams)
  56   *
  57   *              SECTION: Selector box processing functions
  58   *  738:     function selectAddSpecial($dataAcc, $elements, $specialKey)
  59   *  863:     function selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row, $table)
  60   *  917:     function getDataIdList($elements, $fieldConfig, $row, $table)
  61   *  946:     function procesItemArray($selItems,$config,$fieldTSConfig,$table,$row,$field)
  62   *  961:     function addItems($items,$iArray)
  63   *  983:     function procItems($items,$itemsProcFuncTSconfig,$config,$table,$row,$field)
  64   *
  65   *              SECTION: Helper functions
  66   * 1018:     function lockRecord($table, $id, $pid=0)
  67   * 1035:     function regItem($table, $id, $field, $content)
  68   * 1045:     function sL($in)
  69   *
  70   * TOTAL FUNCTIONS: 20
  71   * (This index is automatically created/updated by the extension "extdeveval")
  72   *
  73   */
  74  
  75  
  76  require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
  77  require_once (PATH_t3lib.'class.t3lib_loadmodules.php');
  78  require_once (PATH_t3lib.'class.t3lib_parsehtml_proc.php');
  79  require_once (PATH_t3lib.'class.t3lib_flexformtools.php');
  80  
  81  
  82  
  83  
  84  
  85  
  86  
  87  
  88  
  89  
  90  
  91  
  92  /**
  93   * Class for getting and transforming data for display in backend forms (TCEforms)
  94   *
  95   * @author    Kasper Skaarhoj <kasperYYYY@typo3.com>
  96   * @package TYPO3
  97   * @subpackage t3lib
  98   */
  99  class t3lib_transferData {
 100          // External, static:
 101      var $lockRecords=0;                    // If set, the records requested are locked.
 102      var $disableRTE=0;                    // Is set externally if RTE is disabled.
 103      var $prevPageID = '';                // If the pid in the command is 'prev' then $prevPageID is used as pid for the record. This is used to attach new records to other previous records eg. new pages.
 104      var $defVals=array();                        // Can be set with an array of default values for tables. First key is table name, second level keys are field names. Originally this was a GLOBAL array used internally.
 105      var $addRawData = FALSE;            // If set, the processed data is overlaid the raw record.
 106  
 107          // Internal, dynamic
 108      var $regTableItems = Array();        // Used to register, which items are already loaded!!
 109      var $regTableItems_data = Array();    // This stores the record data of the loaded records
 110      var $loadModules='';                // Contains loadModules object, if used. (for reuse internally)
 111  
 112  
 113  
 114  
 115  
 116  
 117  
 118  
 119  
 120  
 121      /***********************************************
 122       *
 123       * Getting record content, ready for display in TCEforms
 124       *
 125       ***********************************************/
 126  
 127      /**
 128       * A function which can be used for load a batch of records from $table into internal memory of this object.
 129       * The function is also used to produce proper default data for new records
 130       * Ultimately the function will call renderRecord()
 131       *
 132       * @param    string        Table name, must be found in $TCA
 133       * @param    string        Comma list of id values. If $idList is "prev" then the value from $this->prevPageID is used. NOTICE: If $operation is "new", then negative ids are meant to point to a "previous" record and positive ids are PID values for new records. Otherwise (for existing records that is) it is straight forward table/id pairs.
 134       * @param    string        If "new", then a record with default data is returned. Further, the $id values are meant to be PID values (or if negative, pointing to a previous record). If NOT new, then the table/ids are just pointing to an existing record!
 135       * @return    void
 136       * @see renderRecord()
 137       */
 138  	function fetchRecord($table,$idList,$operation)    {
 139          global $TCA;
 140  
 141          if ((string)$idList == 'prev')    {$idList = $this->prevPageID;}
 142  
 143          if ($TCA[$table])    {
 144              t3lib_div::loadTCA($table);
 145  
 146                  // For each ID value (integer) we
 147              $ids = t3lib_div::trimExplode(',',$idList,1);
 148              foreach($ids as $id)    {
 149                  if (strcmp($id,''))    {    // If ID is not blank:
 150  
 151                          // For new records to be created, find default values:
 152                      if ($operation=='new')    {
 153  
 154                              // Default values:
 155                          $newRow = Array();    // Used to store default values as found here:
 156  
 157                              // Default values as set in userTS:
 158                          $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
 159                          if (is_array($TCAdefaultOverride[$table.'.']))    {
 160                              foreach($TCAdefaultOverride[$table.'.'] as $theF => $theV)    {
 161                                  if (isset($TCA[$table]['columns'][$theF]))    {
 162                                      $newRow[$theF]=$theV;
 163                                  }
 164                              }
 165                          }
 166  
 167                              // Default values as submitted:
 168                          if (is_array($this->defVals[$table]))    {
 169                              foreach($this->defVals[$table] as $theF => $theV)    {
 170                                  if (isset($TCA[$table]['columns'][$theF]))    {
 171                                      $newRow[$theF]=$theV;
 172                                  }
 173                              }
 174                          }
 175  
 176                              // Fetch default values if a previous record exists
 177                          if ($id<0 && $TCA[$table]['ctrl']['useColumnsForDefaultValues'])    {
 178                                  // Fetches the previous record:
 179                              $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.abs($id).t3lib_BEfunc::deleteClause($table));
 180                              if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))    {
 181                                      // Gets the list of fields to copy from the previous record.
 182                                  $fArr=t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['useColumnsForDefaultValues'],1);
 183                                  while(list(,$theF)=each($fArr))    {
 184                                      if (isset($TCA[$table]['columns'][$theF]))    {
 185                                          $newRow[$theF]=$row[$theF];
 186                                      }
 187                                  }
 188                              }
 189                              $GLOBALS['TYPO3_DB']->sql_free_result($res);
 190                          }
 191  
 192                              // Finally, call renderRecord:
 193                          $this->renderRecord($table, uniqid('NEW'), $id, $newRow);
 194                      } else {
 195                          $id=intval($id);
 196  
 197                              // Fetch database values
 198                          $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($id).t3lib_BEfunc::deleteClause($table));
 199                          if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))    {
 200                              t3lib_BEfunc::fixVersioningPid($table,$row);
 201                              $this->renderRecord($table, $id, $row['pid'], $row);
 202                              $contentTable = $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'];
 203                              $this->lockRecord($table, $id, $contentTable==$table?$row['pid']:0);    // Locking the pid if the table edited is the content table.
 204                          }
 205                          $GLOBALS['TYPO3_DB']->sql_free_result($res);
 206                      }
 207                  }
 208              }
 209          }
 210      }
 211  
 212      /**
 213       * This function performs processing on the input $row array and stores internally a corresponding array which contains processed values, ready to pass on to the TCEforms rendering in the frontend!
 214       * The objective with this function is to prepare the content for handling in TCEforms.
 215       * Default values from outside/TSconfig is added by fetchRecord(). In this function default values from TCA is used if a field is NOT defined in $row.
 216       * The resulting, processed row is stored in $this->regTableItems_data[$uniqueItemRef], where $uniqueItemRef is "[tablename]_[id-value]"
 217       *
 218       * @param    string        The table name
 219       * @param    string        The uid value of the record (integer). Can also be a string (NEW-something) if the record is a NEW record.
 220       * @param    integer        The pid integer. For existing records this is of course the row's "pid" field. For new records it can be either a page id (positive) or a pointer to another record from the SAME table (negative) after which the record should be inserted (or on same page)
 221       * @param    array        The row of the current record. If NEW record, then it may be loaded with default values (by eg. fetchRecord()).
 222       * @return    void
 223       * @see fetchRecord()
 224       */
 225  	function renderRecord($table, $id, $pid, $row)    {
 226          global $TCA;
 227  
 228              // Init:
 229          $uniqueItemRef = $table.'_'.$id;
 230          t3lib_div::loadTCA($table);
 231  
 232              // Fetches the true PAGE TSconfig pid to use later, if needed. (Until now, only for the RTE, but later..., who knows?)
 233          list($tscPID)=t3lib_BEfunc::getTSCpid($table,$id,$pid);
 234          $TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig($table,array_merge($row,array('uid'=>$id,'pid'=>$pid)));
 235  
 236              // If the record has not already been loaded (in which case we DON'T do it again)...
 237          if (!$this->regTableItems[$uniqueItemRef])    {
 238              $this->regTableItems[$uniqueItemRef] = 1;    // set "loaded" flag.
 239  
 240                  // If the table is pages, set the previous page id internally.
 241              if ($table == 'pages')    {$this->prevPageID = $id;}
 242  
 243              $this->regTableItems_data[$uniqueItemRef] = $this->renderRecordRaw($table, $id, $pid, $row, $TSconfig, $tscPID);
 244  
 245                  // Merges the processed array on-top of the raw one - this is done because some things in TCEforms may need access to other fields than those in the columns configuration!
 246              if ($this->addRawData && is_array($row) && is_array($this->regTableItems_data[$uniqueItemRef]))    {
 247                  $this->regTableItems_data[$uniqueItemRef] = array_merge($row, $this->regTableItems_data[$uniqueItemRef]);
 248              }
 249          }
 250      }
 251  
 252  
 253  
 254      /**
 255       * This function performs processing on the input $row array and stores internally a corresponding array which contains processed values, ready to pass on to the TCEforms rendering in the frontend!
 256       * The objective with this function is to prepare the content for handling in TCEforms.
 257       * In opposite to renderRecord() this function do not prepare things like fetching TSconfig and others.
 258       * The resulting, processed row will be returned.
 259       *
 260       * @param    string        The table name
 261       * @param    string        The uid value of the record (integer). Can also be a string (NEW-something) if the record is a NEW record.
 262       * @param    integer        The pid integer. For existing records this is of course the row's "pid" field. For new records it can be either a page id (positive) or a pointer to another record from the SAME table (negative) after which the record should be inserted (or on same page)
 263       * @param    array        The row of the current record. If NEW record, then it may be loaded with default values (by eg. fetchRecord()).
 264       * @param    array        Tsconfig array
 265       * @param    integer        PAGE TSconfig pid
 266       * @return    array        Processed record data
 267       * @see renderRecord()
 268       */
 269  	function renderRecordRaw($table, $id, $pid, $row, $TSconfig='', $tscPID=0)    {
 270          global $TCA;
 271  
 272          if(!is_array($TSconfig)) {
 273              $TSconfig = array();
 274          }
 275  
 276              // Create blank accumulation array:
 277          $totalRecordContent=array();
 278  
 279              // Traverse the configured columns for the table (TCA):
 280              // For each column configured, we will perform processing if needed based on the type (eg. for "group" and "select" types this is needed)
 281          t3lib_div::loadTCA($table);
 282          $copyOfColumns = $TCA[$table]['columns'];
 283          foreach($copyOfColumns as $field => $fieldConfig)    {
 284                  // Set $data variable for the field, either inputted value from $row - or if not found, the default value as defined in the "config" array
 285              if (isset($row[$field]))    {
 286                  $data = $row[$field];
 287              } else {
 288                  $data = $fieldConfig['config']['default'];
 289              }
 290  
 291              $data = $this->renderRecord_SW($data,$fieldConfig,$TSconfig,$table,$row,$field);
 292  
 293                  // Set the field in the accumulation array IF the $data variabel is set:
 294              $totalRecordContent[$field] = isset($data) ? $data : '';
 295          }
 296  
 297              // Further processing may apply for each field in the record depending on the settings in the "types" configuration (the list of fields to currently display for a record in TCEforms).
 298              // For instance this could be processing instructions for the Rich Text Editor.
 299          $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table,$totalRecordContent);
 300          if (is_array($types_fieldConfig))    {
 301              $totalRecordContent = $this->renderRecord_typesProc($totalRecordContent,$types_fieldConfig,$tscPID,$table,$pid);
 302          }
 303  
 304              // Register items, mostly for external use (overriding the regItem() function)
 305          foreach($totalRecordContent as $field => $data)    {
 306              $this->regItem($table,$id,$field,$data);
 307          }
 308  
 309              // Finally, store the result:
 310          reset($totalRecordContent);
 311  
 312          return $totalRecordContent;
 313  
 314      }
 315  
 316      /**
 317       * Function with the switch() construct which triggers functions for processing of the data value depending on the TCA-config field type.
 318       *
 319       * @param    string        Value to process
 320       * @param    array        TCA/columns array for field    (independant of TCA for flexforms - coming from XML then)
 321       * @param    array        TSconfig    (blank for flexforms for now)
 322       * @param    string        Table name
 323       * @param    array        The row array, always of the real record (also for flexforms)
 324       * @param    string        The field (empty for flexforms!)
 325       * @return    string        Modified $value
 326       */
 327  	function renderRecord_SW($data,$fieldConfig,$TSconfig,$table,$row,$field)    {
 328          switch((string)$fieldConfig['config']['type'])    {
 329              case 'group':
 330                  $data = $this->renderRecord_groupProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
 331              break;
 332              case 'select':
 333                  $data = $this->renderRecord_selectProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
 334              break;
 335              case 'flex':
 336                  $data = $this->renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
 337              break;
 338              case 'inline':
 339                  $data = $this->renderRecord_inlineProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
 340              break;
 341          }
 342  
 343          return $data;
 344      }
 345  
 346      /**
 347       * Processing of the data value in case the field type is "group"
 348       *
 349       * @param    string        The field value
 350       * @param    array        TCA field config
 351       * @param    array        TCEform TSconfig for the record
 352       * @param    string        Table name
 353       * @param    array        The row
 354       * @param    string        Field name
 355       * @return    string        The processed input field value ($data)
 356       * @access private
 357       * @see renderRecord()
 358       */
 359  	function renderRecord_groupProc($data,$fieldConfig,$TSconfig,$table,$row,$field)    {
 360          switch ($fieldConfig['config']['internal_type'])    {
 361              case 'file':
 362                      // Init array used to accumulate the files:
 363                  $dataAcc=array();
 364  
 365                      // Now, load the files into the $dataAcc array, whether stored by MM or as a list of filenames:
 366                  if ($fieldConfig['config']['MM'])    {
 367                      $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
 368                      $loadDB->start('', 'files', $fieldConfig['config']['MM'], $row['uid']);    // Setting dummy startup
 369  
 370                      foreach($loadDB->itemArray as $value)    {
 371                          if ($value['id'])    {
 372                              $dataAcc[]=rawurlencode($value['id']).'|'.rawurlencode($value['id']);
 373                          }
 374                      }
 375                  } else {
 376                      $fileList = t3lib_div::trimExplode(',',$data,1);
 377                      foreach($fileList as $value)    {
 378                          if ($value)    {
 379                              $dataAcc[]=rawurlencode($value).'|'.rawurlencode($value);
 380                          }
 381                      }
 382                  }
 383                      // Implode the accumulation array to a comma separated string:
 384                  $data = implode(',',$dataAcc);
 385              break;
 386              case 'db':
 387                  $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
 388                  $loadDB->start($data, $fieldConfig['config']['allowed'], $fieldConfig['config']['MM'], $row['uid'], $table, $fieldConfig['config']);
 389                  $loadDB->getFromDB();
 390                  $data = $loadDB->readyForInterface();
 391              break;
 392          }
 393  
 394          return $data;
 395      }
 396  
 397      /**
 398       * Processing of the data value in case the field type is "select"
 399       *
 400       * @param    string        The field value
 401       * @param    array        TCA field config
 402       * @param    array        TCEform TSconfig for the record
 403       * @param    string        Table name
 404       * @param    array        The row
 405       * @param    string        Field name
 406       * @return    string        The processed input field value ($data)
 407       * @access private
 408       * @see renderRecord()
 409       */
 410  	function renderRecord_selectProc($data,$fieldConfig,$TSconfig,$table,$row,$field)    {
 411          global $TCA;
 412  
 413              // Initialize:
 414          $elements = t3lib_div::trimExplode(',',$data,1);    // Current data set.
 415          $dataAcc=array();    // New data set, ready for interface (list of values, rawurlencoded)
 416  
 417              // For list selectors (multi-value):
 418          if (intval($fieldConfig['config']['maxitems'])>1)    {
 419  
 420                  // Add regular elements:
 421              if (is_array($fieldConfig['config']['items']))    {
 422                  $fieldConfig['config']['items'] = $this->procesItemArray($fieldConfig['config']['items'], $fieldConfig['config'], $TSconfig[$field], $table, $row, $field);
 423                  foreach($fieldConfig['config']['items'] as $pvpv)    {
 424                      foreach($elements as $eKey => $value)    {
 425                          if (!strcmp($value,$pvpv[1]))    {
 426                              $dataAcc[$eKey]=rawurlencode($pvpv[1]).'|'.rawurlencode($this->sL($pvpv[0]));
 427                          }
 428                      }
 429                  }
 430              }
 431  
 432                  // Add "special"
 433              if ($fieldConfig['config']['special'])    {
 434                  $dataAcc = $this->selectAddSpecial($dataAcc, $elements, $fieldConfig['config']['special']);
 435              }
 436  
 437                  // Add "foreign table" stuff:
 438              if ($TCA[$fieldConfig['config']['foreign_table']])    {
 439                  $dataAcc = $this->selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row, $table);
 440              }
 441  
 442                  // Always keep the native order for display in interface:
 443              ksort($dataAcc);
 444          } else {    // Normal, <= 1 -> value without title on it
 445              if ($TCA[$fieldConfig['config']['foreign_table']])    {
 446                  // Getting the data
 447                  $dataIds = $this->getDataIdList($elements, $fieldConfig, $row, $table);
 448  
 449                  if (!count($dataIds))    $dataIds = array(0);
 450                  $dataAcc[]=$dataIds[0];
 451              } else {
 452                  $dataAcc[]=$elements[0];
 453              }
 454          }
 455  
 456          return implode(',',$dataAcc);
 457      }
 458  
 459      /**
 460       * Processing of the data value in case the field type is "flex"
 461       * MUST NOT be called in case of already INSIDE a flexform!
 462       *
 463       * @param    string        The field value
 464       * @param    array        TCA field config
 465       * @param    array        TCEform TSconfig for the record
 466       * @param    string        Table name
 467       * @param    array        The row
 468       * @param    string        Field name
 469       * @return    string        The processed input field value ($data)
 470       * @access private
 471       * @see renderRecord()
 472       */
 473  	function renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field)    {
 474          global $TCA;
 475  
 476              // Convert the XML data to PHP array:
 477          $currentValueArray = t3lib_div::xml2array($data);
 478          if (is_array($currentValueArray))    {
 479  
 480                  // Get current value array:
 481              $dataStructArray = t3lib_BEfunc::getFlexFormDS($fieldConfig['config'],$row,$table);
 482              if (is_array($dataStructArray))    {
 483                  $currentValueArray['data'] = $this->renderRecord_flexProc_procInData($currentValueArray['data'],$dataStructArray,array($data,$fieldConfig,$TSconfig,$table,$row,$field));
 484  
 485                  $flexObj = t3lib_div::makeInstance('t3lib_flexformtools');
 486                  $data = $flexObj->flexArray2Xml($currentValueArray, TRUE);
 487              }
 488          }
 489  
 490          return $data;
 491      }
 492  
 493      /**
 494       * Processing of the content in $totalRecordcontent based on settings in the types-configuration
 495       *
 496       * @param    array        The array of values which has been processed according to their type (eg. "group" or "select")
 497       * @param    array        The "types" configuration for the current display of fields.
 498       * @param    integer        PAGE TSconfig PID
 499       * @param    string        Table name
 500       * @param    integer        PID value
 501       * @return    array        The processed version of $totalRecordContent
 502       * @access private
 503       */
 504  	function renderRecord_typesProc($totalRecordContent,$types_fieldConfig,$tscPID,$table,$pid)    {
 505          foreach($types_fieldConfig as $vconf)    {
 506  
 507                  // Find file to write to, if configured:
 508              $eFile = t3lib_parsehtml_proc::evalWriteFile($vconf['spec']['static_write'],$totalRecordContent);
 509  
 510                  // Write file configuration:
 511              if (is_array($eFile))    {
 512                  if ($eFile['loadFromFileField'] && $totalRecordContent[$eFile['loadFromFileField']])    {
 513                          // Read the external file, and insert the content between the ###TYPO3_STATICFILE_EDIT### markers:
 514                      $SW_fileContent = t3lib_div::getUrl($eFile['editFile']);
 515                      $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
 516                      $parseHTML->init('','');
 517  
 518                      $totalRecordContent[$vconf['field']] = $parseHTML->getSubpart(
 519                          $SW_fileContent,
 520                          $eFile['markerField']&&trim($totalRecordContent[$eFile['markerField']])
 521                              ? trim($totalRecordContent[$eFile['markerField']])
 522                              : '###TYPO3_STATICFILE_EDIT###'
 523                      );
 524                  }
 525              }
 526          }
 527  
 528          return $totalRecordContent;
 529      }
 530  
 531      /**
 532       * Processing of the data value in case the field type is "inline"
 533       * In some parts nearly the same as type "select"
 534       *
 535       * @param    string        The field value
 536       * @param    array        TCA field config
 537       * @param    array        TCEform TSconfig for the record
 538       * @param    string        Table name
 539       * @param    array        The row
 540       * @param    string        Field name
 541       * @return    string        The processed input field value ($data)
 542       * @access private
 543       * @see renderRecord()
 544       */
 545  	function renderRecord_inlineProc($data,$fieldConfig,$TSconfig,$table,$row,$field)    {
 546          global $TCA;
 547  
 548              // Initialize:
 549          $elements = t3lib_div::trimExplode(',',$data);    // Current data set.
 550          $dataAcc=array();    // New data set, ready for interface (list of values, rawurlencoded)
 551  
 552          $dataAcc = $this->selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row, $table);
 553  
 554          return implode(',',$dataAcc);
 555      }
 556  
 557  
 558  
 559  
 560  
 561  
 562  
 563  
 564  
 565  
 566  
 567  
 568      /***********************************************
 569       *
 570       * FlexForm processing functions
 571       *
 572       ***********************************************/
 573  
 574      /**
 575       * Function traversing sheets/languages for flex form data structures
 576       *
 577       * @param    array        Data array
 578       * @param    array        Data Structure array
 579       * @param    array        Various parameters to pass-through
 580       * @return    array        Modified $dataPart array.
 581       * @access private
 582       * @see t3lib_TCEmain::checkValue_flex_procInData(), renderRecord_flexProc_procInData_travDS()
 583       */
 584  	function renderRecord_flexProc_procInData($dataPart,$dataStructArray,$pParams)    {
 585          if (is_array($dataPart))    {
 586              foreach($dataPart as $sKey => $sheetDef)    {
 587                  list ($dataStruct,$actualSheet) = t3lib_div::resolveSheetDefInDS($dataStructArray,$sKey);
 588  
 589                  if (is_array($dataStruct) && $actualSheet==$sKey && is_array($sheetDef))    {
 590                      foreach($sheetDef as $lKey => $lData)    {
 591                          $this->renderRecord_flexProc_procInData_travDS(
 592                              $dataPart[$sKey][$lKey],
 593                              $dataStruct['ROOT']['el'],
 594                              $pParams
 595                          );
 596                      }
 597                  }
 598              }
 599          }
 600  
 601          return $dataPart;
 602      }
 603  
 604      /**
 605       * Traverse data array / structure
 606       *
 607       * @param    array        Data array passed by reference.
 608       * @param    array        Data structure
 609       * @param    array        Various parameters pass-through.
 610       * @return    void
 611       * @see renderRecord_flexProc_procInData(), t3lib_TCEmain::checkValue_flex_procInData_travDS()
 612       */
 613  	function renderRecord_flexProc_procInData_travDS(&$dataValues,$DSelements,$pParams)        {
 614          if (is_array($DSelements))    {
 615  
 616                  // For each DS element:
 617              foreach($DSelements as $key => $dsConf)    {
 618  
 619                          // Array/Section:
 620                  if ($DSelements[$key]['type']=='array')    {
 621                      if (is_array($dataValues[$key]['el']))    {
 622                          if ($DSelements[$key]['section'])    {
 623                              foreach($dataValues[$key]['el'] as $ik => $el)    {
 624                                  $theKey = key($el);
 625                                  if (is_array($dataValues[$key]['el'][$ik][$theKey]['el']))    {
 626                                      $this->renderRecord_flexProc_procInData_travDS(
 627                                              $dataValues[$key]['el'][$ik][$theKey]['el'],
 628                                              $DSelements[$key]['el'][$theKey]['el'],
 629                                              $pParams
 630                                          );
 631                                  }
 632                              }
 633                          } else {
 634                              if (!isset($dataValues[$key]['el']))    $dataValues[$key]['el']=array();
 635                              $this->renderRecord_flexProc_procInData_travDS(
 636                                      $dataValues[$key]['el'],
 637                                      $DSelements[$key]['el'],
 638                                      $pParams
 639                                  );
 640                          }
 641                      }
 642                  } else {
 643                      if (is_array($dsConf['TCEforms']['config']) && is_array($dataValues[$key]))    {
 644                          foreach($dataValues[$key] as $vKey => $data)    {
 645  
 646                                  // $data,$fieldConfig,$TSconfig,$table,$row,$field
 647                              list(,,$CVTSconfig,$CVtable,$CVrow,$CVfield) = $pParams;
 648  
 649                                  // Set default value:
 650                              if (!isset($dataValues[$key][$vKey]))    {
 651                                  $dataValues[$key][$vKey] = $dsConf['TCEforms']['config']['default'];
 652                              }
 653  
 654                                  // Process value:
 655                              $dataValues[$key][$vKey] = $this->renderRecord_SW($dataValues[$key][$vKey],$dsConf['TCEforms'],$CVTSconfig,$CVtable,$CVrow,'');
 656                          }
 657                      }
 658                  }
 659              }
 660          }
 661      }
 662  
 663  
 664  
 665  
 666  
 667  
 668  
 669  
 670  
 671  
 672  
 673  
 674      /***********************************************
 675       *
 676       * Selector box processing functions
 677       *
 678       ***********************************************/
 679  
 680      /**
 681       * Adding "special" types to the $dataAcc array of selector items
 682       *
 683       * @param    array        Array with numeric keys, containing values for the selector box, prepared for interface. We are going to add elements to this array as needed.
 684       * @param    array        The array of original elements - basically the field value exploded by ","
 685       * @param    string        The "special" key from the TCA config of the field. Determines the type of processing in here.
 686       * @return    array        Modified $dataAcc array
 687       * @access private
 688       * @see renderRecord_selectProc()
 689       */
 690  	function selectAddSpecial($dataAcc, $elements, $specialKey)    {
 691          global $TCA;
 692  
 693              // Special select types:
 694          switch ((string)$specialKey)    {
 695              case 'tables':        // Listing all tables from $TCA:
 696                  $tNames = array_keys($TCA);
 697                  foreach($tNames as $tableName)    {
 698                      foreach($elements as $eKey => $value)    {
 699                          if (!strcmp($tableName,$value))    {
 700                              $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($this->sL($TCA[$value]['ctrl']['title']));
 701                          }
 702                      }
 703                  }
 704              break;
 705              case 'pagetypes':    // Listing all page types (doktype)
 706                  $theTypes = $TCA['pages']['columns']['doktype']['config']['items'];
 707                  if (is_array($theTypes))    {
 708                      foreach($theTypes as $theTypesArrays)    {
 709                          foreach($elements as $eKey => $value)    {
 710                              if (!strcmp($theTypesArrays[1],$value))    {
 711                                  $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($this->sL($theTypesArrays[0]));
 712                              }
 713                          }
 714                      }
 715                  }
 716              break;
 717              case 'exclude':        // Listing exclude fields.
 718                  $theExcludeFields = t3lib_BEfunc::getExcludeFields();
 719  
 720                  if (is_array($theExcludeFields))    {
 721                      foreach($theExcludeFields as $theExcludeFieldsArrays)    {
 722                          foreach($elements as $eKey => $value)    {
 723                              if (!strcmp($theExcludeFieldsArrays[1],$value))    {
 724                                  $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode(ereg_replace(':$','',$theExcludeFieldsArrays[0]));
 725                              }
 726                          }
 727                      }
 728                  }
 729              break;
 730              case 'explicitValues':
 731                  $theTypes = t3lib_BEfunc::getExplicitAuthFieldValues();
 732  
 733                  foreach($theTypes as $tableFieldKey => $theTypeArrays)    {
 734                      if (is_array($theTypeArrays['items']))    {
 735                          foreach($theTypeArrays['items'] as $itemValue => $itemContent)    {
 736                              foreach($elements as $eKey => $value)    {
 737                                  if (!strcmp($tableFieldKey.':'.$itemValue.':'.$itemContent[0], $value))    {
 738                                      $dataAcc[$eKey] = rawurlencode($value).'|'.rawurlencode('['.$itemContent[2].'] '.$itemContent[1]);
 739                                  }
 740                              }
 741                          }
 742                      }
 743                  }
 744              break;
 745              case 'languages':
 746                  $theLangs = t3lib_BEfunc::getSystemLanguages();
 747                  foreach($theLangs as $lCfg)    {
 748                      foreach($elements as $eKey => $value)    {
 749                          if (!strcmp($lCfg[1], $value))    {
 750                              $dataAcc[$eKey] = rawurlencode($value).'|'.rawurlencode($lCfg[0]);
 751                          }
 752                      }
 753                  }
 754              break;
 755              case 'custom':
 756                  $customOptions = $GLOBALS['TYPO3_CONF_VARS']['BE']['customPermOptions'];
 757  
 758                  if (is_array($customOptions))    {
 759                      foreach($customOptions as $coKey => $coValue) {
 760                          if (is_array($coValue['items']))    {
 761                                  // Traverse items:
 762                              foreach($coValue['items'] as $itemKey => $itemCfg)    {
 763                                  foreach($elements as $eKey => $value)    {
 764                                      if (!strcmp($coKey.':'.$itemKey, $value))    {
 765                                          $dataAcc[$eKey] = rawurlencode($value).'|'.rawurlencode($this->sL($itemCfg[0]));
 766                                      }
 767                                  }
 768                              }
 769                          }
 770                      }
 771                  }
 772              break;
 773              case 'modListGroup':    // Listing modules for GROUPS
 774              case 'modListUser':        // Listing modules for USERS:
 775                  if (!$this->loadModules)    {
 776                      $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
 777                      $this->loadModules->load($GLOBALS['TBE_MODULES']);
 778                  }
 779                  $modList = ($specialKey=='modListUser') ? $this->loadModules->modListUser : $this->loadModules->modListGroup;
 780  
 781                  foreach($modList as $theModName)    {
 782                      foreach($elements as $eKey => $value)    {
 783                          $label = '';
 784                              // Add label for main module:
 785                          $pp = explode('_',$value);
 786                          if (count($pp)>1)    $label.=$GLOBALS['LANG']->moduleLabels['tabs'][$pp[0].'_tab'].'>';
 787                              // Add modules own label now:
 788                          $label.= $GLOBALS['LANG']->moduleLabels['tabs'][$value.'_tab'];
 789  
 790                          if (!strcmp($theModName,$value))    {
 791                              $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($label);
 792                          }
 793                      }
 794                  }
 795              break;
 796          }
 797  
 798          return $dataAcc;
 799      }
 800  
 801      /**
 802       * Adds the foreign record elements to $dataAcc, if any
 803       *
 804       * @param    array        Array with numeric keys, containing values for the selector box, prepared for interface. We are going to add elements to this array as needed.
 805       * @param    array        The array of original elements - basically the field value exploded by ","
 806       * @param    array        Field configuration from TCA
 807       * @param    string        The field name
 808       * @param    array        TSconfig for the record
 809       * @param    array        The record
 810       * @param    array        The current table
 811       * @return    array        Modified $dataAcc array
 812       * @access private
 813       * @see renderRecord_selectProc()
 814       */
 815  	function selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row, $table)    {
 816          global $TCA;
 817  
 818              // Init:
 819          $recordList = Array();
 820  
 821              // foreign_table
 822          $subres = t3lib_BEfunc::exec_foreign_table_where_query($fieldConfig,$field,$TSconfig);
 823          while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres))    {
 824              $recordList[$subrow['uid']] = t3lib_BEfunc::getRecordTitle($fieldConfig['config']['foreign_table'],$subrow);
 825          }
 826  
 827              // neg_foreign_table
 828          if (is_array($TCA[$fieldConfig['config']['neg_foreign_table']]))    {
 829              $subres = t3lib_BEfunc::exec_foreign_table_where_query($fieldConfig,$field,$TSconfig,'neg_');
 830              while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres))    {
 831                  $recordList[-$subrow['uid']] = t3lib_BEfunc::getRecordTitle($fieldConfig['config']['neg_foreign_table'],$subrow);
 832              }
 833          }
 834  
 835              // At this point all records that CAN be selected is found in $recordList
 836              // Now, get the data from loadDBgroup based on the input list of values.
 837          $dataIds = $this->getDataIdList($elements, $fieldConfig, $row, $table);
 838          if ($fieldConfig['config']['MM'])    $dataAcc=array();    // Reset, if MM (which cannot bear anything but real relations!)
 839  
 840              // After this we can traverse the loadDBgroup values and match values with the list of possible values in $recordList:
 841          foreach($dataIds as $theId)    {
 842              if (isset($recordList[$theId]))    {
 843                  $lPrefix = $this->sL($fieldConfig['config'][($theId>0?'':'neg_').'foreign_table_prefix']);
 844                  if ($fieldConfig['config']['MM'] || $fieldConfig['config']['foreign_field'])    {
 845                      $dataAcc[]=rawurlencode($theId).'|'.rawurlencode(t3lib_div::fixed_lgd_cs($lPrefix.strip_tags($recordList[$theId]),$GLOBALS['BE_USER']->uc['titleLen']));
 846                  } else {
 847                      foreach($elements as $eKey => $value)    {
 848                          if (!strcmp($theId,$value))    {
 849                              $dataAcc[$eKey]=rawurlencode($theId).'|'.rawurlencode(t3lib_div::fixed_lgd_cs($lPrefix.strip_tags($recordList[$theId]),$GLOBALS['BE_USER']->uc['titleLen']));
 850                          }
 851                      }
 852                  }
 853              }
 854          }
 855  
 856          return $dataAcc;
 857      }
 858  
 859      /**
 860       * Returning the id-list processed by loadDBgroup for the foreign tables.
 861       *
 862       * @param    array        The array of original elements - basically the field value exploded by ","
 863       * @param    array        Field configuration from TCA
 864       * @param    array        The data array, currently. Used to set the "local_uid" for selecting MM relation records.
 865       * @param    string        Current table name. passed on to t3lib_loadDBGroup
 866       * @return    array        An array with ids of the records from the input elements array.
 867       * @access private
 868       */
 869  	function getDataIdList($elements, $fieldConfig, $row, $table)    {
 870          $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
 871          $loadDB->registerNonTableValues=$fieldConfig['config']['allowNonIdValues'] ? 1 : 0;
 872          $loadDB->start(implode(',',$elements),
 873              $fieldConfig['config']['foreign_table'].','.$fieldConfig['config']['neg_foreign_table'],
 874              $fieldConfig['config']['MM'],
 875              $row['uid'],
 876              $table,
 877              $fieldConfig['config']
 878          );
 879  
 880          $idList = $loadDB->convertPosNeg($loadDB->getValueArray(),$fieldConfig['config']['foreign_table'],$fieldConfig['config']['neg_foreign_table']);
 881  
 882          return $idList;
 883      }
 884  
 885      /**
 886       * Processing of selector box items. This includes the automated adding of elements plus user-function processing.
 887       *
 888       * @param    array        The elements to process
 889       * @param    array        TCA/columns configuration
 890       * @param    array        TSconfig for the field
 891       * @param    string        The table name
 892       * @param    array        The current row
 893       * @param    string        The field name
 894       * @return    array        The modified input $selItems array
 895       * @access private
 896       * @see renderRecord_selectProc()
 897       */
 898  	function procesItemArray($selItems,$config,$fieldTSConfig,$table,$row,$field)    {
 899          $selItems = $this->addItems($selItems,$fieldTSConfig['addItems.']);
 900          if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$fieldTSConfig['itemsProcFunc.'],$config,$table,$row,$field);
 901          return $selItems;
 902      }
 903  
 904      /**
 905       * Adding items from $iArray to $items array
 906       *
 907       * @param    array        The array of selector box items to which key(value) / value(label) pairs from $iArray will be added.
 908       * @param    array        The array of elements to add. The keys will become values. The value will become the label.
 909       * @return    array        The modified input $items array
 910       * @access private
 911       * @see procesItemArray()
 912       */
 913  	function addItems($items,$iArray)    {
 914          if (is_array($iArray))    {
 915              foreach($iArray as $value => $label)    {
 916                  $items[]=array($label,$value);
 917              }
 918          }
 919          return $items;
 920      }
 921  
 922      /**
 923       * User processing of a selector box array of values.
 924       *
 925       * @param    array        The array of selector box items
 926       * @param    array        TSconfig for the fields itemProcFunc
 927       * @param    array        TCA/columns configuration
 928       * @param    string        The table name
 929       * @param    array        The current row
 930       * @param    string        The field name
 931       * @return    array        The modified input $items array
 932       * @access private
 933       * @see procesItemArray()
 934       */
 935  	function procItems($items,$itemsProcFuncTSconfig,$config,$table,$row,$field)    {
 936          $params=array();
 937          $params['items'] = &$items;
 938          $params['config'] = $config;
 939          $params['TSconfig'] = $itemsProcFuncTSconfig;
 940          $params['table'] = $table;
 941          $params['row'] = $row;
 942          $params['field'] = $field;
 943  
 944          t3lib_div::callUserFunction($config['itemsProcFunc'],$params,$this);
 945          return $items;
 946      }
 947  
 948  
 949  
 950  
 951  
 952  
 953  
 954  
 955  
 956      /***********************************************
 957       *
 958       * Helper functions
 959       *
 960       ***********************************************/
 961  
 962      /**
 963       * Sets the lock for a record from table/id, IF $this->lockRecords is set!
 964       *
 965       * @param    string        The table name
 966       * @param    integer        The id of the record
 967       * @param    integer        The pid of the record
 968       * @return    void
 969       */
 970  	function lockRecord($table, $id, $pid=0)    {
 971          if ($this->lockRecords)    {
 972              t3lib_BEfunc::lockRecords($table,$id,$pid);
 973          }
 974      }
 975  
 976      /**
 977       * Dummy function, can be used to "register" records. Used by eg. the "show_item" script.
 978       *
 979       * @param    string        Table name
 980       * @param    integer        Record id
 981       * @param    string        Field name
 982       * @param    string        Field content.
 983       * @return    void
 984       * @access private
 985       * @see renderRecord()
 986       */
 987  	function regItem($table, $id, $field, $content)    {
 988      }
 989  
 990      /**
 991       * Local wrapper function for LANG->sL (returning language labels)
 992       *
 993       * @param    string        Language label key
 994       * @return    string        Localized label value.
 995       * @access private
 996       */
 997      function sL($in)    {
 998          return $GLOBALS['LANG']->sL($in);
 999      }
1000  }
1001  
1002  
1003  if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transferdata.php'])    {
1004      include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transferdata.php']);
1005  }
1006  ?>


Généré le : Sun Nov 25 17:13:16 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics