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