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