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