[BUGFIX] Do not gather log info in DataHandler if logging is disabled
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / DataHandling / DataHandler.php
1 <?php
2 namespace TYPO3\CMS\Core\DataHandling;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
19 use TYPO3\CMS\Core\Cache\CacheManager;
20 use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
21 use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
22 use TYPO3\CMS\Core\Database\DatabaseConnection;
23 use TYPO3\CMS\Core\Database\ReferenceIndex;
24 use TYPO3\CMS\Core\Database\RelationHandler;
25 use TYPO3\CMS\Core\Messaging\FlashMessage;
26 use TYPO3\CMS\Core\Messaging\FlashMessageService;
27 use TYPO3\CMS\Core\Resource\ResourceFactory;
28 use TYPO3\CMS\Core\Type\Bitmask\Permission;
29 use TYPO3\CMS\Core\Utility\ArrayUtility;
30 use TYPO3\CMS\Core\Utility\File\BasicFileUtility;
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32 use TYPO3\CMS\Core\Utility\MathUtility;
33 use TYPO3\CMS\Core\Utility\PathUtility;
34 use TYPO3\CMS\Core\Versioning\VersionState;
35
36 /**
37 * The main data handler class which takes care of correctly updating and inserting records.
38 * This class was formerly known as TCEmain.
39 *
40 * This is the TYPO3 Core Engine class for manipulation of the database
41 * This class is used by eg. the tce_db.php script which provides an the interface for POST forms to this class.
42 *
43 * Dependencies:
44 * - $GLOBALS['TCA'] must exist
45 * - $GLOBALS['LANG'] must exist
46 *
47 * tce_db.php for further comments and SYNTAX! Also see document 'TYPO3 Core API' for details.
48 *
49 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
50 */
51 class DataHandler {
52
53 // *********************
54 // Public variables you can configure before using the class:
55 // *********************
56 /**
57 * If TRUE, the default log-messages will be stored. This should not be necessary if the locallang-file for the
58 * log-display is properly configured. So disabling this will just save some database-space as the default messages are not saved.
59 *
60 * @var bool
61 */
62 public $storeLogMessages = TRUE;
63
64 /**
65 * If TRUE, actions are logged to sys_log.
66 *
67 * @var bool
68 */
69 public $enableLogging = TRUE;
70
71 /**
72 * If TRUE, the datamap array is reversed in the order, which is a nice thing if you're creating a whole new
73 * bunch of records.
74 *
75 * @var bool
76 */
77 public $reverseOrder = FALSE;
78
79 /**
80 * If TRUE, only fields which are different from the database values are saved! In fact, if a whole input array
81 * is similar, it's not saved then.
82 *
83 * @var bool
84 */
85 public $checkSimilar = TRUE;
86
87 /**
88 * If TRUE, incoming values in the data-array have their slashes stripped. ALWAYS SET THIS TO ZERO and supply an
89 * unescaped data array instead. This switch may totally disappear in future versions of this class!
90 *
91 * @var bool
92 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
93 */
94 public $stripslashes_values = TRUE;
95
96 /**
97 * This will read the record after having updated or inserted it. If anything is not properly submitted an error
98 * is written to the log. This feature consumes extra time by selecting records
99 *
100 * @var bool
101 */
102 public $checkStoredRecords = TRUE;
103
104 /**
105 * If set, values '' and 0 will equal each other when the stored records are checked.
106 *
107 * @var bool
108 */
109 public $checkStoredRecords_loose = TRUE;
110
111 /**
112 * If this is set, then a page is deleted by deleting the whole branch under it (user must have
113 * delete permissions to it all). If not set, then the page is deleted ONLY if it has no branch.
114 *
115 * @var bool
116 */
117 public $deleteTree = FALSE;
118
119 /**
120 * If set, then the 'hideAtCopy' flag for tables will be ignored.
121 *
122 * @var bool
123 */
124 public $neverHideAtCopy = FALSE;
125
126 /**
127 * If set, then the TCE class has been instantiated during an import action of a T3D
128 *
129 * @var bool
130 */
131 public $isImporting = FALSE;
132
133 /**
134 * If set, then transformations are NOT performed on the input.
135 *
136 * @var bool
137 */
138 public $dontProcessTransformations = FALSE;
139
140 /**
141 * If set, .vDEFbase values are unset in flexforms.
142 *
143 * @var bool
144 */
145 public $clear_flexFormData_vDEFbase = FALSE;
146
147 /**
148 * TRUE: (traditional) Updates when record is saved. For flexforms, updates if change is made to the localized value.
149 * FALSE: Will not update anything.
150 * "FORCE_FFUPD" (string): Like TRUE, but will force update to the FlexForm Field
151 *
152 * @var bool|string
153 */
154 public $updateModeL10NdiffData = TRUE;
155
156 /**
157 * If TRUE, the translation diff. fields will in fact be reset so that they indicate that all needs to change again!
158 * It's meant as the opposite of declaring the record translated.
159 *
160 * @var bool
161 */
162 public $updateModeL10NdiffDataClear = FALSE;
163
164 /**
165 * If TRUE, workspace restrictions are bypassed on edit an create actions (process_datamap()).
166 * YOU MUST KNOW what you do if you use this feature!
167 *
168 * @var bool
169 */
170 public $bypassWorkspaceRestrictions = FALSE;
171
172 /**
173 * If TRUE, file handling of attached files (addition, deletion etc) is bypassed - the value is saved straight away.
174 * YOU MUST KNOW what you are doing with this feature!
175 *
176 * @var bool
177 */
178 public $bypassFileHandling = FALSE;
179
180 /**
181 * If TRUE, access check, check for deleted etc. for records is bypassed.
182 * YOU MUST KNOW what you are doing if you use this feature!
183 *
184 * @var bool
185 */
186 public $bypassAccessCheckForRecords = FALSE;
187
188 /**
189 * Comma-separated list. This list of tables decides which tables will be copied. If empty then none will.
190 * If '*' then all will (that the user has permission to of course)
191 *
192 * @var string
193 */
194 public $copyWhichTables = '*';
195
196 /**
197 * If 0 then branch is NOT copied.
198 * If 1 then pages on the 1st level is copied.
199 * If 2 then pages on the second level is copied ... and so on
200 *
201 * @var int
202 */
203 public $copyTree = 0;
204
205 /**
206 * [table][fields]=value: New records are created with default values and you can set this array on the
207 * form $defaultValues[$table][$field] = $value to override the default values fetched from TCA.
208 * If ->setDefaultsFromUserTS is called UserTSconfig default values will overrule existing values in this array
209 * (thus UserTSconfig overrules externally set defaults which overrules TCA defaults)
210 *
211 * @var array
212 */
213 public $defaultValues = array();
214
215 /**
216 * [table][fields]=value: You can set this array on the form $overrideValues[$table][$field] = $value to
217 * override the incoming data. You must set this externally. You must make sure the fields in this array are also
218 * found in the table, because it's not checked. All columns can be set by this array!
219 *
220 * @var array
221 */
222 public $overrideValues = array();
223
224 /**
225 * [filename]=alternative_filename: Use this array to force another name onto a file.
226 * Eg. if you set ['/tmp/blablabal'] = 'my_file.txt' and '/tmp/blablabal' is set for a certain file-field,
227 * then 'my_file.txt' will be used as the name instead.
228 *
229 * @var array
230 */
231 public $alternativeFileName = array();
232
233 /**
234 * Array [filename]=alternative_filepath: Same as alternativeFileName but with relative path to the file
235 *
236 * @var array
237 */
238 public $alternativeFilePath = array();
239
240 /**
241 * If entries are set in this array corresponding to fields for update, they are ignored and thus NOT updated.
242 * You could set this array from a series of checkboxes with value=0 and hidden fields before the checkbox with 1.
243 * Then an empty checkbox will disable the field.
244 *
245 * @var array
246 */
247 public $data_disableFields = array();
248
249 /**
250 * Use this array to validate suggested uids for tables by setting [table]:[uid]. This is a dangerous option
251 * since it will force the inserted record to have a certain UID. The value just have to be TRUE, but if you set
252 * it to "DELETE" it will make sure any record with that UID will be deleted first (raw delete).
253 * The option is used for import of T3D files when synchronizing between two mirrored servers.
254 * As a security measure this feature is available only for Admin Users (for now)
255 *
256 * @var array
257 */
258 public $suggestedInsertUids = array();
259
260 /**
261 * Object. Call back object for FlexForm traversal. Useful when external classes wants to use the
262 * iteration functions inside DataHandler for traversing a FlexForm structure.
263 *
264 * @var object
265 */
266 public $callBackObj;
267
268 // *********************
269 // Internal variables (mapping arrays) which can be used (read-only) from outside
270 // *********************
271 /**
272 * Contains mapping of auto-versionized records.
273 *
274 * @var array
275 */
276 public $autoVersionIdMap = array();
277
278 /**
279 * When new elements are created, this array contains a map between their "NEW..." string IDs and the eventual UID they got when stored in database
280 *
281 * @var array
282 */
283 public $substNEWwithIDs = array();
284
285 /**
286 * Like $substNEWwithIDs, but where each old "NEW..." id is mapped to the table it was from.
287 *
288 * @var array
289 */
290 public $substNEWwithIDs_table = array();
291
292 /**
293 * Holds the tables and there the ids of newly created child records from IRRE
294 *
295 * @var array
296 */
297 public $newRelatedIDs = array();
298
299 /**
300 * This array is the sum of all copying operations in this class. May be READ from outside, thus partly public.
301 *
302 * @var array
303 */
304 public $copyMappingArray_merged = array();
305
306 /**
307 * A map between input file name and final destination for files being attached to records.
308 *
309 * @var array
310 */
311 public $copiedFileMap = array();
312
313 /**
314 * Contains [table][id][field] of fiels where RTEmagic images was copied. Holds old filename as key and new filename as value.
315 *
316 * @var array
317 */
318 public $RTEmagic_copyIndex = array();
319
320 /**
321 * Errors are collected in this variable.
322 *
323 * @var array
324 */
325 public $errorLog = array();
326
327 /**
328 * Fields from the pages-table for which changes will trigger a pagetree refresh
329 *
330 * @var array
331 */
332 public $pagetreeRefreshFieldsFromPages = array('pid', 'sorting', 'deleted', 'hidden', 'title', 'doktype', 'is_siteroot', 'fe_group', 'nav_hide', 'nav_title', 'module', 'starttime', 'endtime', 'content_from_pid');
333
334 /**
335 * Indicates whether the pagetree needs a refresh because of important changes
336 *
337 * @var bool
338 */
339 public $pagetreeNeedsRefresh = FALSE;
340
341
342 // *********************
343 // Internal Variables, do not touch.
344 // *********************
345
346 // Variables set in init() function:
347
348 /**
349 * The user-object the script uses. If not set from outside, this is set to the current global $BE_USER.
350 *
351 * @var BackendUserAuthentication
352 */
353 public $BE_USER;
354
355 /**
356 * Will be set to uid of be_user executing this script
357 *
358 * @var int
359 */
360 public $userid;
361
362 /**
363 * Will be set to username of be_user executing this script
364 *
365 * @var string
366 */
367 public $username;
368
369 /**
370 * Will be set if user is admin
371 *
372 * @var bool
373 */
374 public $admin;
375
376 /**
377 * Can be overridden from $GLOBALS['TYPO3_CONF_VARS']
378 *
379 * @var array
380 */
381 public $defaultPermissions = array(
382 'user' => 'show,edit,delete,new,editcontent',
383 'group' => 'show,edit,new,editcontent',
384 'everybody' => ''
385 );
386
387 /**
388 * The list of <table>-<fields> that cannot be edited by user. This is compiled from TCA/exclude-flag combined with non_exclude_fields for the user.
389 *
390 * @var array
391 */
392 protected $excludedTablesAndFields = array();
393
394 /**
395 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
396 * @var int
397 */
398 public $include_filefunctions;
399
400 /**
401 * Data submitted from the form view, used to control behaviours,
402 * e.g. this is used to activate/deactivate fields and thus store NULL values
403 *
404 * @var array
405 */
406 protected $control = array();
407
408 /**
409 * Set with incoming data array
410 *
411 * @var array
412 */
413 public $datamap = array();
414
415 /**
416 * Set with incoming cmd array
417 *
418 * @var array
419 */
420 public $cmdmap = array();
421
422 // Internal static:
423 /**
424 * Permission mapping
425 *
426 * @var array
427 */
428 public $pMap = array(
429 'show' => 1,
430 // 1st bit
431 'edit' => 2,
432 // 2nd bit
433 'delete' => 4,
434 // 3rd bit
435 'new' => 8,
436 // 4th bit
437 'editcontent' => 16
438 );
439
440 /**
441 * Integer: The interval between sorting numbers used with tables with a 'sorting' field defined. Min 1
442 *
443 * @var int
444 */
445 public $sortIntervals = 256;
446
447 // Internal caching arrays
448 /**
449 * Used by function checkRecordUpdateAccess() to store whether a record is updatable or not.
450 *
451 * @var array
452 */
453 public $recUpdateAccessCache = array();
454
455 /**
456 * User by function checkRecordInsertAccess() to store whether a record can be inserted on a page id
457 *
458 * @var array
459 */
460 public $recInsertAccessCache = array();
461
462 /**
463 * Caching array for check of whether records are in a webmount
464 *
465 * @var array
466 */
467 public $isRecordInWebMount_Cache = array();
468
469 /**
470 * Caching array for page ids in webmounts
471 *
472 * @var array
473 */
474 public $isInWebMount_Cache = array();
475
476 /**
477 * Caching for collecting TSconfig for page ids
478 *
479 * @var array
480 */
481 public $cachedTSconfig = array();
482
483 /**
484 * Used for caching page records in pageInfo()
485 *
486 * @var array
487 */
488 public $pageCache = array();
489
490 /**
491 * Array caching workspace access for BE_USER
492 *
493 * @var array
494 */
495 public $checkWorkspaceCache = array();
496
497 // Other arrays:
498 /**
499 * For accumulation of MM relations that must be written after new records are created.
500 *
501 * @var array
502 */
503 public $dbAnalysisStore = array();
504
505 /**
506 * For accumulation of files which must be deleted after processing of all input content
507 *
508 * @var array
509 */
510 public $removeFilesStore = array();
511
512 /**
513 * Uploaded files, set by process_uploads()
514 *
515 * @var array
516 */
517 public $uploadedFileArray = array();
518
519 /**
520 * Used for tracking references that might need correction after operations
521 *
522 * @var array
523 */
524 public $registerDBList = array();
525
526 /**
527 * Used for tracking references that might need correction in pid field after operations (e.g. IRRE)
528 *
529 * @var array
530 */
531 public $registerDBPids = array();
532
533 /**
534 * Used by the copy action to track the ids of new pages so subpages are correctly inserted!
535 * THIS is internally cleared for each executed copy operation! DO NOT USE THIS FROM OUTSIDE!
536 * Read from copyMappingArray_merged instead which is accumulating this information.
537 *
538 * NOTE: This is used by some outside scripts (e.g. hooks), as the results in $copyMappingArray_merged
539 * are only available after an action has been completed.
540 *
541 * @var array
542 */
543 public $copyMappingArray = array();
544
545 /**
546 * Array used for remapping uids and values at the end of process_datamap
547 *
548 * @var array
549 */
550 public $remapStack = array();
551
552 /**
553 * Array used for remapping uids and values at the end of process_datamap
554 * (e.g. $remapStackRecords[<table>][<uid>] = <index in $remapStack>)
555 *
556 * @var array
557 */
558 public $remapStackRecords = array();
559
560 /**
561 * Array used for checking whether new children need to be remapped
562 *
563 * @var array
564 */
565 protected $remapStackChildIds = array();
566
567 /**
568 * Array used for executing addition actions after remapping happened (set processRemapStack())
569 *
570 * @var array
571 */
572 protected $remapStackActions = array();
573
574 /**
575 * Array used for executing post-processing on the reference index
576 *
577 * @var array
578 */
579 protected $remapStackRefIndex = array();
580
581 /**
582 * Array used for additional calls to $this->updateRefIndex
583 *
584 * @var array
585 */
586 public $updateRefIndexStack = array();
587
588 /**
589 * Tells, that this DataHandler instance was called from \TYPO3\CMS\Impext\ImportExport.
590 * This variable is set by \TYPO3\CMS\Impext\ImportExport
591 *
592 * @var array
593 */
594 public $callFromImpExp = FALSE;
595
596 /**
597 * Array for new flexform index mapping
598 *
599 * @var array
600 */
601 public $newIndexMap = array();
602
603 // Various
604 /**
605 * basicFileFunctions object
606 * For "singleton" file-manipulation object
607 *
608 * @var BasicFileUtility
609 */
610 public $fileFunc;
611
612 /**
613 * Set to "currentRecord" during checking of values.
614 *
615 * @var array
616 */
617 public $checkValue_currentRecord = array();
618
619 /**
620 * A signal flag used to tell file processing that auto versioning has happened and hence certain action should be applied.
621 *
622 * @var bool
623 */
624 public $autoVersioningUpdate = FALSE;
625
626 /**
627 * Disable delete clause
628 *
629 * @var bool
630 */
631 protected $disableDeleteClause = FALSE;
632
633 /**
634 * @var array
635 */
636 protected $checkModifyAccessListHookObjects;
637
638 /**
639 * @var array
640 */
641 protected $version_remapMMForVersionSwap_reg;
642
643 /**
644 * The outer most instance of \TYPO3\CMS\Core\DataHandling\DataHandler:
645 * This object instantiates itself on versioning and localization ...
646 *
647 * @var \TYPO3\CMS\Core\DataHandling\DataHandler
648 */
649 protected $outerMostInstance = NULL;
650
651 /**
652 * Internal cache for collecting records that should trigger cache clearing
653 *
654 * @var array
655 */
656 static protected $recordsToClearCacheFor = array();
657
658 /**
659 * Database layer. Identical to $GLOBALS['TYPO3_DB']
660 *
661 * @var DatabaseConnection
662 */
663 protected $databaseConnection;
664
665 /**
666 * Runtime Cache to store and retrieve data computed for a single request
667 *
668 * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
669 */
670 protected $runtimeCache = NULL;
671
672 /**
673 * Prefix for the cache entries of nested element calls since the runtimeCache has a global scope.
674 *
675 * @var string
676 */
677 protected $cachePrefixNestedElementCalls = 'core-datahandler-nestedElementCalls-';
678
679 /**
680 *
681 */
682 public function __construct() {
683 $this->databaseConnection = $GLOBALS['TYPO3_DB'];
684 $this->runtimeCache = $this->getRuntimeCache();
685 }
686
687 /**
688 * @param array $control
689 */
690 public function setControl(array $control) {
691 $this->control = $control;
692 }
693
694 /**
695 * Initializing.
696 * For details, see 'TYPO3 Core API' document.
697 * This function does not start the processing of data, but merely initializes the object
698 *
699 * @param array $data Data to be modified or inserted in the database
700 * @param array $cmd Commands to copy, move, delete, localize, versionize records.
701 * @param BackendUserAuthentication|NULL $altUserObject An alternative userobject you can set instead of the default, which is $GLOBALS['BE_USER']
702 * @return void
703 */
704 public function start($data, $cmd, $altUserObject = NULL) {
705 // Initializing BE_USER
706 $this->BE_USER = is_object($altUserObject) ? $altUserObject : $GLOBALS['BE_USER'];
707 $this->userid = $this->BE_USER->user['uid'];
708 $this->username = $this->BE_USER->user['username'];
709 $this->admin = $this->BE_USER->user['admin'];
710 if ($this->BE_USER->uc['recursiveDelete']) {
711 $this->deleteTree = 1;
712 }
713 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['explicitConfirmationOfTranslation'] && $this->updateModeL10NdiffData === TRUE) {
714 $this->updateModeL10NdiffData = FALSE;
715 }
716 // Initializing default permissions for pages
717 $defaultPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPermissions'];
718 if (isset($defaultPermissions['user'])) {
719 $this->defaultPermissions['user'] = $defaultPermissions['user'];
720 }
721 if (isset($defaultPermissions['group'])) {
722 $this->defaultPermissions['group'] = $defaultPermissions['group'];
723 }
724 if (isset($defaultPermissions['everybody'])) {
725 $this->defaultPermissions['everybody'] = $defaultPermissions['everybody'];
726 }
727 // generates the excludelist, based on TCA/exclude-flag and non_exclude_fields for the user:
728 if (!$this->admin) {
729 $this->excludedTablesAndFields = array_flip($this->getExcludeListArray());
730 }
731 // Setting the data and cmd arrays
732 if (is_array($data)) {
733 reset($data);
734 $this->datamap = $data;
735 }
736 if (is_array($cmd)) {
737 reset($cmd);
738 $this->cmdmap = $cmd;
739 }
740 }
741
742 /**
743 * Function that can mirror input values in datamap-array to other uid numbers.
744 * Example: $mirror[table][11] = '22,33' will look for content in $this->datamap[table][11] and copy it to $this->datamap[table][22] and $this->datamap[table][33]
745 *
746 * @param array $mirror This array has the syntax $mirror[table_name][uid] = [list of uids to copy data-value TO!]
747 * @return void
748 */
749 public function setMirror($mirror) {
750 if (is_array($mirror)) {
751 foreach ($mirror as $table => $uid_array) {
752 if (isset($this->datamap[$table])) {
753 foreach ($uid_array as $id => $uidList) {
754 if (isset($this->datamap[$table][$id])) {
755 $theIdsInArray = GeneralUtility::trimExplode(',', $uidList, TRUE);
756 foreach ($theIdsInArray as $copyToUid) {
757 $this->datamap[$table][$copyToUid] = $this->datamap[$table][$id];
758 }
759 }
760 }
761 }
762 }
763 }
764 }
765
766 /**
767 * Initializes default values coming from User TSconfig
768 *
769 * @param array $userTS User TSconfig array
770 * @return void
771 */
772 public function setDefaultsFromUserTS($userTS) {
773 if (is_array($userTS)) {
774 foreach ($userTS as $k => $v) {
775 $k = substr($k, 0, -1);
776 if ($k && is_array($v) && isset($GLOBALS['TCA'][$k])) {
777 if (is_array($this->defaultValues[$k])) {
778 $this->defaultValues[$k] = array_merge($this->defaultValues[$k], $v);
779 } else {
780 $this->defaultValues[$k] = $v;
781 }
782 }
783 }
784 }
785 }
786
787 /**
788 * Processing of uploaded files.
789 * It turns out that some versions of PHP arranges submitted data for files different if sent in an array. This function will unify this so the internal array $this->uploadedFileArray will always contain files arranged in the same structure.
790 *
791 * @param array $postFiles $_FILES array
792 * @return void
793 */
794 public function process_uploads($postFiles) {
795 if (is_array($postFiles)) {
796 // Editing frozen:
797 if ($this->BE_USER->workspace !== 0 && $this->BE_USER->workspaceRec['freeze']) {
798 if ($this->enableLogging) {
799 $this->newlog('All editing in this workspace has been frozen!', 1);
800 }
801 return FALSE;
802 }
803 $subA = reset($postFiles);
804 if (is_array($subA)) {
805 if (is_array($subA['name']) && is_array($subA['type']) && is_array($subA['tmp_name']) && is_array($subA['size'])) {
806 // Initialize the uploadedFilesArray:
807 $this->uploadedFileArray = array();
808 // For each entry:
809 foreach ($subA as $key => $values) {
810 $this->process_uploads_traverseArray($this->uploadedFileArray, $values, $key);
811 }
812 } else {
813 $this->uploadedFileArray = $subA;
814 }
815 }
816 }
817 }
818
819 /**
820 * Traverse the upload array if needed to rearrange values.
821 *
822 * @param array $outputArr $this->uploadedFileArray passed by reference
823 * @param array $inputArr Input array ($_FILES parts)
824 * @param string $keyToSet The current $_FILES array key to set on the outermost level.
825 * @return void
826 * @access private
827 * @see process_uploads()
828 */
829 public function process_uploads_traverseArray(&$outputArr, $inputArr, $keyToSet) {
830 if (is_array($inputArr)) {
831 foreach ($inputArr as $key => $value) {
832 $this->process_uploads_traverseArray($outputArr[$key], $inputArr[$key], $keyToSet);
833 }
834 } else {
835 $outputArr[$keyToSet] = $inputArr;
836 }
837 }
838
839 /*********************************************
840 *
841 * HOOKS
842 *
843 *********************************************/
844 /**
845 * Hook: processDatamap_afterDatabaseOperations
846 * (calls $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);)
847 *
848 * Note: When using the hook after INSERT operations, you will only get the temporary NEW... id passed to your hook as $id,
849 * but you can easily translate it to the real uid of the inserted record using the $this->substNEWwithIDs array.
850 *
851 * @param array $hookObjectsArr (reference) Array with hook objects
852 * @param string $status (reference) Status of the current operation, 'new' or 'update
853 * @param string $table (reference) The table currently processing data for
854 * @param string $id (reference) The record uid currently processing data for, [integer] or [string] (like 'NEW...')
855 * @param array $fieldArray (reference) The field array of a record
856 * @return void
857 */
858 public function hook_processDatamap_afterDatabaseOperations(&$hookObjectsArr, &$status, &$table, &$id, &$fieldArray) {
859 // Process hook directly:
860 if (!isset($this->remapStackRecords[$table][$id])) {
861 foreach ($hookObjectsArr as $hookObj) {
862 if (method_exists($hookObj, 'processDatamap_afterDatabaseOperations')) {
863 $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);
864 }
865 }
866 } else {
867 $this->remapStackRecords[$table][$id]['processDatamap_afterDatabaseOperations'] = array(
868 'status' => $status,
869 'fieldArray' => $fieldArray,
870 'hookObjectsArr' => $hookObjectsArr
871 );
872 }
873 }
874
875 /**
876 * Gets the 'checkModifyAccessList' hook objects.
877 * The first call initializes the accordant objects.
878 *
879 * @return array The 'checkModifyAccessList' hook objects (if any)
880 */
881 protected function getCheckModifyAccessListHookObjects() {
882 if (!isset($this->checkModifyAccessListHookObjects)) {
883 $this->checkModifyAccessListHookObjects = array();
884 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'])) {
885 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'] as $classData) {
886 $hookObject = GeneralUtility::getUserObj($classData);
887 if (!$hookObject instanceof DataHandlerCheckModifyAccessListHookInterface) {
888 throw new \UnexpectedValueException('$hookObject must implement interface \\TYPO3\\CMS\\Core\\DataHandling\\DataHandlerCheckModifyAccessListHookInterface', 1251892472);
889 }
890 $this->checkModifyAccessListHookObjects[] = $hookObject;
891 }
892 }
893 }
894 return $this->checkModifyAccessListHookObjects;
895 }
896
897 /*********************************************
898 *
899 * PROCESSING DATA
900 *
901 *********************************************/
902 /**
903 * Processing the data-array
904 * Call this function to process the data-array set by start()
905 *
906 * @return void|FALSE
907 */
908 public function process_datamap() {
909 $this->controlActiveElements();
910
911 // Keep versionized(!) relations here locally:
912 $registerDBList = array();
913 $this->registerElementsToBeDeleted();
914 $this->datamap = $this->unsetElementsToBeDeleted($this->datamap);
915 // Editing frozen:
916 if ($this->BE_USER->workspace !== 0 && $this->BE_USER->workspaceRec['freeze']) {
917 if ($this->enableLogging) {
918 $this->newlog('All editing in this workspace has been frozen!', 1);
919 }
920 return FALSE;
921 }
922 // First prepare user defined objects (if any) for hooks which extend this function:
923 $hookObjectsArr = array();
924 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'])) {
925 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'] as $classRef) {
926 $hookObject = GeneralUtility::getUserObj($classRef);
927 if (method_exists($hookObject, 'processDatamap_beforeStart')) {
928 $hookObject->processDatamap_beforeStart($this);
929 }
930 $hookObjectsArr[] = $hookObject;
931 }
932 }
933 // Organize tables so that the pages-table is always processed first. This is required if you want to make sure that content pointing to a new page will be created.
934 $orderOfTables = array();
935 // Set pages first.
936 if (isset($this->datamap['pages'])) {
937 $orderOfTables[] = 'pages';
938 }
939 $orderOfTables = array_unique(array_merge($orderOfTables, array_keys($this->datamap)));
940 // Process the tables...
941 foreach ($orderOfTables as $table) {
942 // Check if
943 // - table is set in $GLOBALS['TCA'],
944 // - table is NOT readOnly
945 // - the table is set with content in the data-array (if not, there's nothing to process...)
946 // - permissions for tableaccess OK
947 $modifyAccessList = $this->checkModifyAccessList($table);
948 if ($this->enableLogging && !$modifyAccessList) {
949 $this->log($table, 0, 2, 0, 1, 'Attempt to modify table \'%s\' without permission', 1, array($table));
950 }
951 if (isset($GLOBALS['TCA'][$table]) && !$this->tableReadOnly($table) && is_array($this->datamap[$table]) && $modifyAccessList) {
952 if ($this->reverseOrder) {
953 $this->datamap[$table] = array_reverse($this->datamap[$table], 1);
954 }
955 // For each record from the table, do:
956 // $id is the record uid, may be a string if new records...
957 // $incomingFieldArray is the array of fields
958 foreach ($this->datamap[$table] as $id => $incomingFieldArray) {
959 if (is_array($incomingFieldArray)) {
960 // Handle native date/time fields
961 $dateTimeFormats = $this->databaseConnection->getDateTimeFormats($table);
962 foreach ($GLOBALS['TCA'][$table]['columns'] as $column => $config) {
963 if (isset($incomingFieldArray[$column])) {
964 if (isset($config['config']['dbType']) && ($config['config']['dbType'] === 'date' || $config['config']['dbType'] === 'datetime')) {
965 $emptyValue = $dateTimeFormats[$config['config']['dbType']]['empty'];
966 $format = $dateTimeFormats[$config['config']['dbType']]['format'];
967 $incomingFieldArray[$column] = $incomingFieldArray[$column] ? gmdate($format, $incomingFieldArray[$column]) : $emptyValue;
968 }
969 }
970 }
971 // Hook: processDatamap_preProcessFieldArray
972 foreach ($hookObjectsArr as $hookObj) {
973 if (method_exists($hookObj, 'processDatamap_preProcessFieldArray')) {
974 $hookObj->processDatamap_preProcessFieldArray($incomingFieldArray, $table, $id, $this);
975 }
976 }
977 // ******************************
978 // Checking access to the record
979 // ******************************
980 $createNewVersion = FALSE;
981 $recordAccess = FALSE;
982 $old_pid_value = '';
983 $this->autoVersioningUpdate = FALSE;
984 // Is it a new record? (Then Id is a string)
985 if (!MathUtility::canBeInterpretedAsInteger($id)) {
986 // Get a fieldArray with default values
987 $fieldArray = $this->newFieldArray($table);
988 // A pid must be set for new records.
989 if (isset($incomingFieldArray['pid'])) {
990 // $value = the pid
991 $pid_value = $incomingFieldArray['pid'];
992 // Checking and finding numerical pid, it may be a string-reference to another value
993 $OK = 1;
994 // If a NEW... id
995 if (strstr($pid_value, 'NEW')) {
996 if ($pid_value[0] === '-') {
997 $negFlag = -1;
998 $pid_value = substr($pid_value, 1);
999 } else {
1000 $negFlag = 1;
1001 }
1002 // Trying to find the correct numerical value as it should be mapped by earlier processing of another new record.
1003 if (isset($this->substNEWwithIDs[$pid_value])) {
1004 if ($negFlag === 1) {
1005 $old_pid_value = $this->substNEWwithIDs[$pid_value];
1006 }
1007 $pid_value = (int)($negFlag * $this->substNEWwithIDs[$pid_value]);
1008 } else {
1009 $OK = 0;
1010 }
1011 }
1012 $pid_value = (int)$pid_value;
1013 // The $pid_value is now the numerical pid at this point
1014 if ($OK) {
1015 $sortRow = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
1016 // Points to a page on which to insert the element, possibly in the top of the page
1017 if ($pid_value >= 0) {
1018 // If this table is sorted we better find the top sorting number
1019 if ($sortRow) {
1020 $fieldArray[$sortRow] = $this->getSortNumber($table, 0, $pid_value);
1021 }
1022 // The numerical pid is inserted in the data array
1023 $fieldArray['pid'] = $pid_value;
1024 } else {
1025 // points to another record before ifself
1026 // If this table is sorted we better find the top sorting number
1027 if ($sortRow) {
1028 // Because $pid_value is < 0, getSortNumber returns an array
1029 $tempArray = $this->getSortNumber($table, 0, $pid_value);
1030 $fieldArray['pid'] = $tempArray['pid'];
1031 $fieldArray[$sortRow] = $tempArray['sortNumber'];
1032 } else {
1033 // Here we fetch the PID of the record that we point to...
1034 $tempdata = $this->recordInfo($table, abs($pid_value), 'pid');
1035 $fieldArray['pid'] = $tempdata['pid'];
1036 }
1037 }
1038 }
1039 }
1040 $theRealPid = $fieldArray['pid'];
1041 // Now, check if we may insert records on this pid.
1042 if ($theRealPid >= 0) {
1043 // Checks if records can be inserted on this $pid.
1044 $recordAccess = $this->checkRecordInsertAccess($table, $theRealPid);
1045 if ($recordAccess) {
1046 $this->addDefaultPermittedLanguageIfNotSet($table, $incomingFieldArray);
1047 $recordAccess = $this->BE_USER->recordEditAccessInternals($table, $incomingFieldArray, TRUE);
1048 if (!$recordAccess) {
1049 if ($this->enableLogging) {
1050 $this->newlog('recordEditAccessInternals() check failed. [' . $this->BE_USER->errorMsg . ']', 1);
1051 }
1052 } elseif (!$this->bypassWorkspaceRestrictions) {
1053 // Workspace related processing:
1054 // If LIVE records cannot be created in the current PID due to workspace restrictions, prepare creation of placeholder-record
1055 if ($res = $this->BE_USER->workspaceAllowLiveRecordsInPID($theRealPid, $table)) {
1056 if ($res < 0) {
1057 $recordAccess = FALSE;
1058 if ($this->enableLogging) {
1059 $this->newlog('Stage for versioning root point and users access level did not allow for editing', 1);
1060 }
1061 }
1062 } else {
1063 // So, if no live records were allowed, we have to create a new version of this record:
1064 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
1065 $createNewVersion = TRUE;
1066 } else {
1067 $recordAccess = FALSE;
1068 if ($this->enableLogging) {
1069 $this->newlog('Record could not be created in this workspace in this branch', 1);
1070 }
1071 }
1072 }
1073 }
1074 }
1075 } else {
1076 debug('Internal ERROR: pid should not be less than zero!');
1077 }
1078 // Yes new record, change $record_status to 'insert'
1079 $status = 'new';
1080 } else {
1081 // Nope... $id is a number
1082 $fieldArray = array();
1083 $recordAccess = $this->checkRecordUpdateAccess($table, $id, $incomingFieldArray, $hookObjectsArr);
1084 if (!$recordAccess) {
1085 if ($this->enableLogging) {
1086 $propArr = $this->getRecordProperties($table, $id);
1087 $this->log($table, $id, 2, 0, 1, 'Attempt to modify record \'%s\' (%s) without permission. Or non-existing page.', 2, array($propArr['header'], $table . ':' . $id), $propArr['event_pid']);
1088 }
1089 } else {
1090 // Next check of the record permissions (internals)
1091 $recordAccess = $this->BE_USER->recordEditAccessInternals($table, $id);
1092 if (!$recordAccess) {
1093 if ($this->enableLogging) {
1094 $this->newlog('recordEditAccessInternals() check failed. [' . $this->BE_USER->errorMsg . ']', 1);
1095 }
1096 } else {
1097 // Here we fetch the PID of the record that we point to...
1098 $tempdata = $this->recordInfo($table, $id, 'pid' . ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'] ? ',t3ver_wsid,t3ver_stage' : ''));
1099 $theRealPid = $tempdata['pid'];
1100 // Use the new id of the versionized record we're trying to write to:
1101 // (This record is a child record of a parent and has already been versionized.)
1102 if ($this->autoVersionIdMap[$table][$id]) {
1103 // For the reason that creating a new version of this record, automatically
1104 // created related child records (e.g. "IRRE"), update the accordant field:
1105 $this->getVersionizedIncomingFieldArray($table, $id, $incomingFieldArray, $registerDBList);
1106 // Use the new id of the copied/versionized record:
1107 $id = $this->autoVersionIdMap[$table][$id];
1108 $recordAccess = TRUE;
1109 $this->autoVersioningUpdate = TRUE;
1110 } elseif (!$this->bypassWorkspaceRestrictions && ($errorCode = $this->BE_USER->workspaceCannotEditRecord($table, $tempdata))) {
1111 $recordAccess = FALSE;
1112 // Versioning is required and it must be offline version!
1113 // Check if there already is a workspace version
1114 $WSversion = BackendUtility::getWorkspaceVersionOfRecord($this->BE_USER->workspace, $table, $id, 'uid,t3ver_oid');
1115 if ($WSversion) {
1116 $id = $WSversion['uid'];
1117 $recordAccess = TRUE;
1118 } elseif ($this->BE_USER->workspaceAllowAutoCreation($table, $id, $theRealPid)) {
1119 // new version of a record created in a workspace - so always refresh pagetree to indicate there is a change in the workspace
1120 $this->pagetreeNeedsRefresh = TRUE;
1121
1122 /** @var $tce DataHandler */
1123 $tce = GeneralUtility::makeInstance(self::class);
1124 $tce->stripslashes_values = 0;
1125 // Setting up command for creating a new version of the record:
1126 $cmd = array();
1127 $cmd[$table][$id]['version'] = array(
1128 'action' => 'new',
1129 'treeLevels' => -1,
1130 // Default is to create a version of the individual records... element versioning that is.
1131 'label' => 'Auto-created for WS #' . $this->BE_USER->workspace
1132 );
1133 $tce->start(array(), $cmd);
1134 $tce->process_cmdmap();
1135 $this->errorLog = array_merge($this->errorLog, $tce->errorLog);
1136 // If copying was successful, share the new uids (also of related children):
1137 if ($tce->copyMappingArray[$table][$id]) {
1138 foreach ($tce->copyMappingArray as $origTable => $origIdArray) {
1139 foreach ($origIdArray as $origId => $newId) {
1140 $this->uploadedFileArray[$origTable][$newId] = $this->uploadedFileArray[$origTable][$origId];
1141 $this->autoVersionIdMap[$origTable][$origId] = $newId;
1142 }
1143 }
1144 ArrayUtility::mergeRecursiveWithOverrule($this->RTEmagic_copyIndex, $tce->RTEmagic_copyIndex);
1145 // See where RTEmagic_copyIndex is used inside fillInFieldArray() for more information...
1146 // Update registerDBList, that holds the copied relations to child records:
1147 $registerDBList = array_merge($registerDBList, $tce->registerDBList);
1148 // For the reason that creating a new version of this record, automatically
1149 // created related child records (e.g. "IRRE"), update the accordant field:
1150 $this->getVersionizedIncomingFieldArray($table, $id, $incomingFieldArray, $registerDBList);
1151 // Use the new id of the copied/versionized record:
1152 $id = $this->autoVersionIdMap[$table][$id];
1153 $recordAccess = TRUE;
1154 $this->autoVersioningUpdate = TRUE;
1155 } elseif ($this->enableLogging) {
1156 $this->newlog('Could not be edited in offline workspace in the branch where found (failure state: \'' . $errorCode . '\'). Auto-creation of version failed!', 1);
1157 }
1158 } elseif ($this->enableLogging) {
1159 $this->newlog('Could not be edited in offline workspace in the branch where found (failure state: \'' . $errorCode . '\'). Auto-creation of version not allowed in workspace!', 1);
1160 }
1161 }
1162 }
1163 }
1164 // The default is 'update'
1165 $status = 'update';
1166 }
1167 // If access was granted above, proceed to create or update record:
1168 if ($recordAccess) {
1169 // Here the "pid" is set IF NOT the old pid was a string pointing to a place in the subst-id array.
1170 list($tscPID) = BackendUtility::getTSCpid($table, $id, $old_pid_value ? $old_pid_value : $fieldArray['pid']);
1171 if ($status === 'new' && $table === 'pages') {
1172 $TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
1173 if (isset($TSConfig['permissions.']) && is_array($TSConfig['permissions.'])) {
1174 $fieldArray = $this->setTSconfigPermissions($fieldArray, $TSConfig['permissions.']);
1175 }
1176 }
1177 // Processing of all fields in incomingFieldArray and setting them in $fieldArray
1178 $fieldArray = $this->fillInFieldArray($table, $id, $fieldArray, $incomingFieldArray, $theRealPid, $status, $tscPID);
1179 if ($createNewVersion) {
1180 // create a placeholder array with already processed field content
1181 $newVersion_placeholderFieldArray = $fieldArray;
1182 }
1183 // NOTICE! All manipulation beyond this point bypasses both "excludeFields" AND possible "MM" relations / file uploads to field!
1184 // Forcing some values unto field array:
1185 // NOTICE: This overriding is potentially dangerous; permissions per field is not checked!!!
1186 $fieldArray = $this->overrideFieldArray($table, $fieldArray);
1187 if ($createNewVersion) {
1188 $newVersion_placeholderFieldArray = $this->overrideFieldArray($table, $newVersion_placeholderFieldArray);
1189 }
1190 // Setting system fields
1191 if ($status == 'new') {
1192 if ($GLOBALS['TCA'][$table]['ctrl']['crdate']) {
1193 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME'];
1194 if ($createNewVersion) {
1195 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME'];
1196 }
1197 }
1198 if ($GLOBALS['TCA'][$table]['ctrl']['cruser_id']) {
1199 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']] = $this->userid;
1200 if ($createNewVersion) {
1201 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']] = $this->userid;
1202 }
1203 }
1204 } elseif ($this->checkSimilar) {
1205 // Removing fields which are equal to the current value:
1206 $fieldArray = $this->compareFieldArrayWithCurrentAndUnset($table, $id, $fieldArray);
1207 }
1208 if ($GLOBALS['TCA'][$table]['ctrl']['tstamp'] && count($fieldArray)) {
1209 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
1210 if ($createNewVersion) {
1211 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
1212 }
1213 }
1214 // Set stage to "Editing" to make sure we restart the workflow
1215 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
1216 $fieldArray['t3ver_stage'] = 0;
1217 }
1218 // Hook: processDatamap_postProcessFieldArray
1219 foreach ($hookObjectsArr as $hookObj) {
1220 if (method_exists($hookObj, 'processDatamap_postProcessFieldArray')) {
1221 $hookObj->processDatamap_postProcessFieldArray($status, $table, $id, $fieldArray, $this);
1222 }
1223 }
1224 // Performing insert/update. If fieldArray has been unset by some userfunction (see hook above), don't do anything
1225 // Kasper: Unsetting the fieldArray is dangerous; MM relations might be saved already and files could have been uploaded that are now "lost"
1226 if (is_array($fieldArray)) {
1227 if ($status == 'new') {
1228 if ($table === 'pages') {
1229 // for new pages always a refresh is needed
1230 $this->pagetreeNeedsRefresh = TRUE;
1231 }
1232
1233 // This creates a new version of the record with online placeholder and offline version
1234 if ($createNewVersion) {
1235 // new record created in a workspace - so always refresh pagetree to indicate there is a change in the workspace
1236 $this->pagetreeNeedsRefresh = TRUE;
1237
1238 $newVersion_placeholderFieldArray['t3ver_label'] = 'INITIAL PLACEHOLDER';
1239 // Setting placeholder state value for temporary record
1240 $newVersion_placeholderFieldArray['t3ver_state'] = (string)new VersionState(VersionState::NEW_PLACEHOLDER);
1241 // Setting workspace - only so display of place holders can filter out those from other workspaces.
1242 $newVersion_placeholderFieldArray['t3ver_wsid'] = $this->BE_USER->workspace;
1243 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['label']] = $this->getPlaceholderTitleForTableLabel($table);
1244 // Saving placeholder as 'original'
1245 $this->insertDB($table, $id, $newVersion_placeholderFieldArray, FALSE);
1246 // For the actual new offline version, set versioning values to point to placeholder:
1247 $fieldArray['pid'] = -1;
1248 $fieldArray['t3ver_oid'] = $this->substNEWwithIDs[$id];
1249 $fieldArray['t3ver_id'] = 1;
1250 // Setting placeholder state value for version (so it can know it is currently a new version...)
1251 $fieldArray['t3ver_state'] = (string)new VersionState(VersionState::NEW_PLACEHOLDER_VERSION);
1252 $fieldArray['t3ver_label'] = 'First draft version';
1253 $fieldArray['t3ver_wsid'] = $this->BE_USER->workspace;
1254 // When inserted, $this->substNEWwithIDs[$id] will be changed to the uid of THIS version and so the interface will pick it up just nice!
1255 $phShadowId = $this->insertDB($table, $id, $fieldArray, TRUE, 0, TRUE);
1256 if ($phShadowId) {
1257 // Processes fields of the placeholder record:
1258 $this->triggerRemapAction($table, $id, array($this, 'placeholderShadowing'), array($table, $phShadowId));
1259 // Hold auto-versionized ids of placeholders:
1260 $this->autoVersionIdMap[$table][$this->substNEWwithIDs[$id]] = $phShadowId;
1261 }
1262 } else {
1263 $this->insertDB($table, $id, $fieldArray, FALSE, $incomingFieldArray['uid']);
1264 }
1265 } else {
1266 if ($table === 'pages') {
1267 // only a certain number of fields needs to be checked for updates
1268 // if $this->checkSimilar is TRUE, fields with unchanged values are already removed here
1269 $fieldsToCheck = array_intersect($this->pagetreeRefreshFieldsFromPages, array_keys($fieldArray));
1270 if (count($fieldsToCheck)) {
1271 $this->pagetreeNeedsRefresh = TRUE;
1272 }
1273 }
1274 $this->updateDB($table, $id, $fieldArray);
1275 $this->placeholderShadowing($table, $id);
1276 }
1277 }
1278 // Hook: processDatamap_afterDatabaseOperations
1279 // Note: When using the hook after INSERT operations, you will only get the temporary NEW... id passed to your hook as $id,
1280 // but you can easily translate it to the real uid of the inserted record using the $this->substNEWwithIDs array.
1281 $this->hook_processDatamap_afterDatabaseOperations($hookObjectsArr, $status, $table, $id, $fieldArray);
1282 }
1283 }
1284 }
1285 }
1286 }
1287 // Process the stack of relations to remap/correct
1288 $this->processRemapStack();
1289 $this->dbAnalysisStoreExec();
1290 $this->removeRegisteredFiles();
1291 // Hook: processDatamap_afterAllOperations
1292 // Note: When this hook gets called, all operations on the submitted data have been finished.
1293 foreach ($hookObjectsArr as $hookObj) {
1294 if (method_exists($hookObj, 'processDatamap_afterAllOperations')) {
1295 $hookObj->processDatamap_afterAllOperations($this);
1296 }
1297 }
1298 if ($this->isOuterMostInstance()) {
1299 $this->processClearCacheQueue();
1300 $this->resetElementsToBeDeleted();
1301 }
1302 }
1303
1304 /**
1305 * Fix shadowing of data in case we are editing a offline version of a live "New" placeholder record:
1306 *
1307 * @param string $table Table name
1308 * @param int $id Record uid
1309 * @return void
1310 */
1311 public function placeholderShadowing($table, $id) {
1312 if ($liveRec = BackendUtility::getLiveVersionOfRecord($table, $id, '*')) {
1313 if (VersionState::cast($liveRec['t3ver_state'])->indicatesPlaceholder()) {
1314 $justStoredRecord = BackendUtility::getRecord($table, $id);
1315 $newRecord = array();
1316 $shadowCols = $GLOBALS['TCA'][$table]['ctrl']['shadowColumnsForNewPlaceholders'];
1317 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['languageField'];
1318 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
1319 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['type'];
1320 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['label'];
1321 $shadowColumns = array_unique(GeneralUtility::trimExplode(',', $shadowCols, TRUE));
1322 foreach ($shadowColumns as $fieldName) {
1323 if ((string)$justStoredRecord[$fieldName] !== (string)$liveRec[$fieldName] && isset($GLOBALS['TCA'][$table]['columns'][$fieldName]) && $fieldName !== 'uid' && $fieldName !== 'pid') {
1324 $newRecord[$fieldName] = $justStoredRecord[$fieldName];
1325 }
1326 }
1327 if (count($newRecord)) {
1328 if ($this->enableLogging) {
1329 $this->newlog2('Shadowing done on fields <i>' . implode(',', array_keys($newRecord)) . '</i> in placeholder record ' . $table . ':' . $liveRec['uid'] . ' (offline version UID=' . $id . ')', $table, $liveRec['uid'], $liveRec['pid']);
1330 }
1331 $this->updateDB($table, $liveRec['uid'], $newRecord);
1332 }
1333 }
1334 }
1335 }
1336
1337 /**
1338 * Create a placeholder title for the label field that does match the field requirements
1339 *
1340 * @param string $table The table name
1341 * @return string placeholder value
1342 */
1343 protected function getPlaceholderTitleForTableLabel($table) {
1344 $labelPlaceholder = '[PLACEHOLDER, WS#' . $this->BE_USER->workspace . ']';
1345 $labelField = $GLOBALS['TCA'][$table]['ctrl']['label'];
1346 if (!isset($GLOBALS['TCA'][$table]['columns'][$labelField]['config']['eval'])) {
1347 return $labelPlaceholder;
1348 }
1349 $evalCodesArray = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$labelField]['config']['eval'], TRUE);
1350 $transformedLabel = $this->checkValue_input_Eval($labelPlaceholder, $evalCodesArray, '');
1351 return isset($transformedLabel['value']) ? $transformedLabel['value'] : $labelPlaceholder;
1352 }
1353
1354 /**
1355 * Filling in the field array
1356 * $this->excludedTablesAndFields is used to filter fields if needed.
1357 *
1358 * @param string $table Table name
1359 * @param int $id Record ID
1360 * @param array $fieldArray Default values, Preset $fieldArray with 'pid' maybe (pid and uid will be not be overridden anyway)
1361 * @param array $incomingFieldArray Is which fields/values you want to set. There are processed and put into $fieldArray if OK
1362 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted.
1363 * @param string $status Is 'new' or 'update'
1364 * @param int $tscPID TSconfig PID
1365 * @return array Field Array
1366 */
1367 public function fillInFieldArray($table, $id, $fieldArray, $incomingFieldArray, $realPid, $status, $tscPID) {
1368 // Initialize:
1369 $originalLanguageRecord = NULL;
1370 $originalLanguage_diffStorage = NULL;
1371 $diffStorageFlag = FALSE;
1372 // Setting 'currentRecord' and 'checkValueRecord':
1373 if (strstr($id, 'NEW')) {
1374 // Must have the 'current' array - not the values after processing below...
1375 $currentRecord = ($checkValueRecord = $fieldArray);
1376 // IF $incomingFieldArray is an array, overlay it.
1377 // The point is that when new records are created as copies with flex type fields there might be a field containing information about which DataStructure to use and without that information the flexforms cannot be correctly processed.... This should be OK since the $checkValueRecord is used by the flexform evaluation only anyways...
1378 if (is_array($incomingFieldArray) && is_array($checkValueRecord)) {
1379 ArrayUtility::mergeRecursiveWithOverrule($checkValueRecord, $incomingFieldArray);
1380 }
1381 } else {
1382 // We must use the current values as basis for this!
1383 $currentRecord = ($checkValueRecord = $this->recordInfo($table, $id, '*'));
1384 // This is done to make the pid positive for offline versions; Necessary to have diff-view for pages_language_overlay in workspaces.
1385 BackendUtility::fixVersioningPid($table, $currentRecord);
1386 // Get original language record if available:
1387 if (is_array($currentRecord) && $GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField'] && $GLOBALS['TCA'][$table]['ctrl']['languageField'] && $currentRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0 && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] && (int)$currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] > 0) {
1388 $lookUpTable = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable'] ?: $table;
1389 $originalLanguageRecord = $this->recordInfo($lookUpTable, $currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']], '*');
1390 BackendUtility::workspaceOL($lookUpTable, $originalLanguageRecord);
1391 $originalLanguage_diffStorage = unserialize($currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']]);
1392 }
1393 }
1394 $this->checkValue_currentRecord = $checkValueRecord;
1395 // In the following all incoming value-fields are tested:
1396 // - Are the user allowed to change the field?
1397 // - Is the field uid/pid (which are already set)
1398 // - perms-fields for pages-table, then do special things...
1399 // - If the field is nothing of the above and the field is configured in TCA, the fieldvalues are evaluated by ->checkValue
1400 // If everything is OK, the field is entered into $fieldArray[]
1401 foreach ($incomingFieldArray as $field => $fieldValue) {
1402 if (!isset($this->excludedTablesAndFields[$table . '-' . $field]) && !$this->data_disableFields[$table][$id][$field]) {
1403 // The field must be editable.
1404 // Checking if a value for language can be changed:
1405 $languageDeny = $GLOBALS['TCA'][$table]['ctrl']['languageField'] && (string)$GLOBALS['TCA'][$table]['ctrl']['languageField'] === (string)$field && !$this->BE_USER->checkLanguageAccess($fieldValue);
1406 if (!$languageDeny) {
1407 // Stripping slashes - will probably be removed the day $this->stripslashes_values is removed as an option...
1408 // @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1409 if ($this->stripslashes_values) {
1410 GeneralUtility::deprecationLog(
1411 'The option stripslash_values is typically set to FALSE as data should be properly prepared before sending to DataHandler. Do not rely on DataHandler removing extra slashes. The option will be removed in TYPO3 CMS 8.'
1412 );
1413 if (is_array($fieldValue)) {
1414 GeneralUtility::stripSlashesOnArray($fieldValue);
1415 } else {
1416 $fieldValue = stripslashes($fieldValue);
1417 }
1418 }
1419 switch ($field) {
1420 case 'uid':
1421 case 'pid':
1422 // Nothing happens, already set
1423 break;
1424 case 'perms_userid':
1425 case 'perms_groupid':
1426 case 'perms_user':
1427 case 'perms_group':
1428 case 'perms_everybody':
1429 // Permissions can be edited by the owner or the administrator
1430 if ($table == 'pages' && ($this->admin || $status == 'new' || $this->pageInfo($id, 'perms_userid') == $this->userid)) {
1431 $value = (int)$fieldValue;
1432 switch ($field) {
1433 case 'perms_userid':
1434 $fieldArray[$field] = $value;
1435 break;
1436 case 'perms_groupid':
1437 $fieldArray[$field] = $value;
1438 break;
1439 default:
1440 if ($value >= 0 && $value < pow(2, 5)) {
1441 $fieldArray[$field] = $value;
1442 }
1443 }
1444 }
1445 break;
1446 case 't3ver_oid':
1447 case 't3ver_id':
1448 case 't3ver_wsid':
1449 case 't3ver_state':
1450 case 't3ver_count':
1451 case 't3ver_stage':
1452 case 't3ver_tstamp':
1453 // t3ver_label is not here because it CAN be edited as a regular field!
1454 break;
1455 default:
1456 if (isset($GLOBALS['TCA'][$table]['columns'][$field])) {
1457 // Evaluating the value
1458 $res = $this->checkValue($table, $field, $fieldValue, $id, $status, $realPid, $tscPID);
1459 if (array_key_exists('value', $res)) {
1460 $fieldArray[$field] = $res['value'];
1461 }
1462 // Add the value of the original record to the diff-storage content:
1463 if ($this->updateModeL10NdiffData && $GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']) {
1464 $originalLanguage_diffStorage[$field] = $this->updateModeL10NdiffDataClear ? '' : $originalLanguageRecord[$field];
1465 $diffStorageFlag = TRUE;
1466 }
1467 // If autoversioning is happening we need to perform a nasty hack. The case is parallel to a similar hack inside checkValue_group_select_file().
1468 // When a copy or version is made of a record, a search is made for any RTEmagic* images in fields having the "images" soft reference parser applied.
1469 // That should be TRUE for RTE fields. If any are found they are duplicated to new names and the file reference in the bodytext is updated accordingly.
1470 // However, with auto-versioning the submitted content of the field will just overwrite the corrected values. This leaves a) lost RTEmagic files and b) creates a double reference to the old files.
1471 // The only solution I can come up with is detecting when auto versioning happens, then see if any RTEmagic images was copied and if so make a stupid string-replace of the content !
1472 if ($this->autoVersioningUpdate === TRUE) {
1473 if (is_array($this->RTEmagic_copyIndex[$table][$id][$field])) {
1474 foreach ($this->RTEmagic_copyIndex[$table][$id][$field] as $oldRTEmagicName => $newRTEmagicName) {
1475 $fieldArray[$field] = str_replace(' src="' . $oldRTEmagicName . '"', ' src="' . $newRTEmagicName . '"', $fieldArray[$field]);
1476 }
1477 }
1478 }
1479 } elseif ($GLOBALS['TCA'][$table]['ctrl']['origUid'] === $field) {
1480 // Allow value for original UID to pass by...
1481 $fieldArray[$field] = $fieldValue;
1482 }
1483 }
1484 }
1485 }
1486 }
1487 // Add diff-storage information:
1488 if ($diffStorageFlag && !isset($fieldArray[$GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']])) {
1489 // If the field is set it would probably be because of an undo-operation - in which case we should not update the field of course...
1490 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']] = serialize($originalLanguage_diffStorage);
1491 }
1492 // Checking for RTE-transformations of fields:
1493 $types_fieldConfig = BackendUtility::getTCAtypes($table, $currentRecord);
1494 $theTypeString = NULL;
1495 if (is_array($types_fieldConfig)) {
1496 foreach ($types_fieldConfig as $vconf) {
1497 // RTE transformations:
1498 if (!$this->dontProcessTransformations) {
1499 if (isset($fieldArray[$vconf['field']])) {
1500 // Look for transformation flag:
1501 switch ((string)$incomingFieldArray[('_TRANSFORM_' . $vconf['field'])]) {
1502 case 'RTE':
1503 if ($theTypeString === NULL) {
1504 $theTypeString = BackendUtility::getTCAtypeValue($table, $currentRecord);
1505 }
1506 $RTEsetup = $this->BE_USER->getTSConfig('RTE', BackendUtility::getPagesTSconfig($tscPID));
1507 $thisConfig = BackendUtility::RTEsetup($RTEsetup['properties'], $table, $vconf['field'], $theTypeString);
1508 // Get RTE object, draw form and set flag:
1509 $RTEobj = BackendUtility::RTEgetObj();
1510 if (is_object($RTEobj)) {
1511 $fieldArray[$vconf['field']] = $RTEobj->transformContent('db', $fieldArray[$vconf['field']], $table, $vconf['field'], $currentRecord, $vconf['spec'], $thisConfig, '', $currentRecord['pid']);
1512 } else {
1513 debug('NO RTE OBJECT FOUND!');
1514 }
1515 break;
1516 }
1517 }
1518 }
1519 }
1520 }
1521 // Return fieldArray
1522 return $fieldArray;
1523 }
1524
1525 /*********************************************
1526 *
1527 * Evaluation of input values
1528 *
1529 ********************************************/
1530 /**
1531 * Evaluates a value according to $table/$field settings.
1532 * This function is for real database fields - NOT FlexForm "pseudo" fields.
1533 * NOTICE: Calling this function expects this: 1) That the data is saved! (files are copied and so on) 2) That files registered for deletion IS deleted at the end (with ->removeRegisteredFiles() )
1534 *
1535 * @param string $table Table name
1536 * @param string $field Field name
1537 * @param string $value Value to be evaluated. Notice, this is the INPUT value from the form. The original value (from any existing record) must be manually looked up inside the function if needed - or taken from $currentRecord array.
1538 * @param string $id The record-uid, mainly - but not exclusively - used for logging
1539 * @param string $status 'update' or 'new' flag
1540 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
1541 * @param int $tscPID TSconfig PID
1542 * @return array Returns the evaluated $value as key "value" in this array. Can be checked with isset($res['value']) ...
1543 */
1544 public function checkValue($table, $field, $value, $id, $status, $realPid, $tscPID) {
1545 // Result array
1546 $res = array();
1547
1548 // Processing special case of field pages.doktype
1549 if (($table === 'pages' || $table === 'pages_language_overlay') && $field === 'doktype') {
1550 // If the user may not use this specific doktype, we issue a warning
1551 if (!($this->admin || GeneralUtility::inList($this->BE_USER->groupData['pagetypes_select'], $value))) {
1552 if ($this->enableLogging) {
1553 $propArr = $this->getRecordProperties($table, $id);
1554 $this->log($table, $id, 5, 0, 1, 'You cannot change the \'doktype\' of page \'%s\' to the desired value.', 1, array($propArr['header']), $propArr['event_pid']);
1555 }
1556 return $res;
1557 }
1558 if ($status == 'update') {
1559 // This checks 1) if we should check for disallowed tables and 2) if there are records from disallowed tables on the current page
1560 $onlyAllowedTables = isset($GLOBALS['PAGES_TYPES'][$value]['onlyAllowedTables']) ? $GLOBALS['PAGES_TYPES'][$value]['onlyAllowedTables'] : $GLOBALS['PAGES_TYPES']['default']['onlyAllowedTables'];
1561 if ($onlyAllowedTables) {
1562 $theWrongTables = $this->doesPageHaveUnallowedTables($id, $value);
1563 if ($theWrongTables) {
1564 if ($this->enableLogging) {
1565 $propArr = $this->getRecordProperties($table, $id);
1566 $this->log($table, $id, 5, 0, 1, '\'doktype\' of page \'%s\' could not be changed because the page contains records from disallowed tables; %s', 2, array($propArr['header'], $theWrongTables), $propArr['event_pid']);
1567 }
1568 return $res;
1569 }
1570 }
1571 }
1572 }
1573
1574 $curValue = NULL;
1575 if ((int)$id !== 0) {
1576 // Get current value:
1577 $curValueRec = $this->recordInfo($table, $id, $field);
1578 if (isset($curValueRec[$field])) {
1579 $curValue = $curValueRec[$field];
1580 }
1581 }
1582
1583 // Getting config for the field
1584 $tcaFieldConf = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
1585
1586 // Create $recFID only for those types that need it
1587 if (
1588 $tcaFieldConf['type'] === 'flex'
1589 || $tcaFieldConf['type'] === 'group' && ($tcaFieldConf['internal_type'] === 'file' || $tcaFieldConf['internal_type'] === 'file_reference')
1590 ) {
1591 $recFID = $table . ':' . $id . ':' . $field;
1592 } else {
1593 $recFID = NULL;
1594 }
1595
1596 // Perform processing:
1597 $res = $this->checkValue_SW($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $field, $this->uploadedFileArray[$table][$id][$field], $tscPID);
1598 return $res;
1599 }
1600
1601 /**
1602 * Branches out evaluation of a field value based on its type as configured in $GLOBALS['TCA']
1603 * Can be called for FlexForm pseudo fields as well, BUT must not have $field set if so.
1604 *
1605 * @param array $res The result array. The processed value (if any!) is set in the "value" key.
1606 * @param string $value The value to set.
1607 * @param array $tcaFieldConf Field configuration from $GLOBALS['TCA']
1608 * @param string $table Table name
1609 * @param int $id UID of record
1610 * @param mixed $curValue Current value of the field
1611 * @param string $status 'update' or 'new' flag
1612 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
1613 * @param string $recFID Field identifier [table:uid:field] for flexforms
1614 * @param string $field Field name. Must NOT be set if the call is for a flexform field (since flexforms are not allowed within flexforms).
1615 * @param array $uploadedFiles
1616 * @param int $tscPID TSconfig PID
1617 * @param array $additionalData Additional data to be forwarded to sub-processors
1618 * @return array Returns the evaluated $value as key "value" in this array.
1619 */
1620 public function checkValue_SW($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $field, $uploadedFiles, $tscPID, array $additionalData = NULL) {
1621 // Convert to NULL value if defined in TCA
1622 if ($value === NULL && !empty($tcaFieldConf['eval']) && GeneralUtility::inList($tcaFieldConf['eval'], 'null')) {
1623 $res = array('value' => NULL);
1624 return $res;
1625 }
1626
1627 switch ($tcaFieldConf['type']) {
1628 case 'text':
1629 $res = $this->checkValueForText($value, $tcaFieldConf);
1630 break;
1631 case 'passthrough':
1632 case 'imageManipulation':
1633 case 'user':
1634 $res['value'] = $value;
1635 break;
1636 case 'input':
1637 $res = $this->checkValueForInput($value, $tcaFieldConf, $table, $id, $realPid, $field);
1638 break;
1639 case 'check':
1640 $res = $this->checkValueForCheck($res, $value, $tcaFieldConf, $table, $id, $realPid, $field);
1641 break;
1642 case 'radio':
1643 $res = $this->checkValueForRadio($res, $value, $tcaFieldConf);
1644 break;
1645 case 'group':
1646 case 'select':
1647 $res = $this->checkValueForGroupSelect($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $recFID, $uploadedFiles, $field);
1648 break;
1649 case 'inline':
1650 $res = $this->checkValueForInline($res, $value, $tcaFieldConf, $table, $id, $status, $field, $additionalData);
1651 break;
1652 case 'flex':
1653 // FlexForms are only allowed for real fields.
1654 if ($field) {
1655 $res = $this->checkValueForFlex($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $tscPID, $uploadedFiles, $field);
1656 }
1657 break;
1658 default:
1659 // Do nothing
1660 }
1661 return $res;
1662 }
1663
1664 /**
1665 * Evaluate "text" type values.
1666 *
1667 * @param array $res The result array. The processed value (if any!) is set in the "value" key.
1668 * @param string $value The value to set.
1669 * @param array $tcaFieldConf Field configuration from TCA
1670 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
1671 * @param string $field Field name
1672 * @return array Modified $res array
1673 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1674 */
1675 public function checkValue_text($res, $value, $tcaFieldConf, $PP, $field = '') {
1676 GeneralUtility::logDeprecatedFunction();
1677 return $this->checkValueForText($value, $tcaFieldConf);
1678 }
1679
1680 /**
1681 * Evaluate "text" type values.
1682 *
1683 * @param string $value The value to set.
1684 * @param array $tcaFieldConf Field configuration from TCA
1685 * @return array $res The result array. The processed value (if any!) is set in the "value" key.
1686 */
1687 protected function checkValueForText($value, $tcaFieldConf) {
1688 if (!isset($tcaFieldConf['eval']) || $tcaFieldConf['eval'] === '') {
1689 return array('value' => $value);
1690 }
1691 $cacheId = $this->getFieldEvalCacheIdentifier($tcaFieldConf['eval']);
1692 if ($this->runtimeCache->has($cacheId)) {
1693 $evalCodesArray = $this->runtimeCache->get($cacheId);
1694 } else {
1695 $evalCodesArray = GeneralUtility::trimExplode(',', $tcaFieldConf['eval'], TRUE);
1696 $this->runtimeCache->set($cacheId, $evalCodesArray);
1697 }
1698 return $this->checkValue_text_Eval($value, $evalCodesArray, $tcaFieldConf['is_in']);
1699 }
1700
1701 /**
1702 * Evaluate "input" type values.
1703 *
1704 * @param array $res The result array. The processed value (if any!) is set in the "value" key.
1705 * @param string $value The value to set.
1706 * @param array $tcaFieldConf Field configuration from TCA
1707 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
1708 * @param string $field Field name
1709 * @return array Modified $res array
1710 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1711 */
1712 public function checkValue_input($res, $value, $tcaFieldConf, $PP, $field = '') {
1713 GeneralUtility::logDeprecatedFunction();
1714 list($table, $id, , , $realPid) = $PP;
1715 return $this->checkValueForInput($value, $tcaFieldConf, $table, $id, $realPid, $field);
1716 }
1717
1718 /**
1719 * Evaluate "input" type values.
1720 *
1721 * @param string $value The value to set.
1722 * @param array $tcaFieldConf Field configuration from TCA
1723 * @param string $table Table name
1724 * @param int $id UID of record
1725 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
1726 * @param string $field Field name
1727 * @return array $res The result array. The processed value (if any!) is set in the "value" key.
1728 */
1729 protected function checkValueForInput($value, $tcaFieldConf, $table, $id, $realPid, $field) {
1730 // Handle native date/time fields
1731 $isDateOrDateTimeField = FALSE;
1732 $format = '';
1733 $emptyValue = '';
1734 if (isset($tcaFieldConf['dbType']) && ($tcaFieldConf['dbType'] === 'date' || $tcaFieldConf['dbType'] === 'datetime')) {
1735 $isDateOrDateTimeField = TRUE;
1736 $dateTimeFormats = $this->databaseConnection->getDateTimeFormats($table);
1737 // Convert the date/time into a timestamp for the sake of the checks
1738 $emptyValue = $dateTimeFormats[$tcaFieldConf['dbType']]['empty'];
1739 $format = $dateTimeFormats[$tcaFieldConf['dbType']]['format'];
1740 // At this point in the processing, the timestamps are still based on UTC
1741 $timeZone = new \DateTimeZone('UTC');
1742 $dateTime = \DateTime::createFromFormat('!' . $format, $value, $timeZone);
1743 $value = $value === $emptyValue ? 0 : $dateTime->getTimestamp();
1744 }
1745 // Secures the string-length to be less than max.
1746 if ((int)$tcaFieldConf['max'] > 0) {
1747 $value = $GLOBALS['LANG']->csConvObj->substr($GLOBALS['LANG']->charSet, $value, 0, (int)$tcaFieldConf['max']);
1748 }
1749 // Checking range of value:
1750 if ($tcaFieldConf['range'] && $value != $tcaFieldConf['checkbox'] && (int)$value !== (int)$tcaFieldConf['default']) {
1751 if (isset($tcaFieldConf['range']['upper']) && (int)$value > (int)$tcaFieldConf['range']['upper']) {
1752 $value = $tcaFieldConf['range']['upper'];
1753 }
1754 if (isset($tcaFieldConf['range']['lower']) && (int)$value < (int)$tcaFieldConf['range']['lower']) {
1755 $value = $tcaFieldConf['range']['lower'];
1756 }
1757 }
1758
1759 if (empty($tcaFieldConf['eval'])) {
1760 $res = array('value' => $value);
1761 } else {
1762 // Process evaluation settings:
1763 $cacheId = $this->getFieldEvalCacheIdentifier($tcaFieldConf['eval']);
1764 if ($this->runtimeCache->has($cacheId)) {
1765 $evalCodesArray = $this->runtimeCache->get($cacheId);
1766 } else {
1767 $evalCodesArray = GeneralUtility::trimExplode(',', $tcaFieldConf['eval'], TRUE);
1768 $this->runtimeCache->set($cacheId, $evalCodesArray);
1769 }
1770
1771 $res = $this->checkValue_input_Eval($value, $evalCodesArray, $tcaFieldConf['is_in']);
1772
1773 // Process UNIQUE settings:
1774 // Field is NOT set for flexForms - which also means that uniqueInPid and unique is NOT available for flexForm fields! Also getUnique should not be done for versioning and if PID is -1 ($realPid<0) then versioning is happening...
1775 if ($field && $realPid >= 0 && !empty($res['value'])) {
1776 if (in_array('uniqueInPid', $evalCodesArray, TRUE)) {
1777 $res['value'] = $this->getUnique($table, $field, $res['value'], $id, $realPid);
1778 }
1779 if ($res['value'] && in_array('unique', $evalCodesArray, TRUE)) {
1780 $res['value'] = $this->getUnique($table, $field, $res['value'], $id);
1781 }
1782 }
1783 }
1784
1785 // Handle native date/time fields
1786 if ($isDateOrDateTimeField) {
1787 // Convert the timestamp back to a date/time
1788 $res['value'] = $res['value'] ? date($format, $res['value']) : $emptyValue;
1789 }
1790 return $res;
1791 }
1792
1793 /**
1794 * Evaluates 'check' type values.
1795 *
1796 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1797 * @param string $value The value to set.
1798 * @param array $tcaFieldConf Field configuration from TCA
1799 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
1800 * @param string $field Field name
1801 * @return array Modified $res array
1802 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1803 */
1804 public function checkValue_check($res, $value, $tcaFieldConf, $PP, $field = '') {
1805 GeneralUtility::logDeprecatedFunction();
1806 list($table, $id, , , $realPid) = $PP;
1807 return $this->checkValueForCheck($res, $value, $tcaFieldConf, $table, $id, $realPid, $field);
1808 }
1809
1810 /**
1811 * Evaluates 'check' type values.
1812 *
1813 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1814 * @param string $value The value to set.
1815 * @param array $tcaFieldConf Field configuration from TCA
1816 * @param string $table Table name
1817 * @param int $id UID of record
1818 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
1819 * @param string $field Field name
1820 * @return array Modified $res array
1821 */
1822 protected function checkValueForCheck($res, $value, $tcaFieldConf, $table, $id, $realPid, $field) {
1823 $itemC = count($tcaFieldConf['items']);
1824 if (!$itemC) {
1825 $itemC = 1;
1826 }
1827 $maxV = pow(2, $itemC) - 1;
1828 if ($value < 0) {
1829 $value = 0;
1830 }
1831 if ($value > $maxV) {
1832 $value = $maxV;
1833 }
1834 if ($field && $realPid >= 0 && $value > 0 && !empty($tcaFieldConf['eval'])) {
1835 $evalCodesArray = GeneralUtility::trimExplode(',', $tcaFieldConf['eval'], TRUE);
1836 $otherRecordsWithSameValue = array();
1837 $maxCheckedRecords = 0;
1838 if (in_array('maximumRecordsCheckedInPid', $evalCodesArray, TRUE)) {
1839 $otherRecordsWithSameValue = $this->getRecordsWithSameValue($table, $id, $field, $value, $realPid);
1840 $maxCheckedRecords = (int)$tcaFieldConf['validation']['maximumRecordsCheckedInPid'];
1841 }
1842 if (in_array('maximumRecordsChecked', $evalCodesArray, TRUE)) {
1843 $otherRecordsWithSameValue = $this->getRecordsWithSameValue($table, $id, $field, $value);
1844 $maxCheckedRecords = (int)$tcaFieldConf['validation']['maximumRecordsChecked'];
1845 }
1846
1847 // there are more than enough records with value "1" in the DB
1848 // if so, set this value to "0" again
1849 if ($maxCheckedRecords && count($otherRecordsWithSameValue) >= $maxCheckedRecords) {
1850 $value = 0;
1851 if ($this->enableLogging) {
1852 $this->log($table, $id, 5, 0, 1, 'Could not activate checkbox for field "%s". A total of %s record(s) can have this checkbox activated. Uncheck other records first in order to activate the checkbox of this record.', -1, array($GLOBALS['LANG']->sL(BackendUtility::getItemLabel($table, $field)), $maxCheckedRecords));
1853 }
1854 }
1855 }
1856 $res['value'] = $value;
1857 return $res;
1858 }
1859
1860 /**
1861 * Evaluates 'radio' type values.
1862 *
1863 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1864 * @param string $value The value to set.
1865 * @param array $tcaFieldConf Field configuration from TCA
1866 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
1867 * @return array Modified $res array
1868 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1869 */
1870 public function checkValue_radio($res, $value, $tcaFieldConf, $PP) {
1871 GeneralUtility::logDeprecatedFunction();
1872 return $this->checkValueForRadio($res, $value, $tcaFieldConf);
1873 }
1874
1875 /**
1876 * Evaluates 'radio' type values.
1877 *
1878 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1879 * @param string $value The value to set.
1880 * @param array $tcaFieldConf Field configuration from TCA
1881 * @return array Modified $res array
1882 */
1883 protected function checkValueForRadio($res, $value, $tcaFieldConf) {
1884 if (is_array($tcaFieldConf['items'])) {
1885 foreach ($tcaFieldConf['items'] as $set) {
1886 if ((string)$set[1] === (string)$value) {
1887 $res['value'] = $value;
1888 break;
1889 }
1890 }
1891 }
1892 return $res;
1893 }
1894
1895 /**
1896 * Evaluates 'group' or 'select' type values.
1897 *
1898 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1899 * @param string $value The value to set.
1900 * @param array $tcaFieldConf Field configuration from TCA
1901 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
1902 * @param array $uploadedFiles
1903 * @param string $field Field name
1904 * @return array Modified $res array
1905 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1906 */
1907 public function checkValue_group_select($res, $value, $tcaFieldConf, $PP, $uploadedFiles, $field) {
1908 GeneralUtility::logDeprecatedFunction();
1909 list($table, $id, $curValue, $status, , $recFID) = $PP;
1910 return $this->checkValueForGroupSelect($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $recFID, $uploadedFiles, $field);
1911 }
1912
1913 /**
1914 * Evaluates 'group' or 'select' type values.
1915 *
1916 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1917 * @param string $value The value to set.
1918 * @param array $tcaFieldConf Field configuration from TCA
1919 * @param string $table Table name
1920 * @param int $id UID of record
1921 * @param mixed $curValue Current value of the field
1922 * @param string $status 'update' or 'new' flag
1923 * @param string $recFID Field identifier [table:uid:field] for flexforms
1924 * @param array $uploadedFiles
1925 * @param string $field Field name
1926 * @return array Modified $res array
1927 */
1928 protected function checkValueForGroupSelect($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $recFID, $uploadedFiles, $field) {
1929 // Detecting if value sent is an array and if so, implode it around a comma:
1930 if (is_array($value)) {
1931 $value = implode(',', $value);
1932 }
1933 // This converts all occurrences of '&#123;' to the byte 123 in the string - this is needed in very rare cases where file names with special characters (e.g. ???, umlaut) gets sent to the server as HTML entities instead of bytes. The error is done only by MSIE, not Mozilla and Opera.
1934 // Anyway, this should NOT disturb anything else:
1935 $value = $this->convNumEntityToByteValue($value);
1936 // When values are sent as group or select they come as comma-separated values which are exploded by this function:
1937 $valueArray = $this->checkValue_group_select_explodeSelectGroupValue($value);
1938 // If multiple is not set, remove duplicates:
1939 if (!$tcaFieldConf['multiple']) {
1940 $valueArray = array_unique($valueArray);
1941 }
1942 // If an exclusive key is found, discard all others:
1943 if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['exclusiveKeys']) {
1944 $exclusiveKeys = GeneralUtility::trimExplode(',', $tcaFieldConf['exclusiveKeys']);
1945 foreach ($valueArray as $index => $key) {
1946 if (in_array($key, $exclusiveKeys, TRUE)) {
1947 $valueArray = array($index => $key);
1948 break;
1949 }
1950 }
1951 }
1952 // This could be a good spot for parsing the array through a validation-function which checks if the values are correct (except that database references are not in their final form - but that is the point, isn't it?)
1953 // NOTE!!! Must check max-items of files before the later check because that check would just leave out file names if there are too many!!
1954 $valueArray = $this->applyFiltersToValues($tcaFieldConf, $valueArray);
1955 // Checking for select / authMode, removing elements from $valueArray if any of them is not allowed!
1956 if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['authMode']) {
1957 $preCount = count($valueArray);
1958 foreach ($valueArray as $index => $key) {
1959 if (!$this->BE_USER->checkAuthMode($table, $field, $key, $tcaFieldConf['authMode'])) {
1960 unset($valueArray[$index]);
1961 }
1962 }
1963 // During the check it turns out that the value / all values were removed - we respond by simply returning an empty array so nothing is written to DB for this field.
1964 if ($preCount && !count($valueArray)) {
1965 return array();
1966 }
1967 }
1968 // For group types:
1969 if ($tcaFieldConf['type'] == 'group') {
1970 switch ($tcaFieldConf['internal_type']) {
1971 case 'file_reference':
1972
1973 case 'file':
1974 $valueArray = $this->checkValue_group_select_file($valueArray, $tcaFieldConf, $curValue, $uploadedFiles, $status, $table, $id, $recFID);
1975 break;
1976 case 'db':
1977 $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, 'group', $table, $field);
1978 break;
1979 }
1980 }
1981 // For select types which has a foreign table attached:
1982 $unsetResult = FALSE;
1983 if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['foreign_table']) {
1984 // check, if there is a NEW... id in the value, that should be substituted later
1985 if (strpos($value, 'NEW') !== FALSE) {
1986 $this->remapStackRecords[$table][$id] = array('remapStackIndex' => count($this->remapStack));
1987 $this->addNewValuesToRemapStackChildIds($valueArray);
1988 $this->remapStack[] = array(
1989 'func' => 'checkValue_group_select_processDBdata',
1990 'args' => array($valueArray, $tcaFieldConf, $id, $status, 'select', $table, $field),
1991 'pos' => array('valueArray' => 0, 'tcaFieldConf' => 1, 'id' => 2, 'table' => 5),
1992 'field' => $field
1993 );
1994 $unsetResult = TRUE;
1995 } else {
1996 $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, 'select', $table, $field);
1997 }
1998 }
1999 if (!$unsetResult) {
2000 $newVal = $this->checkValue_checkMax($tcaFieldConf, $valueArray);
2001 $res['value'] = implode(',', $newVal);
2002 } else {
2003 unset($res['value']);
2004 }
2005 return $res;
2006 }
2007
2008 /**
2009 * Applies the filter methods from a column's TCA configuration to a value array.
2010 *
2011 * @param array $tcaFieldConfiguration
2012 * @param array $values
2013 * @return array|mixed
2014 * @throws \RuntimeException
2015 */
2016 protected function applyFiltersToValues(array $tcaFieldConfiguration, array $values) {
2017 if (empty($tcaFieldConfiguration['filter']) || !is_array($tcaFieldConfiguration['filter'])) {
2018 return $values;
2019 }
2020 foreach ($tcaFieldConfiguration['filter'] as $filter) {
2021 if (empty($filter['userFunc'])) {
2022 continue;
2023 }
2024 $parameters = $filter['parameters'] ?: array();
2025 $parameters['values'] = $values;
2026 $parameters['tcaFieldConfig'] = $tcaFieldConfiguration;
2027 $values = GeneralUtility::callUserFunction($filter['userFunc'], $parameters, $this);
2028 if (!is_array($values)) {
2029 throw new \RuntimeException('Failed calling filter userFunc.', 1336051942);
2030 }
2031 }
2032 return $values;
2033 }
2034
2035 /**
2036 * Handling files for group/select function
2037 *
2038 * @param array $valueArray Array of incoming file references. Keys are numeric, values are files (basically, this is the exploded list of incoming files)
2039 * @param array $tcaFieldConf Configuration array from TCA of the field
2040 * @param string $curValue Current value of the field
2041 * @param array $uploadedFileArray Array of uploaded files, if any
2042 * @param string $status 'update' or 'new' flag
2043 * @param string $table tablename of record
2044 * @param int $id UID of record
2045 * @param string $recFID Field identifier [table:uid:field] for flexforms
2046 * @return array Modified value array
2047 * @see checkValue_group_select()
2048 */
2049 public function checkValue_group_select_file($valueArray, $tcaFieldConf, $curValue, $uploadedFileArray, $status, $table, $id, $recFID) {
2050 // If file handling should NOT be bypassed, do processing:
2051 if (!$this->bypassFileHandling) {
2052 // If any files are uploaded, add them to value array
2053 // Numeric index means that there are multiple files
2054 if (isset($uploadedFileArray[0])) {
2055 $uploadedFiles = $uploadedFileArray;
2056 } else {
2057 // There is only one file
2058 $uploadedFiles = array($uploadedFileArray);
2059 }
2060 foreach ($uploadedFiles as $uploadedFileArray) {
2061 if (!empty($uploadedFileArray['name']) && $uploadedFileArray['tmp_name'] !== 'none') {
2062 $valueArray[] = $uploadedFileArray['tmp_name'];
2063 $this->alternativeFileName[$uploadedFileArray['tmp_name']] = $uploadedFileArray['name'];
2064 }
2065 }
2066 // Creating fileFunc object.
2067 if (!$this->fileFunc) {
2068 $this->fileFunc = GeneralUtility::makeInstance(BasicFileUtility::class);
2069 $this->include_filefunctions = 1;
2070 }
2071 // Setting permitted extensions.
2072 $all_files = array();
2073 $all_files['webspace']['allow'] = $tcaFieldConf['allowed'];
2074 $all_files['webspace']['deny'] = $tcaFieldConf['disallowed'] ?: '*';
2075 $all_files['ftpspace'] = $all_files['webspace'];
2076 $this->fileFunc->init('', $all_files);
2077 }
2078 // If there is an upload folder defined:
2079 if ($tcaFieldConf['uploadfolder'] && $tcaFieldConf['internal_type'] == 'file') {
2080 // If filehandling should NOT be bypassed, do processing:
2081 if (!$this->bypassFileHandling) {
2082 // For logging..
2083 $propArr = $this->getRecordProperties($table, $id);
2084 // Get destrination path:
2085 $dest = $this->destPathFromUploadFolder($tcaFieldConf['uploadfolder']);
2086 // If we are updating:
2087 if ($status == 'update') {
2088 // Traverse the input values and convert to absolute filenames in case the update happens to an autoVersionized record.
2089 // Background: This is a horrible workaround! The problem is that when a record is auto-versionized the files of the record get copied and therefore get new names which is overridden with the names from the original record in the incoming data meaning both lost files and double-references!
2090 // The only solution I could come up with (except removing support for managing files when autoversioning) was to convert all relative files to absolute names so they are copied again (and existing files deleted). This should keep references intact but means that some files are copied, then deleted after being copied _again_.
2091 // Actually, the same problem applies to database references in case auto-versioning would include sub-records since in such a case references are remapped - and they would be overridden due to the same principle then.
2092 // Illustration of the problem comes here:
2093 // We have a record 123 with a file logo.gif. We open and edit the files header in a workspace. So a new version is automatically made.
2094 // The versions uid is 456 and the file is copied to "logo_01.gif". But the form data that we sent was based on uid 123 and hence contains the filename "logo.gif" from the original.
2095 // The file management code below will do two things: First it will blindly accept "logo.gif" as a file attached to the record (thus creating a double reference) and secondly it will find that "logo_01.gif" was not in the incoming filelist and therefore should be deleted.
2096 // If we prefix the incoming file "logo.gif" with its absolute path it will be seen as a new file added. Thus it will be copied to "logo_02.gif". "logo_01.gif" will still be deleted but since the files are the same the difference is zero - only more processing and file copying for no reason. But it will work.
2097 if ($this->autoVersioningUpdate === TRUE) {
2098 foreach ($valueArray as $key => $theFile) {
2099 // If it is an already attached file...
2100 if ($theFile === basename($theFile)) {
2101 $valueArray[$key] = PATH_site . $tcaFieldConf['uploadfolder'] . '/' . $theFile;
2102 }
2103 }
2104 }
2105 // Finding the CURRENT files listed, either from MM or from the current record.
2106 $theFileValues = array();
2107 // If MM relations for the files also!
2108 if ($tcaFieldConf['MM']) {
2109 $dbAnalysis = $this->createRelationHandlerInstance();
2110 /** @var $dbAnalysis RelationHandler */
2111 $dbAnalysis->start('', 'files', $tcaFieldConf['MM'], $id);
2112 foreach ($dbAnalysis->itemArray as $item) {
2113 if ($item['id']) {
2114 $theFileValues[] = $item['id'];
2115 }
2116 }
2117 } else {
2118 $theFileValues = GeneralUtility::trimExplode(',', $curValue, TRUE);
2119 }
2120 $currentFilesForHistory = implode(',', $theFileValues);
2121 // DELETE files: If existing files were found, traverse those and register files for deletion which has been removed:
2122 if (count($theFileValues)) {
2123 // Traverse the input values and for all input values which match an EXISTING value, remove the existing from $theFileValues array (this will result in an array of all the existing files which should be deleted!)
2124 foreach ($valueArray as $key => $theFile) {
2125 if ($theFile && !strstr(GeneralUtility::fixWindowsFilePath($theFile), '/')) {
2126 $theFileValues = ArrayUtility::removeArrayEntryByValue($theFileValues, $theFile);
2127 }
2128 }
2129 // This array contains the filenames in the uploadfolder that should be deleted:
2130 foreach ($theFileValues as $key => $theFile) {
2131 $theFile = trim($theFile);
2132 if (@is_file(($dest . '/' . $theFile))) {
2133 $this->removeFilesStore[] = $dest . '/' . $theFile;
2134 } elseif ($this->enableLogging && $theFile) {
2135 $this->log($table, $id, 5, 0, 1, 'Could not delete file \'%s\' (does not exist). (%s)', 10, array($dest . '/' . $theFile, $recFID), $propArr['event_pid']);
2136 }
2137 }
2138 }
2139 }
2140 // Traverse the submitted values:
2141 foreach ($valueArray as $key => $theFile) {
2142 // Init:
2143 $maxSize = (int)$tcaFieldConf['max_size'];
2144 // Must be cleared. Else a faulty fileref may be inserted if the below code returns an error!
2145 $theDestFile = '';
2146 // a FAL file was added, now resolve the file object and get the absolute path
2147 // @todo in future versions this needs to be modified to handle FAL objects natively
2148 if (!empty($theFile) && MathUtility::canBeInterpretedAsInteger($theFile)) {
2149 $fileObject = ResourceFactory::getInstance()->getFileObject($theFile);
2150 $theFile = $fileObject->getForLocalProcessing(FALSE);
2151 }
2152 // NEW FILES? If the value contains '/' it indicates, that the file
2153 // is new and should be added to the uploadsdir (whether its absolute or relative does not matter here)
2154 if (strstr(GeneralUtility::fixWindowsFilePath($theFile), '/')) {
2155 // Check various things before copying file:
2156 // File and destination must exist
2157 if (@is_dir($dest) && (@is_file($theFile) || @is_uploaded_file($theFile))) {
2158 // Finding size.
2159 if (is_uploaded_file($theFile) && $theFile == $uploadedFileArray['tmp_name']) {
2160 $fileSize = $uploadedFileArray['size'];
2161 } else {
2162 $fileSize = filesize($theFile);
2163 }
2164 // Check file size:
2165 if (!$maxSize || $fileSize <= $maxSize * 1024) {
2166 // Prepare filename:
2167 $theEndFileName = isset($this->alternativeFileName[$theFile]) ? $this->alternativeFileName[$theFile] : $theFile;
2168 $fI = GeneralUtility::split_fileref($theEndFileName);
2169 // Check for allowed extension:
2170 if ($this->fileFunc->checkIfAllowed($fI['fileext'], $dest, $theEndFileName)) {
2171 $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($fI['file']), $dest);
2172 // If we have a unique destination filename, then write the file:
2173 if ($theDestFile) {
2174 GeneralUtility::upload_copy_move($theFile, $theDestFile);
2175 // Hook for post-processing the upload action
2176 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processUpload'])) {
2177 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processUpload'] as $classRef) {
2178 $hookObject = GeneralUtility::getUserObj($classRef);
2179 if (!$hookObject instanceof DataHandlerProcessUploadHookInterface) {
2180 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Core\\DataHandling\\DataHandlerProcessUploadHookInterface', 1279962349);
2181 }
2182 $hookObject->processUpload_postProcessAction($theDestFile, $this);
2183 }
2184 }
2185 $this->copiedFileMap[$theFile] = $theDestFile;
2186 clearstatcache();
2187 if ($this->enableLogging && !@is_file($theDestFile)) {
2188 $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)', 16, array($theFile, dirname($theDestFile), $recFID), $propArr['event_pid']);
2189 }
2190 } elseif ($this->enableLogging) {
2191 $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: No destination file (%s) possible!. (%s)', 11, array($theFile, $theDestFile, $recFID), $propArr['event_pid']);
2192 }
2193 } elseif ($this->enableLogging) {
2194 $this->log($table, $id, 5, 0, 1, 'File extension \'%s\' not allowed. (%s)', 12, array($fI['fileext'], $recFID), $propArr['event_pid']);
2195 }
2196 } elseif ($this->enableLogging) {
2197 $this->log($table, $id, 5, 0, 1, 'Filesize (%s) of file \'%s\' exceeds limit (%s). (%s)', 13, array(GeneralUtility::formatSize($fileSize), $theFile, GeneralUtility::formatSize($maxSize * 1024), $recFID), $propArr['event_pid']);
2198 }
2199 } elseif ($this->enableLogging) {
2200 $this->log($table, $id, 5, 0, 1, 'The destination (%s) or the source file (%s) does not exist. (%s)', 14, array($dest, $theFile, $recFID), $propArr['event_pid']);
2201 }
2202 // If the destination file was created, we will set the new filename in the value array, otherwise unset the entry in the value array!
2203 if (@is_file($theDestFile)) {
2204 $info = GeneralUtility::split_fileref($theDestFile);
2205 // The value is set to the new filename
2206 $valueArray[$key] = $info['file'];
2207 } else {
2208 // The value is set to the new filename
2209 unset($valueArray[$key]);
2210 }
2211 }
2212 }
2213 }
2214 // If MM relations for the files, we will set the relations as MM records and change the valuearray to contain a single entry with a count of the number of files!
2215 if ($tcaFieldConf['MM']) {
2216 /** @var $dbAnalysis RelationHandler */
2217 $dbAnalysis = $this->createRelationHandlerInstance();
2218 // Dummy
2219 $dbAnalysis->tableArray['files'] = array();
2220 foreach ($valueArray as $key => $theFile) {
2221 // Explode files
2222 $dbAnalysis->itemArray[]['id'] = $theFile;
2223 }
2224 if ($status == 'update') {
2225 $dbAnalysis->writeMM($tcaFieldConf['MM'], $id, 0);
2226 $newFiles = implode(',', $dbAnalysis->getValueArray());
2227 list(, , $recFieldName) = explode(':', $recFID);
2228 if ($currentFilesForHistory != $newFiles) {
2229 $this->mmHistoryRecords[$table . ':' . $id]['oldRecord'][$recFieldName] = $currentFilesForHistory;
2230 $this->mmHistoryRecords[$table . ':' . $id]['newRecord'][$recFieldName] = $newFiles;
2231 } else {
2232 $this->mmHistoryRecords[$table . ':' . $id]['oldRecord'][$recFieldName] = '';
2233 $this->mmHistoryRecords[$table . ':' . $id]['newRecord'][$recFieldName] = '';
2234 }
2235 } else {
2236 $this->dbAnalysisStore[] = array($dbAnalysis, $tcaFieldConf['MM'], $id, 0);
2237 }
2238 $valueArray = $dbAnalysis->countItems();
2239 }
2240 } else {
2241 if (count($valueArray)) {
2242 // If filehandling should NOT be bypassed, do processing:
2243 if (!$this->bypassFileHandling) {
2244 // For logging..
2245 $propArr = $this->getRecordProperties($table, $id);
2246 foreach ($valueArray as &$theFile) {
2247 // FAL handling: it's a UID, thus it is resolved to the absolute path
2248 if (!empty($theFile) && MathUtility::canBeInterpretedAsInteger($theFile)) {
2249 $fileObject = ResourceFactory::getInstance()->getFileObject($theFile);
2250 $theFile = $fileObject->getForLocalProcessing(FALSE);
2251 }
2252 if ($this->alternativeFilePath[$theFile]) {
2253 // If alternative File Path is set for the file, then it was an import
2254 // don't import the file if it already exists
2255 if (@is_file((PATH_site . $this->alternativeFilePath[$theFile]))) {
2256 $theFile = PATH_site . $this->alternativeFilePath[$theFile];
2257 } elseif (@is_file($theFile)) {
2258 $dest = dirname(PATH_site . $this->alternativeFilePath[$theFile]);
2259 if (!@is_dir($dest)) {
2260 GeneralUtility::mkdir_deep(PATH_site, dirname($this->alternativeFilePath[$theFile]) . '/');
2261 }
2262 // Init:
2263 $maxSize = (int)$tcaFieldConf['max_size'];
2264 // Must be cleared. Else a faulty fileref may be inserted if the below code returns an error!
2265 $theDestFile = '';
2266 $fileSize = filesize($theFile);
2267 // Check file size:
2268 if (!$maxSize || $fileSize <= $maxSize * 1024) {
2269 // Prepare filename:
2270 $theEndFileName = isset($this->alternativeFileName[$theFile]) ? $this->alternativeFileName[$theFile] : $theFile;
2271 $fI = GeneralUtility::split_fileref($theEndFileName);
2272 // Check for allowed extension:
2273 if ($this->fileFunc->checkIfAllowed($fI['fileext'], $dest, $theEndFileName)) {
2274 $theDestFile = PATH_site . $this->alternativeFilePath[$theFile];
2275 // Write the file:
2276 if ($theDestFile) {
2277 GeneralUtility::upload_copy_move($theFile, $theDestFile);
2278 $this->copiedFileMap[$theFile] = $theDestFile;
2279 clearstatcache();
2280 if ($this->enableLogging && !@is_file($theDestFile)) {
2281 $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)', 16, array($theFile, dirname($theDestFile), $recFID), $propArr['event_pid']);
2282 }
2283 } elseif ($this->enableLogging) {
2284 $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: No destination file (%s) possible!. (%s)', 11, array($theFile, $theDestFile, $recFID), $propArr['event_pid']);
2285 }
2286 } elseif ($this->enableLogging) {
2287 $this->log($table, $id, 5, 0, 1, 'File extension \'%s\' not allowed. (%s)', 12, array($fI['fileext'], $recFID), $propArr['event_pid']);
2288 }
2289 } elseif ($this->enableLogging) {
2290 $this->log($table, $id, 5, 0, 1, 'Filesize (%s) of file \'%s\' exceeds limit (%s). (%s)', 13, array(GeneralUtility::formatSize($fileSize), $theFile, GeneralUtility::formatSize($maxSize * 1024), $recFID), $propArr['event_pid']);
2291 }
2292 // If the destination file was created, we will set the new filename in the value array, otherwise unset the entry in the value array!
2293 if (@is_file($theDestFile)) {
2294 // The value is set to the new filename
2295 $theFile = $theDestFile;
2296 } else {
2297 // The value is set to the new filename
2298 unset($theFile);
2299 }
2300 }
2301 }
2302 $theFile = GeneralUtility::fixWindowsFilePath($theFile);
2303 if (GeneralUtility::isFirstPartOfStr($theFile, PATH_site)) {
2304 $theFile = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($theFile);
2305 }
2306 }
2307 unset($theFile);
2308 }
2309 }
2310 }
2311 return $valueArray;
2312 }
2313
2314 /**
2315 * Evaluates 'flex' type values.
2316 *
2317 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
2318 * @param string|array $value The value to set.
2319 * @param array $tcaFieldConf Field configuration from TCA
2320 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
2321 * @param array $uploadedFiles Uploaded files for the field
2322 * @param string $field Field name
2323 * @return array Modified $res array
2324 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
2325 */
2326 public function checkValue_flex($res, $value, $tcaFieldConf, $PP, $uploadedFiles, $field) {
2327 GeneralUtility::logDeprecatedFunction();
2328 list($table, $id, $curValue, $status, $realPid, $recFID, $tscPID) = $PP;
2329 $this->checkValueForFlex($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $tscPID, $uploadedFiles, $field);
2330 }
2331
2332 /**
2333 * Evaluates 'flex' type values.
2334 *
2335 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
2336 * @param string|array $value The value to set.
2337 * @param array $tcaFieldConf Field configuration from TCA
2338 * @param string $table Table name
2339 * @param int $id UID of record
2340 * @param mixed $curValue Current value of the field
2341 * @param string $status 'update' or 'new' flag
2342 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
2343 * @param string $recFID Field identifier [table:uid:field] for flexforms
2344 * @param int $tscPID TSconfig PID
2345 * @param array $uploadedFiles Uploaded files for the field
2346 * @param string $field Field name
2347 * @return array Modified $res array
2348 */
2349 protected function checkValueForFlex($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $tscPID, $uploadedFiles, $field) {
2350
2351 if (is_array($value)) {
2352 // This value is necessary for flex form processing to happen on flexform fields in page records when they are copied.
2353 // Problem: when copying a page, flexform XML comes along in the array for the new record - but since $this->checkValue_currentRecord does not have a uid or pid for that
2354 // sake, the BackendUtility::getFlexFormDS() function returns no good DS. For new records we do know the expected PID so therefore we send that with this special parameter.
2355 // Only active when larger than zero.
2356 $newRecordPidValue = $status == 'new' ? $realPid : 0;
2357 // Get current value array:
2358 $dataStructArray = BackendUtility::getFlexFormDS($tcaFieldConf, $this->checkValue_currentRecord, $table, $field, TRUE, $newRecordPidValue);
2359 $currentValueArray = (string)$curValue !== '' ? GeneralUtility::xml2array($curValue) : array();
2360 if (!is_array($currentValueArray)) {
2361 $currentValueArray = array();
2362 }
2363 if (is_array($currentValueArray['meta']['currentLangId'])) {
2364 unset($currentValueArray['meta']['currentLangId']);
2365 }
2366 // Remove all old meta for languages...
2367 // Evaluation of input values:
2368 $value['data'] = $this->checkValue_flex_procInData($value['data'], $currentValueArray['data'], $uploadedFiles['data'], $dataStructArray, array($table, $id, $curValue, $status, $realPid, $recFID, $tscPID));
2369 // Create XML from input value:
2370 $xmlValue = $this->checkValue_flexArray2Xml($value, TRUE);
2371
2372 // Here we convert the currently submitted values BACK to an array, then merge the two and then BACK to XML again. This is needed to ensure the charsets are the same
2373 // (provided that the current value was already stored IN the charset that the new value is converted to).
2374 $arrValue = GeneralUtility::xml2array($xmlValue);
2375
2376 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkFlexFormValue'])) {
2377 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkFlexFormValue'] as $classRef) {
2378 $hookObject = GeneralUtility::getUserObj($classRef);
2379 if (method_exists($hookObject, 'checkFlexFormValue_beforeMerge')) {
2380 $hookObject->checkFlexFormValue_beforeMerge($this, $currentValueArray, $arrValue);
2381 }
2382 }
2383 }
2384
2385 ArrayUtility::mergeRecursiveWithOverrule($currentValueArray, $arrValue);
2386 $xmlValue = $this->checkValue_flexArray2Xml($currentValueArray, TRUE);
2387
2388 // Action commands (sorting order and removals of elements) for flexform sections,
2389 // see FormEngine for the use of this GP parameter
2390 $actionCMDs = GeneralUtility::_GP('_ACTION_FLEX_FORMdata');
2391 if (is_array($actionCMDs[$table][$id][$field]['data'])) {
2392 $arrValue = GeneralUtility::xml2array($xmlValue);
2393 $this->_ACTION_FLEX_FORMdata($arrValue['data'], $actionCMDs[$table][$id][$field]['data']);
2394 $xmlValue = $this->checkValue_flexArray2Xml($arrValue, TRUE);
2395 }
2396 // Create the value XML:
2397 $res['value'] = '';
2398 $res['value'] .= $xmlValue;
2399 } else {
2400 // Passthrough...:
2401 $res['value'] = $value;
2402 }
2403
2404 return $res;
2405 }
2406
2407 /**
2408 * Converts an array to FlexForm XML
2409 *
2410 * @param array $array Array with FlexForm data
2411 * @param bool $addPrologue If set, the XML prologue is returned as well.
2412 * @return string Input array converted to XML
2413 */
2414 public function checkValue_flexArray2Xml($array, $addPrologue = FALSE) {
2415 /** @var $flexObj FlexFormTools */
2416 $flexObj = GeneralUtility::makeInstance(FlexFormTools::class);
2417 return $flexObj->flexArray2Xml($array, $addPrologue);
2418 }
2419
2420 /**
2421 * Actions for flex form element (move, delete)
2422 * allows to remove and move flexform sections
2423 *
2424 * @param array $valueArray by reference
2425 * @param array $actionCMDs
2426 */
2427 protected function _ACTION_FLEX_FORMdata(&$valueArray, $actionCMDs) {
2428 if (is_array($valueArray) && is_array($actionCMDs)) {
2429 foreach ($actionCMDs as $key => $value) {
2430 if ($key == '_ACTION') {
2431 // First, check if there are "commands":
2432 if (current($actionCMDs[$key]) !== '') {
2433 asort($actionCMDs[$key]);
2434 $newValueArray = array();
2435 foreach ($actionCMDs[$key] as $idx => $order) {
2436 if (substr($idx, 0, 3) == 'ID-') {
2437 $idx = $this->newIndexMap[$idx];
2438 }
2439 // Just one reflection here: It is clear that when removing elements from a flexform, then we will get lost files unless we act on this delete operation by traversing and deleting files that were referred to.
2440 if ($order != 'DELETE') {
2441 $newValueArray[$idx] = $valueArray[$idx];
2442 }
2443 unset($valueArray[$idx]);
2444 }
2445 $valueArray = $valueArray + $newValueArray;
2446 }
2447 } elseif (is_array($actionCMDs[$key]) && isset($valueArray[$key])) {
2448 $this->_ACTION_FLEX_FORMdata($valueArray[$key], $actionCMDs[$key]);
2449 }
2450 }
2451 }
2452 }
2453
2454 /**
2455 * Evaluates 'inline' type values.
2456 * (partly copied from the select_group function on this issue)
2457 *
2458 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
2459 * @param string $value The value to set.
2460 * @param array $tcaFieldConf Field configuration from TCA
2461 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
2462 * @param string $field Field name
2463 * @param array $additionalData Additional data to be forwarded to sub-processors
2464 * @return array Modified $res array
2465 */
2466 public function checkValue_inline($res, $value, $tcaFieldConf, $PP, $field, array $additionalData = NULL) {
2467 list($table, $id, , $status) = $PP;
2468 $this->checkValueForInline($res, $value, $tcaFieldConf, $table, $id, $status, $field, $additionalData);
2469 }
2470
2471 /**
2472 * Evaluates 'inline' type values.
2473 * (partly copied from the select_group function on this issue)
2474 *
2475 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
2476 * @param string $value The value to set.
2477 * @param array $tcaFieldConf Field configuration from TCA
2478 * @param string $table Table name
2479 * @param int $id UID of record
2480 * @param string $status 'update' or 'new' flag
2481 * @param string $field Field name
2482 * @param array $additionalData Additional data to be forwarded to sub-processors
2483 * @return array Modified $res array
2484 */
2485 public function checkValueForInline($res, $value, $tcaFieldConf, $table, $id, $status, $field, array $additionalData = NULL) {
2486 if (!$tcaFieldConf['foreign_table']) {
2487 // Fatal error, inline fields should always have a foreign_table defined
2488 return FALSE;
2489 }
2490 // When values are sent they come as comma-separated values which are exploded by this function:
2491 $valueArray = GeneralUtility::trimExplode(',', $value);
2492 // Remove duplicates: (should not be needed)
2493 $valueArray = array_unique($valueArray);
2494 // Example for received data:
2495 // $value = 45,NEW4555fdf59d154,12,123
2496 // We need to decide whether we use the stack or can save the relation directly.
2497 if (strpos($value, 'NEW') !== FALSE || !MathUtility::canBeInterpretedAsInteger($id)) {
2498 $this->remapStackRecords[$table][$id] = array('remapStackIndex' => count($this->remapStack));
2499 $this->addNewValuesToRemapStackChildIds($valueArray);
2500 $this->remapStack[] = array(
2501 'func' => 'checkValue_inline_processDBdata',
2502 'args' => array($valueArray, $tcaFieldConf, $id, $status, $table, $field, $additionalData),
2503 'pos' => array('valueArray' => 0, 'tcaFieldConf' => 1, 'id' => 2, 'table' => 4),
2504 'additionalData' => $additionalData,
2505 'field' => $field,
2506 );
2507 unset($res['value']);
2508 } elseif ($value || MathUtility::canBeInterpretedAsInteger($id)) {
2509 $res['value'] = $this->checkValue_inline_processDBdata($valueArray, $tcaFieldConf, $id, $status, $table, $field, $additionalData);
2510 }
2511 return $res;
2512 }
2513
2514 /**
2515 * Checks if a fields has more items than defined via TCA in maxitems.
2516 * If there are more items than allowd, the item list is truncated to the defined number.
2517 *
2518 * @param array $tcaFieldConf Field configuration from TCA
2519 * @param array $valueArray Current value array of items
2520 * @return array The truncated value array of items
2521 */
2522 public function checkValue_checkMax($tcaFieldConf, $valueArray) {
2523 // BTW, checking for min and max items here does NOT make any sense when MM is used because the above function calls will just return an array with a single item (the count) if MM is used... Why didn't I perform the check before? Probably because we could not evaluate the validity of record uids etc... Hmm...
2524 $valueArrayC = count($valueArray);
2525 // NOTE to the comment: It's not really possible to check for too few items, because you must then determine first, if the field is actual used regarding the CType.
2526 $maxI = isset($tcaFieldConf['maxitems']) ? (int)$tcaFieldConf['maxitems'] : 1;
2527 if ($valueArrayC > $maxI) {
2528 $valueArrayC = $maxI;
2529 }
2530 // Checking for not too many elements
2531 // Dumping array to list
2532 $newVal = array();
2533 foreach ($valueArray as $nextVal) {
2534 if ($valueArrayC == 0) {
2535 break;
2536 }
2537 $valueArrayC--;
2538 $newVal[] = $nextVal;
2539 }
2540 return $newVal;
2541 }
2542
2543 /*********************************************
2544 *
2545 * Helper functions for evaluation functions.
2546 *
2547 ********************************************/
2548 /**
2549 * Gets a unique value for $table/$id/$field based on $value
2550 *
2551 * @param string $table Table name
2552 * @param string $field Field name for which $value must be unique
2553 * @param string $value Value string.
2554 * @param int $id UID to filter out in the lookup (the record itself...)
2555 * @param int $newPid If set, the value will be unique for this PID
2556 * @return string Modified value (if not-unique). Will be the value appended with a number (until 100, then the function just breaks).
2557 */
2558 public function getUnique($table, $field, $value, $id, $newPid = 0) {
2559 // Initialize:
2560 $whereAdd = '';
2561 $newValue = '';
2562 if ((int)$newPid) {
2563 $whereAdd .= ' AND pid=' . (int)$newPid;
2564 } else {
2565 $whereAdd .= ' AND pid>=0';
2566 }
2567 // "AND pid>=0" for versioning
2568 $whereAdd .= $this->deleteClause($table);
2569 // If the field is configured in TCA, proceed:
2570 if (is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'][$field])) {
2571 // Look for a record which might already have the value:
2572 $res = $this->databaseConnection->exec_SELECTquery('uid', $table, $field . '=' . $this->databaseConnection->fullQuoteStr($value, $table) . ' AND uid<>' . (int)$id . $whereAdd);
2573 $counter = 0;
2574 // For as long as records with the test-value existing, try again (with incremented numbers appended).
2575 while ($this->databaseConnection->sql_num_rows($res)) {
2576 $newValue = $value . $counter;
2577 $res = $this->databaseConnection->exec_SELECTquery('uid', $table, $field . '=' . $this->databaseConnection->fullQuoteStr($newValue, $table) . ' AND uid<>' . (int)$id . $whereAdd);
2578 $counter++;
2579 if ($counter > 100) {
2580 break;
2581 }
2582 }
2583 $this->databaseConnection->sql_free_result($res);
2584 // If the new value is there:
2585 $value = $newValue !== '' ? $newValue : $value;
2586 }
2587 return $value;
2588 }
2589
2590 /**
2591 * gets all records that have the same value in a field
2592 * excluding the given uid
2593 *
2594 * @param string $tableName Table name
2595 * @param int $uid UID to filter out in the lookup (the record itself...)
2596 * @param string $fieldName Field name for which $value must be unique
2597 * @param string $value Value string.
2598 * @param int $pageId If set, the value will be unique for this PID
2599 * @return array
2600 */
2601 public function getRecordsWithSameValue($tableName, $uid, $fieldName, $value, $pageId = 0) {
2602 $result = array();
2603 if (!empty($GLOBALS['TCA'][$tableName]['columns'][$fieldName])) {
2604
2605 $uid = (int)$uid;
2606 $pageId = (int)$pageId;
2607 $whereStatement = ' AND uid <> ' . $uid . ' AND ' . ($pageId ? 'pid = ' . $pageId : 'pid >= 0');
2608 $result = BackendUtility::getRecordsByField($tableName, $fieldName, $value, $whereStatement);
2609 }
2610 return $result;
2611 }
2612
2613 /**
2614 * @param string $value The field value to be evaluated
2615 * @param array $evalArray Array of evaluations to traverse.
2616 * @param string $is_in The "is_in" value of the field configuration from TCA
2617 * @return array
2618 */
2619 public function checkValue_text_Eval($value, $evalArray, $is_in) {
2620 $res = array();
2621 $set = TRUE;
2622 foreach ($evalArray as $func) {
2623 switch ($func) {
2624 case 'trim':
2625 $value = trim($value);
2626 break;
2627 case 'required':
2628 if (!$value) {
2629 $set = FALSE;
2630 }
2631 break;
2632 default:
2633 if (empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
2634 break;
2635 }
2636 $evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
2637 if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) {
2638 $value = $evalObj->evaluateFieldValue($value, $is_in, $set);
2639 }
2640 }
2641 }
2642 if ($set) {
2643 $res['value'] = $value;
2644 }
2645 return $res;
2646 }
2647
2648 /**
2649 * Evaluation of 'input'-type values based on 'eval' list
2650 *
2651 * @param string $value Value to evaluate
2652 * @param array $evalArray Array of evaluations to traverse.
2653 * @param string $is_in Is-in string for 'is_in' evaluation
2654 * @return array Modified $value in key 'value' or empty array
2655 */
2656 public function checkValue_input_Eval($value, $evalArray, $is_in) {
2657 $res = array();
2658 $set = TRUE;
2659 foreach ($evalArray as $func) {
2660 switch ($func) {
2661 case 'int':
2662 case 'year':
2663 case 'time':
2664 case 'timesec':
2665 $value = (int)$value;
2666 break;
2667 case 'date':
2668 case 'datetime':
2669 $value = (int)$value;
2670 if ($value > 0 && !$this->dontProcessTransformations) {
2671 $value -= date('Z', $value);
2672 }
2673 break;
2674 case 'double2':
2675 $value = preg_replace('/[^0-9,\\.-]/', '', $value);
2676 $negative = $value[0] === '-';
2677 $value = strtr($value, array(',' => '.', '-' => ''));
2678 if (strpos($value, '.') === FALSE) {
2679 $value .= '.0';
2680 }
2681 $valueArray = explode('.', $value);
2682 $dec = array_pop($valueArray);
2683 $value = join('', $valueArray) . '.' . $dec;
2684 if ($negative) {
2685 $value *= -1;
2686 }
2687 $value = number_format($value, 2, '.', '');
2688 break;
2689 case 'md5':
2690 if (strlen($value) != 32) {
2691 $set = FALSE;
2692 }
2693 break;
2694 case 'trim':
2695 $value = trim($value);
2696 break;
2697 case 'upper':
2698 $value = $GLOBALS['LANG']->csConvObj->conv_case($GLOBALS['LANG']->charSet, $value, 'toUpper');
2699 break;
2700 case 'lower':
2701 $value = $GLOBALS['LANG']->csConvObj->conv_case($GLOBALS['LANG']->charSet, $value, 'toLower');
2702 break;
2703 case 'required':
2704 if (!isset($value) || $value === '') {
2705 $set = FALSE;
2706 }
2707 break;
2708 case 'is_in':
2709 $c = strlen($value);
2710 if ($c) {
2711 $newVal = '';
2712 for ($a = 0; $a < $c; $a++) {
2713 $char = substr($value, $a, 1);
2714 if (strpos($is_in, $char) !== FALSE) {
2715 $newVal .= $char;
2716 }
2717 }
2718 $value = $newVal;
2719 }
2720 break;
2721 case 'nospace':
2722 $value = str_replace(' ', '', $value);
2723 break;
2724 case 'alpha':
2725 $value = preg_replace('/[^a-zA-Z]/', '', $value);
2726 break;
2727 case 'num':
2728 $value = preg_replace('/[^0-9]/', '', $value);
2729 break;
2730 case 'alphanum':
2731 $value = preg_replace('/[^a-zA-Z0-9]/', '', $value);
2732 break;
2733 case 'alphanum_x':
2734 $value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value);
2735 break;
2736 case 'domainname':
2737 if (!preg_match('/^[a-z0-9.\\-]*$/i', $value)) {
2738 $value = GeneralUtility::idnaEncode($value);
2739 }
2740 break;
2741 case 'email':
2742 $this->checkValue_input_ValidateEmail($value, $set);
2743 break;
2744 default:
2745 if (empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
2746 break;
2747 }
2748 $evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
2749 if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) {
2750 $value = $evalObj->evaluateFieldValue($value, $is_in, $set);
2751 }
2752 }
2753 }
2754 if ($set) {
2755 $res['value'] = $value;
2756 }
2757 return $res;
2758 }
2759
2760 /**
2761 * If $value is not a valid e-mail address,
2762 * $set will be set to false and a flash error
2763 * message will be added
2764 *
2765 * @param string $value Value to evaluate