[BUGFIX] Decouple thumbnail generation from controllers
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Utility / BackendUtility.php
1 <?php
2 namespace TYPO3\CMS\Backend\Utility;
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\Routing\UriBuilder;
18 use TYPO3\CMS\Backend\Template\DocumentTemplate;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20 use TYPO3\CMS\Core\Cache\CacheManager;
21 use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
22 use TYPO3\CMS\Core\Database\Connection;
23 use TYPO3\CMS\Core\Database\ConnectionPool;
24 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
25 use TYPO3\CMS\Core\Database\Query\QueryHelper;
26 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
27 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
28 use TYPO3\CMS\Core\Database\RelationHandler;
29 use TYPO3\CMS\Core\Imaging\Icon;
30 use TYPO3\CMS\Core\Imaging\IconFactory;
31 use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
32 use TYPO3\CMS\Core\Resource\AbstractFile;
33 use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
34 use TYPO3\CMS\Core\Resource\File;
35 use TYPO3\CMS\Core\Resource\ProcessedFile;
36 use TYPO3\CMS\Core\Resource\ResourceFactory;
37 use TYPO3\CMS\Core\Type\Bitmask\Permission;
38 use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
39 use TYPO3\CMS\Core\Utility\ArrayUtility;
40 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
41 use TYPO3\CMS\Core\Utility\GeneralUtility;
42 use TYPO3\CMS\Core\Utility\MathUtility;
43 use TYPO3\CMS\Core\Utility\PathUtility;
44 use TYPO3\CMS\Core\Versioning\VersionState;
45 use TYPO3\CMS\Frontend\Page\PageRepository;
46 use TYPO3\CMS\Lang\LanguageService;
47
48 /**
49 * Standard functions available for the TYPO3 backend.
50 * You are encouraged to use this class in your own applications (Backend Modules)
51 * Don't instantiate - call functions with "\TYPO3\CMS\Backend\Utility\BackendUtility::" prefixed the function name.
52 *
53 * Call ALL methods without making an object!
54 * Eg. to get a page-record 51 do this: '\TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('pages',51)'
55 */
56 class BackendUtility
57 {
58 /**
59 * Cache the TCA configuration of tables with their types during runtime
60 *
61 * @var array
62 * @see self::getTCAtypes()
63 */
64 protected static $tcaTableTypeConfigurationCache = [];
65
66 /*******************************************
67 *
68 * SQL-related, selecting records, searching
69 *
70 *******************************************/
71 /**
72 * Returns the WHERE clause " AND NOT [tablename].[deleted-field]" if a deleted-field
73 * is configured in $GLOBALS['TCA'] for the tablename, $table
74 * This function should ALWAYS be called in the backend for selection on tables which
75 * are configured in $GLOBALS['TCA'] since it will ensure consistent selection of records,
76 * even if they are marked deleted (in which case the system must always treat them as non-existent!)
77 * In the frontend a function, ->enableFields(), is known to filter hidden-field, start- and endtime
78 * and fe_groups as well. But that is a job of the frontend, not the backend. If you need filtering
79 * on those fields as well in the backend you can use ->BEenableFields() though.
80 *
81 * @param string $table Table name present in $GLOBALS['TCA']
82 * @param string $tableAlias Table alias if any
83 * @return string WHERE clause for filtering out deleted records, eg " AND tablename.deleted=0
84 */
85 public static function deleteClause($table, $tableAlias = '')
86 {
87 if (empty($GLOBALS['TCA'][$table]['ctrl']['delete'])) {
88 return '';
89 }
90 $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
91 ->getQueryBuilderForTable($table)
92 ->expr();
93 return ' AND ' . $expressionBuilder->eq(
94 ($tableAlias ?: $table) . '.' . $GLOBALS['TCA'][$table]['ctrl']['delete'],
95 0
96 );
97 }
98
99 /**
100 * Gets record with uid = $uid from $table
101 * You can set $field to a list of fields (default is '*')
102 * Additional WHERE clauses can be added by $where (fx. ' AND blabla = 1')
103 * Will automatically check if records has been deleted and if so, not return anything.
104 * $table must be found in $GLOBALS['TCA']
105 *
106 * @param string $table Table name present in $GLOBALS['TCA']
107 * @param int $uid UID of record
108 * @param string $fields List of fields to select
109 * @param string $where Additional WHERE clause, eg. " AND blablabla = 0
110 * @param bool $useDeleteClause Use the deleteClause to check if a record is deleted (default TRUE)
111 * @return array|null Returns the row if found, otherwise NULL
112 */
113 public static function getRecord($table, $uid, $fields = '*', $where = '', $useDeleteClause = true)
114 {
115 // Ensure we have a valid uid (not 0 and not NEWxxxx) and a valid TCA
116 if ((int)$uid && !empty($GLOBALS['TCA'][$table])) {
117 $queryBuilder = static::getQueryBuilderForTable($table);
118
119 // do not use enabled fields here
120 $queryBuilder->getRestrictions()->removeAll();
121
122 // should the delete clause be used
123 if ($useDeleteClause) {
124 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
125 }
126
127 // set table and where clause
128 $queryBuilder
129 ->select(...GeneralUtility::trimExplode(',', $fields, true))
130 ->from($table)
131 ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter((int)$uid, \PDO::PARAM_INT)));
132
133 // add custom where clause
134 if ($where) {
135 $queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($where));
136 }
137
138 $row = $queryBuilder->execute()->fetch();
139 if ($row) {
140 return $row;
141 }
142 }
143 return null;
144 }
145
146 /**
147 * Like getRecord(), but overlays workspace version if any.
148 *
149 * @param string $table Table name present in $GLOBALS['TCA']
150 * @param int $uid UID of record
151 * @param string $fields List of fields to select
152 * @param string $where Additional WHERE clause, eg. " AND blablabla = 0
153 * @param bool $useDeleteClause Use the deleteClause to check if a record is deleted (default TRUE)
154 * @param bool $unsetMovePointers If TRUE the function does not return a "pointer" row for moved records in a workspace
155 * @return array Returns the row if found, otherwise nothing
156 */
157 public static function getRecordWSOL(
158 $table,
159 $uid,
160 $fields = '*',
161 $where = '',
162 $useDeleteClause = true,
163 $unsetMovePointers = false
164 ) {
165 if ($fields !== '*') {
166 $internalFields = GeneralUtility::uniqueList($fields . ',uid,pid');
167 $row = self::getRecord($table, $uid, $internalFields, $where, $useDeleteClause);
168 self::workspaceOL($table, $row, -99, $unsetMovePointers);
169 if (is_array($row)) {
170 foreach ($row as $key => $_) {
171 if (!GeneralUtility::inList($fields, $key) && $key[0] !== '_') {
172 unset($row[$key]);
173 }
174 }
175 }
176 } else {
177 $row = self::getRecord($table, $uid, $fields, $where, $useDeleteClause);
178 self::workspaceOL($table, $row, -99, $unsetMovePointers);
179 }
180 return $row;
181 }
182
183 /**
184 * Returns the first record found from $table with $where as WHERE clause
185 * This function does NOT check if a record has the deleted flag set.
186 * $table does NOT need to be configured in $GLOBALS['TCA']
187 * The query used is simply this:
188 * $query = 'SELECT ' . $fields . ' FROM ' . $table . ' WHERE ' . $where;
189 *
190 * @param string $table Table name (not necessarily in TCA)
191 * @param string $where WHERE clause
192 * @param string $fields $fields is a list of fields to select, default is '*'
193 * @return array|bool First row found, if any, FALSE otherwise
194 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
195 */
196 public static function getRecordRaw($table, $where = '', $fields = '*')
197 {
198 GeneralUtility::logDeprecatedFunction();
199 $queryBuilder = static::getQueryBuilderForTable($table);
200 $queryBuilder->getRestrictions()->removeAll();
201
202 $row = $queryBuilder
203 ->select(...GeneralUtility::trimExplode(',', $fields, true))
204 ->from($table)
205 ->where(QueryHelper::stripLogicalOperatorPrefix($where))
206 ->execute()
207 ->fetch();
208
209 return $row ?: false;
210 }
211
212 /**
213 * Returns records from table, $theTable, where a field ($theField) equals the value, $theValue
214 * The records are returned in an array
215 * If no records were selected, the function returns nothing
216 *
217 * @param string $theTable Table name present in $GLOBALS['TCA']
218 * @param string $theField Field to select on
219 * @param string $theValue Value that $theField must match
220 * @param string $whereClause Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
221 * @param string $groupBy Optional GROUP BY field(s), if none, supply blank string.
222 * @param string $orderBy Optional ORDER BY field(s), if none, supply blank string.
223 * @param string $limit Optional LIMIT value ([begin,]max), if none, supply blank string.
224 * @param bool $useDeleteClause Use the deleteClause to check if a record is deleted (default TRUE)
225 * @param QueryBuilder|null $queryBuilder The queryBuilder must be provided, if the parameter $whereClause is given and the concept of prepared statement was used. Example within self::firstDomainRecord()
226 * @return mixed Multidimensional array with selected records (if any is selected)
227 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
228 */
229 public static function getRecordsByField(
230 $theTable,
231 $theField,
232 $theValue,
233 $whereClause = '',
234 $groupBy = '',
235 $orderBy = '',
236 $limit = '',
237 $useDeleteClause = true,
238 $queryBuilder = null
239 ) {
240 GeneralUtility::logDeprecatedFunction();
241 if (is_array($GLOBALS['TCA'][$theTable])) {
242 if (null === $queryBuilder) {
243 $queryBuilder = static::getQueryBuilderForTable($theTable);
244 }
245
246 // Show all records except versioning placeholders
247 $queryBuilder->getRestrictions()
248 ->removeAll()
249 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
250
251 // Remove deleted records from the query result
252 if ($useDeleteClause) {
253 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
254 }
255
256 // build fields to select
257 $queryBuilder
258 ->select('*')
259 ->from($theTable)
260 ->where($queryBuilder->expr()->eq($theField, $queryBuilder->createNamedParameter($theValue)));
261
262 // additional where
263 if ($whereClause) {
264 $queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($whereClause));
265 }
266
267 // group by
268 if ($groupBy !== '') {
269 $queryBuilder->groupBy(QueryHelper::parseGroupBy($groupBy));
270 }
271
272 // order by
273 if ($orderBy !== '') {
274 foreach (QueryHelper::parseOrderBy($orderBy) as $orderPair) {
275 list($fieldName, $order) = $orderPair;
276 $queryBuilder->addOrderBy($fieldName, $order);
277 }
278 }
279
280 // limit
281 if ($limit !== '') {
282 if (strpos($limit, ',')) {
283 $limitOffsetAndMax = GeneralUtility::intExplode(',', $limit);
284 $queryBuilder->setFirstResult((int)$limitOffsetAndMax[0]);
285 $queryBuilder->setMaxResults((int)$limitOffsetAndMax[1]);
286 } else {
287 $queryBuilder->setMaxResults((int)$limit);
288 }
289 }
290
291 $rows = $queryBuilder->execute()->fetchAll();
292 return $rows;
293 }
294 return null;
295 }
296
297 /**
298 * Purges computed properties starting with underscore character ('_').
299 *
300 * @param array $record
301 * @return array
302 */
303 public static function purgeComputedPropertiesFromRecord(array $record): array
304 {
305 return array_filter(
306 $record,
307 function (string $propertyName): bool {
308 return $propertyName[0] !== '_';
309 },
310 ARRAY_FILTER_USE_KEY
311 );
312 }
313
314 /**
315 * Purges computed property names starting with underscore character ('_').
316 *
317 * @param array $propertyNames
318 * @return array
319 */
320 public static function purgeComputedPropertyNames(array $propertyNames): array
321 {
322 return array_filter(
323 $propertyNames,
324 function (string $propertyName): bool {
325 return $propertyName[0] !== '_';
326 }
327 );
328 }
329
330 /**
331 * Makes an backwards explode on the $str and returns an array with ($table, $uid).
332 * Example: tt_content_45 => array('tt_content', 45)
333 *
334 * @param string $str [tablename]_[uid] string to explode
335 * @return array
336 */
337 public static function splitTable_Uid($str)
338 {
339 list($uid, $table) = explode('_', strrev($str), 2);
340 return [strrev($table), strrev($uid)];
341 }
342
343 /**
344 * Returns a list of pure ints based on $in_list being a list of records with table-names prepended.
345 * Ex: $in_list = "pages_4,tt_content_12,45" would result in a return value of "4,45" if $tablename is "pages" and $default_tablename is 'pages' as well.
346 *
347 * @param string $in_list Input list
348 * @param string $tablename Table name from which ids is returned
349 * @param string $default_tablename $default_tablename denotes what table the number '45' is from (if nothing is prepended on the value)
350 * @return string List of ids
351 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
352 */
353 public static function getSQLselectableList($in_list, $tablename, $default_tablename)
354 {
355 GeneralUtility::logDeprecatedFunction();
356 $list = [];
357 if ((string)trim($in_list) != '') {
358 $tempItemArray = explode(',', trim($in_list));
359 foreach ($tempItemArray as $key => $val) {
360 $val = strrev($val);
361 $parts = explode('_', $val, 2);
362 if ((string)trim($parts[0]) != '') {
363 $theID = (int)strrev($parts[0]);
364 $theTable = trim($parts[1]) ? strrev(trim($parts[1])) : $default_tablename;
365 if ($theTable == $tablename) {
366 $list[] = $theID;
367 }
368 }
369 }
370 }
371 return implode(',', $list);
372 }
373
374 /**
375 * Backend implementation of enableFields()
376 * Notice that "fe_groups" is not selected for - only disabled, starttime and endtime.
377 * Notice that deleted-fields are NOT filtered - you must ALSO call deleteClause in addition.
378 * $GLOBALS["SIM_ACCESS_TIME"] is used for date.
379 *
380 * @param string $table The table from which to return enableFields WHERE clause. Table name must have a 'ctrl' section in $GLOBALS['TCA'].
381 * @param bool $inv Means that the query will select all records NOT VISIBLE records (inverted selection)
382 * @return string WHERE clause part
383 */
384 public static function BEenableFields($table, $inv = false)
385 {
386 $ctrl = $GLOBALS['TCA'][$table]['ctrl'];
387 $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
388 ->getConnectionForTable($table)
389 ->getExpressionBuilder();
390 $query = $expressionBuilder->andX();
391 $invQuery = $expressionBuilder->orX();
392
393 if (is_array($ctrl)) {
394 if (is_array($ctrl['enablecolumns'])) {
395 if ($ctrl['enablecolumns']['disabled']) {
396 $field = $table . '.' . $ctrl['enablecolumns']['disabled'];
397 $query->add($expressionBuilder->eq($field, 0));
398 $invQuery->add($expressionBuilder->neq($field, 0));
399 }
400 if ($ctrl['enablecolumns']['starttime']) {
401 $field = $table . '.' . $ctrl['enablecolumns']['starttime'];
402 $query->add($expressionBuilder->lte($field, (int)$GLOBALS['SIM_ACCESS_TIME']));
403 $invQuery->add(
404 $expressionBuilder->andX(
405 $expressionBuilder->neq($field, 0),
406 $expressionBuilder->gt($field, (int)$GLOBALS['SIM_ACCESS_TIME'])
407 )
408 );
409 }
410 if ($ctrl['enablecolumns']['endtime']) {
411 $field = $table . '.' . $ctrl['enablecolumns']['endtime'];
412 $query->add(
413 $expressionBuilder->orX(
414 $expressionBuilder->eq($field, 0),
415 $expressionBuilder->gt($field, (int)$GLOBALS['SIM_ACCESS_TIME'])
416 )
417 );
418 $invQuery->add(
419 $expressionBuilder->andX(
420 $expressionBuilder->neq($field, 0),
421 $expressionBuilder->lte($field, (int)$GLOBALS['SIM_ACCESS_TIME'])
422 )
423 );
424 }
425 }
426 }
427
428 if ($query->count() === 0) {
429 return '';
430 }
431
432 return ' AND ' . ($inv ? $invQuery : $query);
433 }
434
435 /**
436 * Fetches the localization for a given record.
437 *
438 * @param string $table Table name present in $GLOBALS['TCA']
439 * @param int $uid The uid of the record
440 * @param int $language The uid of the language record in sys_language
441 * @param string $andWhereClause Optional additional WHERE clause (default: '')
442 * @return mixed Multidimensional array with selected records; if none exist, FALSE is returned
443 */
444 public static function getRecordLocalization($table, $uid, $language, $andWhereClause = '')
445 {
446 $recordLocalization = false;
447
448 // Pages still stores translations in the pages_language_overlay table, all other tables store in themself
449 if ($table === 'pages') {
450 $table = 'pages_language_overlay';
451 }
452
453 if (self::isTableLocalizable($table)) {
454 $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
455
456 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
457 ->getQueryBuilderForTable($table);
458 $queryBuilder->getRestrictions()
459 ->removeAll()
460 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
461 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
462
463 $queryBuilder->select('*')
464 ->from($table)
465 ->where(
466 $queryBuilder->expr()->eq(
467 $tcaCtrl['translationSource'] ?? $tcaCtrl['transOrigPointerField'],
468 $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
469 ),
470 $queryBuilder->expr()->eq(
471 $tcaCtrl['languageField'],
472 $queryBuilder->createNamedParameter((int)$language, \PDO::PARAM_INT)
473 )
474 )
475 ->setMaxResults(1);
476
477 if ($andWhereClause) {
478 $queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($andWhereClause));
479 }
480
481 $recordLocalization = $queryBuilder->execute()->fetchAll();
482 }
483
484 return $recordLocalization;
485 }
486
487 /*******************************************
488 *
489 * Page tree, TCA related
490 *
491 *******************************************/
492 /**
493 * Returns what is called the 'RootLine'. That is an array with information about the page records from a page id
494 * ($uid) and back to the root.
495 * By default deleted pages are filtered.
496 * This RootLine will follow the tree all the way to the root. This is opposite to another kind of root line known
497 * from the frontend where the rootline stops when a root-template is found.
498 *
499 * @param int $uid Page id for which to create the root line.
500 * @param string $clause Clause can be used to select other criteria. It would typically be where-clauses that
501 * stops the process if we meet a page, the user has no reading access to.
502 * @param bool $workspaceOL If TRUE, version overlay is applied. This must be requested specifically because it is
503 * usually only wanted when the rootline is used for visual output while for permission checking you want the raw thing!
504 * @return array Root line array, all the way to the page tree root (or as far as $clause allows!)
505 */
506 public static function BEgetRootLine($uid, $clause = '', $workspaceOL = false)
507 {
508 static $BEgetRootLine_cache = [];
509 $output = [];
510 $pid = $uid;
511 $ident = $pid . '-' . $clause . '-' . $workspaceOL;
512 if (is_array($BEgetRootLine_cache[$ident] ?? false)) {
513 $output = $BEgetRootLine_cache[$ident];
514 } else {
515 $loopCheck = 100;
516 $theRowArray = [];
517 while ($uid != 0 && $loopCheck) {
518 $loopCheck--;
519 $row = self::getPageForRootline($uid, $clause, $workspaceOL);
520 if (is_array($row)) {
521 $uid = $row['pid'];
522 $theRowArray[] = $row;
523 } else {
524 break;
525 }
526 }
527 if ($uid == 0) {
528 $theRowArray[] = ['uid' => 0, 'title' => ''];
529 }
530 $c = count($theRowArray);
531 foreach ($theRowArray as $val) {
532 $c--;
533 $output[$c] = [
534 'uid' => $val['uid'],
535 'pid' => $val['pid'],
536 'title' => $val['title'],
537 'doktype' => $val['doktype'],
538 'tsconfig_includes' => $val['tsconfig_includes'],
539 'TSconfig' => $val['TSconfig'],
540 'is_siteroot' => $val['is_siteroot'],
541 't3ver_oid' => $val['t3ver_oid'],
542 't3ver_wsid' => $val['t3ver_wsid'],
543 't3ver_state' => $val['t3ver_state'],
544 't3ver_stage' => $val['t3ver_stage'],
545 'backend_layout_next_level' => $val['backend_layout_next_level']
546 ];
547 if (isset($val['_ORIG_pid'])) {
548 $output[$c]['_ORIG_pid'] = $val['_ORIG_pid'];
549 }
550 }
551 $BEgetRootLine_cache[$ident] = $output;
552 }
553 return $output;
554 }
555
556 /**
557 * Gets the cached page record for the rootline
558 *
559 * @param int $uid Page id for which to create the root line.
560 * @param string $clause Clause can be used to select other criteria. It would typically be where-clauses that stops the process if we meet a page, the user has no reading access to.
561 * @param bool $workspaceOL If TRUE, version overlay is applied. This must be requested specifically because it is usually only wanted when the rootline is used for visual output while for permission checking you want the raw thing!
562 * @return array Cached page record for the rootline
563 * @see BEgetRootLine
564 */
565 protected static function getPageForRootline($uid, $clause, $workspaceOL)
566 {
567 static $getPageForRootline_cache = [];
568 $ident = $uid . '-' . $clause . '-' . $workspaceOL;
569 if (is_array($getPageForRootline_cache[$ident] ?? false)) {
570 $row = $getPageForRootline_cache[$ident];
571 } else {
572 $queryBuilder = static::getQueryBuilderForTable('pages');
573 $queryBuilder->getRestrictions()
574 ->removeAll()
575 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
576
577 $row = $queryBuilder
578 ->select(
579 'pid',
580 'uid',
581 'title',
582 'doktype',
583 'tsconfig_includes',
584 'TSconfig',
585 'is_siteroot',
586 't3ver_oid',
587 't3ver_wsid',
588 't3ver_state',
589 't3ver_stage',
590 'backend_layout_next_level'
591 )
592 ->from('pages')
593 ->where(
594 $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)),
595 QueryHelper::stripLogicalOperatorPrefix($clause)
596 )
597 ->execute()
598 ->fetch();
599
600 if ($row) {
601 $newLocation = false;
602 if ($workspaceOL) {
603 self::workspaceOL('pages', $row);
604 $newLocation = self::getMovePlaceholder('pages', $row['uid'], 'pid');
605 }
606 if (is_array($row)) {
607 if ($newLocation !== false) {
608 $row['pid'] = $newLocation['pid'];
609 } else {
610 self::fixVersioningPid('pages', $row);
611 }
612 $getPageForRootline_cache[$ident] = $row;
613 }
614 }
615 }
616 return $row;
617 }
618
619 /**
620 * Opens the page tree to the specified page id
621 *
622 * @param int $pid Page id.
623 * @param bool $clearExpansion If set, then other open branches are closed.
624 */
625 public static function openPageTree($pid, $clearExpansion)
626 {
627 $beUser = static::getBackendUserAuthentication();
628 // Get current expansion data:
629 if ($clearExpansion) {
630 $expandedPages = [];
631 } else {
632 $expandedPages = unserialize($beUser->uc['browseTrees']['browsePages']);
633 }
634 // Get rootline:
635 $rL = self::BEgetRootLine($pid);
636 // First, find out what mount index to use (if more than one DB mount exists):
637 $mountIndex = 0;
638 $mountKeys = array_flip($beUser->returnWebmounts());
639 foreach ($rL as $rLDat) {
640 if (isset($mountKeys[$rLDat['uid']])) {
641 $mountIndex = $mountKeys[$rLDat['uid']];
642 break;
643 }
644 }
645 // Traverse rootline and open paths:
646 foreach ($rL as $rLDat) {
647 $expandedPages[$mountIndex][$rLDat['uid']] = 1;
648 }
649 // Write back:
650 $beUser->uc['browseTrees']['browsePages'] = serialize($expandedPages);
651 $beUser->writeUC();
652 }
653
654 /**
655 * Returns the path (visually) of a page $uid, fx. "/First page/Second page/Another subpage"
656 * Each part of the path will be limited to $titleLimit characters
657 * Deleted pages are filtered out.
658 *
659 * @param int $uid Page uid for which to create record path
660 * @param string $clause Clause is additional where clauses, eg.
661 * @param int $titleLimit Title limit
662 * @param int $fullTitleLimit Title limit of Full title (typ. set to 1000 or so)
663 * @return mixed Path of record (string) OR array with short/long title if $fullTitleLimit is set.
664 */
665 public static function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit = 0)
666 {
667 if (!$titleLimit) {
668 $titleLimit = 1000;
669 }
670 $output = $fullOutput = '/';
671 $clause = trim($clause);
672 if ($clause !== '' && substr($clause, 0, 3) !== 'AND') {
673 $clause = 'AND ' . $clause;
674 }
675 $data = self::BEgetRootLine($uid, $clause);
676 foreach ($data as $record) {
677 if ($record['uid'] === 0) {
678 continue;
679 }
680 $output = '/' . GeneralUtility::fixed_lgd_cs(strip_tags($record['title']), $titleLimit) . $output;
681 if ($fullTitleLimit) {
682 $fullOutput = '/' . GeneralUtility::fixed_lgd_cs(strip_tags($record['title']), $fullTitleLimit) . $fullOutput;
683 }
684 }
685 if ($fullTitleLimit) {
686 return [$output, $fullOutput];
687 }
688 return $output;
689 }
690
691 /**
692 * Gets the original translation pointer table.
693 * That is now the same table, apart from pages_language_overlay
694 * where pages is the original.
695 *
696 * @param string $table Name of the table
697 * @return string Pointer table (if any)
698 */
699 public static function getOriginalTranslationTable($table)
700 {
701 return $table === 'pages_language_overlay' ? 'pages' : $table;
702 }
703
704 /**
705 * Determines whether a table is localizable and has the languageField and transOrigPointerField set in $GLOBALS['TCA'].
706 *
707 * @param string $table The table to check
708 * @return bool Whether a table is localizable
709 */
710 public static function isTableLocalizable($table)
711 {
712 $isLocalizable = false;
713 if (isset($GLOBALS['TCA'][$table]['ctrl']) && is_array($GLOBALS['TCA'][$table]['ctrl'])) {
714 $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
715 $isLocalizable = isset($tcaCtrl['languageField']) && $tcaCtrl['languageField'] && isset($tcaCtrl['transOrigPointerField']) && $tcaCtrl['transOrigPointerField'];
716 }
717 return $isLocalizable;
718 }
719
720 /**
721 * Returns the value of the property localizationMode in the given $config array ($GLOBALS['TCA'][<table>]['columns'][<field>]['config']).
722 * If the table is prepared for localization and no localizationMode is set, 'select' is returned by default.
723 * If the table is not prepared for localization or not defined at all in $GLOBALS['TCA'], FALSE is returned.
724 *
725 * @param string $table The name of the table to lookup in TCA
726 * @param mixed $fieldOrConfig The fieldname (string) or the configuration of the field to check (array)
727 * @return mixed If table is localizable, the set localizationMode is returned (if property is not set, 'select' is returned by default); if table is not localizable, FALSE is returned
728 * @deprecated: IRRE 'localizationMode' is deprecated and will be removed in TYPO3 CMS 9, migrate to l10n_mode or allowLanguageSynchronization
729 */
730 public static function getInlineLocalizationMode($table, $fieldOrConfig)
731 {
732 $localizationMode = false;
733 $config = null;
734 if (is_array($fieldOrConfig) && !empty($fieldOrConfig)) {
735 $config = $fieldOrConfig;
736 } elseif (is_string($fieldOrConfig) && isset($GLOBALS['TCA'][$table]['columns'][$fieldOrConfig]['config'])) {
737 $config = $GLOBALS['TCA'][$table]['columns'][$fieldOrConfig]['config'];
738 }
739 if (is_array($config) && isset($config['type']) && $config['type'] === 'inline' && self::isTableLocalizable($table)) {
740 $localizationMode = isset($config['behaviour']['localizationMode']) && $config['behaviour']['localizationMode']
741 ? $config['behaviour']['localizationMode']
742 : 'select';
743 // The mode 'select' is not possible when child table is not localizable at all:
744 if ($localizationMode === 'select' && !self::isTableLocalizable($config['foreign_table'])) {
745 $localizationMode = false;
746 }
747 }
748 return $localizationMode;
749 }
750
751 /**
752 * Returns a page record (of page with $id) with an extra field "_thePath" set to the record path IF the WHERE clause, $perms_clause, selects the record. Thus is works as an access check that returns a page record if access was granted, otherwise not.
753 * If $id is zero a pseudo root-page with "_thePath" set is returned IF the current BE_USER is admin.
754 * In any case ->isInWebMount must return TRUE for the user (regardless of $perms_clause)
755 *
756 * @param int $id Page uid for which to check read-access
757 * @param string $perms_clause This is typically a value generated with static::getBackendUserAuthentication()->getPagePermsClause(1);
758 * @return array|bool Returns page record if OK, otherwise FALSE.
759 */
760 public static function readPageAccess($id, $perms_clause)
761 {
762 if ((string)$id !== '') {
763 $id = (int)$id;
764 if (!$id) {
765 if (static::getBackendUserAuthentication()->isAdmin()) {
766 $path = '/';
767 $pageinfo['_thePath'] = $path;
768 return $pageinfo;
769 }
770 } else {
771 $pageinfo = self::getRecord('pages', $id, '*', $perms_clause);
772 if ($pageinfo['uid'] && static::getBackendUserAuthentication()->isInWebMount($id, $perms_clause)) {
773 self::workspaceOL('pages', $pageinfo);
774 if (is_array($pageinfo)) {
775 self::fixVersioningPid('pages', $pageinfo);
776 list($pageinfo['_thePath'], $pageinfo['_thePathFull']) = self::getRecordPath((int)$pageinfo['uid'], $perms_clause, 15, 1000);
777 return $pageinfo;
778 }
779 }
780 }
781 }
782 return false;
783 }
784
785 /**
786 * Returns the "types" configuration parsed into an array for the record, $rec, from table, $table
787 *
788 * @param string $table Table name (present in TCA)
789 * @param array $rec Record from $table
790 * @param bool $useFieldNameAsKey If $useFieldNameAsKey is set, then the fieldname is associative keys in the return array, otherwise just numeric keys.
791 * @return array|null
792 */
793 public static function getTCAtypes($table, $rec, $useFieldNameAsKey = false)
794 {
795 if ($GLOBALS['TCA'][$table]) {
796 // Get type value:
797 $fieldValue = self::getTCAtypeValue($table, $rec);
798 $cacheIdentifier = $table . '-type-' . $fieldValue . '-fnk-' . $useFieldNameAsKey;
799
800 // Fetch from first-level-cache if available
801 if (isset(self::$tcaTableTypeConfigurationCache[$cacheIdentifier])) {
802 return self::$tcaTableTypeConfigurationCache[$cacheIdentifier];
803 }
804
805 // Get typesConf
806 $typesConf = $GLOBALS['TCA'][$table]['types'][$fieldValue];
807 // Get fields list and traverse it
808 $fieldList = explode(',', $typesConf['showitem']);
809
810 // Add subtype fields e.g. for a valid RTE transformation
811 // The RTE runs the DB -> RTE transformation only, if the RTE field is part of the getTCAtypes array
812 if (isset($typesConf['subtype_value_field'])) {
813 $subType = $rec[$typesConf['subtype_value_field']];
814 if (isset($typesConf['subtypes_addlist'][$subType])) {
815 $subFields = GeneralUtility::trimExplode(',', $typesConf['subtypes_addlist'][$subType], true);
816 $fieldList = array_merge($fieldList, $subFields);
817 }
818 }
819
820 // Add palette fields e.g. for a valid RTE transformation
821 $paletteFieldList = [];
822 foreach ($fieldList as $fieldData) {
823 list($pFieldName, $pAltTitle, $pPalette) = GeneralUtility::trimExplode(';', $fieldData);
824 if ($pPalette
825 && isset($GLOBALS['TCA'][$table]['palettes'][$pPalette])
826 && is_array($GLOBALS['TCA'][$table]['palettes'][$pPalette])
827 && isset($GLOBALS['TCA'][$table]['palettes'][$pPalette]['showitem'])
828 ) {
829 $paletteFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['palettes'][$pPalette]['showitem'], true);
830 foreach ($paletteFields as $paletteField) {
831 if ($paletteField !== '--linebreak--') {
832 $paletteFieldList[] = $paletteField;
833 }
834 }
835 }
836 }
837 $fieldList = array_merge($fieldList, $paletteFieldList);
838
839 $altFieldList = [];
840 // Traverse fields in types config and parse the configuration into a nice array:
841 foreach ($fieldList as $k => $v) {
842 list($pFieldName, $pAltTitle, $pPalette) = GeneralUtility::trimExplode(';', $v);
843 $fieldList[$k] = [
844 'field' => $pFieldName,
845 'title' => $pAltTitle,
846 'palette' => $pPalette,
847 'spec' => [],
848 'origString' => $v
849 ];
850 if ($useFieldNameAsKey) {
851 $altFieldList[$fieldList[$k]['field']] = $fieldList[$k];
852 }
853 }
854 if ($useFieldNameAsKey) {
855 $fieldList = $altFieldList;
856 }
857
858 // Add to first-level-cache
859 self::$tcaTableTypeConfigurationCache[$cacheIdentifier] = $fieldList;
860
861 // Return array:
862 return $fieldList;
863 }
864 return null;
865 }
866
867 /**
868 * Returns the "type" value of $rec from $table which can be used to look up the correct "types" rendering section in $GLOBALS['TCA']
869 * If no "type" field is configured in the "ctrl"-section of the $GLOBALS['TCA'] for the table, zero is used.
870 * If zero is not an index in the "types" section of $GLOBALS['TCA'] for the table, then the $fieldValue returned will default to 1 (no matter if that is an index or not)
871 *
872 * Note: This method is very similar to the type determination of FormDataProvider/DatabaseRecordTypeValue,
873 * however, it has two differences:
874 * 1) The method in TCEForms also takes care of localization (which is difficult to do here as the whole infrastructure for language overlays is only in TCEforms).
875 * 2) The $row array looks different in TCEForms, as in there it's not the raw record but the prepared data from other providers is handled, which changes e.g. how "select"
876 * and "group" field values are stored, which makes different processing of the "foreign pointer field" type field variant necessary.
877 *
878 * @param string $table Table name present in TCA
879 * @param array $row Record from $table
880 * @throws \RuntimeException
881 * @return string Field value
882 * @see getTCAtypes()
883 */
884 public static function getTCAtypeValue($table, $row)
885 {
886 $typeNum = 0;
887 if ($GLOBALS['TCA'][$table]) {
888 $field = $GLOBALS['TCA'][$table]['ctrl']['type'];
889 if (strpos($field, ':') !== false) {
890 list($pointerField, $foreignTableTypeField) = explode(':', $field);
891 // Get field value from database if field is not in the $row array
892 if (!isset($row[$pointerField])) {
893 $localRow = self::getRecord($table, $row['uid'], $pointerField);
894 $foreignUid = $localRow[$pointerField];
895 } else {
896 $foreignUid = $row[$pointerField];
897 }
898 if ($foreignUid) {
899 $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$pointerField]['config'];
900 $relationType = $fieldConfig['type'];
901 if ($relationType === 'select') {
902 $foreignTable = $fieldConfig['foreign_table'];
903 } elseif ($relationType === 'group') {
904 $allowedTables = explode(',', $fieldConfig['allowed']);
905 $foreignTable = $allowedTables[0];
906 } else {
907 throw new \RuntimeException(
908 'TCA foreign field pointer fields are only allowed to be used with group or select field types.',
909 1325862240
910 );
911 }
912 $foreignRow = self::getRecord($foreignTable, $foreignUid, $foreignTableTypeField);
913 if ($foreignRow[$foreignTableTypeField]) {
914 $typeNum = $foreignRow[$foreignTableTypeField];
915 }
916 }
917 } else {
918 $typeNum = $row[$field];
919 }
920 // If that value is an empty string, set it to "0" (zero)
921 if (empty($typeNum)) {
922 $typeNum = 0;
923 }
924 }
925 // If current typeNum doesn't exist, set it to 0 (or to 1 for historical reasons, if 0 doesn't exist)
926 if (!$GLOBALS['TCA'][$table]['types'][$typeNum]) {
927 $typeNum = $GLOBALS['TCA'][$table]['types']['0'] ? 0 : 1;
928 }
929 // Force to string. Necessary for eg '-1' to be recognized as a type value.
930 $typeNum = (string)$typeNum;
931 return $typeNum;
932 }
933
934 /**
935 * Parses "defaultExtras" of $GLOBALS['TCA'] columns config section to an array.
936 * Elements are split by ":" and within those parts, parameters are split by "|".
937 *
938 * See unit tests for details.
939 *
940 * @param string $defaultExtrasString "defaultExtras" string from columns config
941 * @return array
942 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
943 */
944 public static function getSpecConfParts($defaultExtrasString)
945 {
946 GeneralUtility::logDeprecatedFunction();
947 $specConfParts = GeneralUtility::trimExplode(':', $defaultExtrasString, true);
948 $reg = [];
949 if (!empty($specConfParts)) {
950 foreach ($specConfParts as $k2 => $v2) {
951 unset($specConfParts[$k2]);
952 if (preg_match('/(.*)\\[(.*)\\]/', $v2, $reg)) {
953 $specConfParts[trim($reg[1])] = [
954 'parameters' => GeneralUtility::trimExplode('|', $reg[2], true)
955 ];
956 } else {
957 $specConfParts[trim($v2)] = 1;
958 }
959 }
960 } else {
961 $specConfParts = [];
962 }
963 return $specConfParts;
964 }
965
966 /**
967 * Takes an array of "[key] = [value]" strings and returns an array with the keys set as keys pointing to the value.
968 * Better see it in action! Find example in Inside TYPO3
969 *
970 * @param array $pArr Array of "[key] = [value]" strings to convert.
971 * @return array
972 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
973 */
974 public static function getSpecConfParametersFromArray($pArr)
975 {
976 GeneralUtility::logDeprecatedFunction();
977 $out = [];
978 if (is_array($pArr)) {
979 foreach ($pArr as $k => $v) {
980 $parts = explode('=', $v, 2);
981 if (count($parts) === 2) {
982 $out[trim($parts[0])] = trim($parts[1]);
983 } else {
984 $out[$k] = $v;
985 }
986 }
987 }
988 return $out;
989 }
990
991 /**
992 * Finds the Data Structure for a FlexForm field
993 *
994 * NOTE ON data structures for deleted records: This function may fail to deliver the data structure
995 * for a record for a few reasons:
996 * a) The data structure could be deleted (either with deleted-flagged or hard-deleted),
997 * b) the data structure is fetched using the ds_pointerField_searchParent in which case any
998 * deleted record on the route to the final location of the DS will make it fail.
999 * In theory, we can solve the problem in the case where records that are deleted-flagged keeps us
1000 * from finding the DS - this is done at the markers ###NOTE_A### where we make sure to also select deleted records.
1001 * However, we generally want the DS lookup to fail for deleted records since for the working website we expect a
1002 * deleted-flagged record to be as inaccessible as one that is completely deleted from the DB. Any way we look
1003 * at it, this may lead to integrity problems of the reference index and even lost files if attached.
1004 * However, that is not really important considering that a single change to a data structure can instantly
1005 * invalidate large amounts of the reference index which we do accept as a cost for the flexform features.
1006 * Other than requiring a reference index update, deletion of/changes in data structure or the failure to look
1007 * them up when completely deleting records may lead to lost files in the uploads/ folders since those are now
1008 * without a proper reference.
1009 *
1010 * @param array $conf Field config array
1011 * @param array $row Record data
1012 * @param string $table The table name
1013 * @param string $fieldName Optional fieldname passed to hook object
1014 * @param bool $WSOL If set, workspace overlay is applied to records. This is correct behaviour for all presentation and export, but NOT if you want a TRUE reflection of how things are in the live workspace.
1015 * @param int $newRecordPidValue SPECIAL CASES: Use this, if the DataStructure may come from a parent record and the INPUT row doesn't have a uid yet (hence, the pid cannot be looked up). Then it is necessary to supply a PID value to search recursively in for the DS (used from DataHandler)
1016 * @return mixed If array, the data structure was found and returned as an array. Otherwise (string) it is an error message.
1017 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9. This is now integrated as FlexFormTools->getDataStructureIdentifier()
1018 */
1019 public static function getFlexFormDS($conf, $row, $table, $fieldName = '', $WSOL = true, $newRecordPidValue = 0)
1020 {
1021 GeneralUtility::logDeprecatedFunction();
1022 // Get pointer field etc from TCA-config:
1023 $ds_pointerField = $conf['ds_pointerField'];
1024 $ds_array = $conf['ds'];
1025 $ds_tableField = $conf['ds_tableField'];
1026 $ds_searchParentField = $conf['ds_pointerField_searchParent'];
1027 // If there is a data source array, that takes precedence
1028 if (is_array($ds_array)) {
1029 // If a pointer field is set, take the value from that field in the $row array and use as key.
1030 if ($ds_pointerField) {
1031 // Up to two pointer fields can be specified in a comma separated list.
1032 $pointerFields = GeneralUtility::trimExplode(',', $ds_pointerField);
1033 // If we have two pointer fields, the array keys should contain both field values separated by comma.
1034 // The asterisk "*" catches all values. For backwards compatibility, it's also possible to specify only
1035 // the value of the first defined ds_pointerField.
1036 if (count($pointerFields) === 2) {
1037 if ($ds_array[$row[$pointerFields[0]] . ',' . $row[$pointerFields[1]]]) {
1038 // Check if we have a DS for the combination of both pointer fields values
1039 $srcPointer = $row[$pointerFields[0]] . ',' . $row[$pointerFields[1]];
1040 } elseif ($ds_array[$row[$pointerFields[1]] . ',*']) {
1041 // Check if we have a DS for the value of the first pointer field suffixed with ",*"
1042 $srcPointer = $row[$pointerFields[1]] . ',*';
1043 } elseif ($ds_array['*,' . $row[$pointerFields[1]]]) {
1044 // Check if we have a DS for the value of the second pointer field prefixed with "*,"
1045 $srcPointer = '*,' . $row[$pointerFields[1]];
1046 } elseif ($ds_array[$row[$pointerFields[0]]]) {
1047 // Check if we have a DS for just the value of the first pointer field (mainly for backwards compatibility)
1048 $srcPointer = $row[$pointerFields[0]];
1049 } else {
1050 $srcPointer = null;
1051 }
1052 } else {
1053 $srcPointer = $row[$pointerFields[0]];
1054 }
1055 $srcPointer = $srcPointer !== null && isset($ds_array[$srcPointer]) ? $srcPointer : 'default';
1056 } else {
1057 $srcPointer = 'default';
1058 }
1059 // Get Data Source: Detect if it's a file reference and in that case read the file and parse as XML. Otherwise the value is expected to be XML.
1060 if (substr($ds_array[$srcPointer], 0, 5) === 'FILE:') {
1061 $file = GeneralUtility::getFileAbsFileName(substr($ds_array[$srcPointer], 5));
1062 if ($file && @is_file($file)) {
1063 $dataStructArray = GeneralUtility::xml2array(file_get_contents($file));
1064 } else {
1065 $dataStructArray = 'The file "' . substr($ds_array[$srcPointer], 5) . '" in ds-array key "' . $srcPointer . '" was not found ("' . $file . '")';
1066 }
1067 } else {
1068 $dataStructArray = GeneralUtility::xml2array($ds_array[$srcPointer]);
1069 }
1070 } elseif ($ds_pointerField) {
1071 // If pointer field AND possibly a table/field is set:
1072 // Value of field pointed to:
1073 $srcPointer = $row[$ds_pointerField];
1074 // Searching recursively back if 'ds_pointerField_searchParent' is defined (typ. a page rootline, or maybe a tree-table):
1075 if ($ds_searchParentField && !$srcPointer) {
1076 $rr = self::getRecord($table, $row['uid'], 'uid,' . $ds_searchParentField);
1077 // Get the "pid" field - we cannot know that it is in the input record! ###NOTE_A###
1078 if ($WSOL) {
1079 self::workspaceOL($table, $rr);
1080 self::fixVersioningPid($table, $rr, true);
1081 }
1082
1083 $queryBuilder = static::getQueryBuilderForTable($table);
1084 $queryBuilder->getRestrictions()
1085 ->removeAll()
1086 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
1087
1088 $uidAcc = [];
1089 // Used to avoid looping, if any should happen.
1090 $subFieldPointer = $conf['ds_pointerField_searchParent_subField'];
1091 while (!$srcPointer) {
1092 // select fields
1093 $queryBuilder
1094 ->select('uid', $ds_pointerField, $ds_searchParentField)
1095 ->from($table)
1096 ->where(
1097 $queryBuilder->expr()->eq(
1098 'uid',
1099 $queryBuilder->createNamedParameter(
1100 ($newRecordPidValue ?: $rr[$ds_searchParentField]),
1101 \PDO::PARAM_INT
1102 )
1103 )
1104 );
1105 if ($subFieldPointer) {
1106 $queryBuilder->addSelect($subFieldPointer);
1107 }
1108
1109 $rr = $queryBuilder->execute()->fetch();
1110
1111 $newRecordPidValue = 0;
1112 // Break if no result from SQL db or if looping...
1113 if (!is_array($rr) || isset($uidAcc[$rr['uid']])) {
1114 break;
1115 }
1116 $uidAcc[$rr['uid']] = 1;
1117 if ($WSOL) {
1118 self::workspaceOL($table, $rr);
1119 self::fixVersioningPid($table, $rr, true);
1120 }
1121 $srcPointer = $subFieldPointer && $rr[$subFieldPointer] ? $rr[$subFieldPointer] : $rr[$ds_pointerField];
1122 }
1123 }
1124 // If there is a srcPointer value:
1125 if ($srcPointer) {
1126 if (MathUtility::canBeInterpretedAsInteger($srcPointer)) {
1127 // If integer, then its a record we will look up:
1128 list($tName, $fName) = explode(':', $ds_tableField, 2);
1129 if ($tName && $fName && is_array($GLOBALS['TCA'][$tName])) {
1130 $dataStructRec = self::getRecord($tName, $srcPointer);
1131 if ($WSOL) {
1132 self::workspaceOL($tName, $dataStructRec);
1133 }
1134 if (strpos($dataStructRec[$fName], '<') === false) {
1135 if (is_file(PATH_site . $dataStructRec[$fName])) {
1136 // The value is a pointer to a file
1137 $dataStructArray = GeneralUtility::xml2array(file_get_contents(PATH_site . $dataStructRec[$fName]));
1138 } else {
1139 $dataStructArray = sprintf('File \'%s\' was not found', $dataStructRec[$fName]);
1140 }
1141 } else {
1142 // No file pointer, handle as being XML (default behaviour)
1143 $dataStructArray = GeneralUtility::xml2array($dataStructRec[$fName]);
1144 }
1145 } else {
1146 $dataStructArray = 'No tablename (' . $tName . ') or fieldname (' . $fName . ') was found an valid!';
1147 }
1148 } else {
1149 // Otherwise expect it to be a file:
1150 $file = GeneralUtility::getFileAbsFileName($srcPointer);
1151 if ($file && @is_file($file)) {
1152 $dataStructArray = GeneralUtility::xml2array(file_get_contents($file));
1153 } else {
1154 // Error message.
1155 $dataStructArray = 'The file "' . $srcPointer . '" was not found ("' . $file . '")';
1156 }
1157 }
1158 } else {
1159 // Error message.
1160 $dataStructArray = 'No source value in fieldname "' . $ds_pointerField . '"';
1161 }
1162 } else {
1163 $dataStructArray = 'No proper configuration!';
1164 }
1165 // Hook for post-processing the Flexform DS. Introduces the possibility to configure Flexforms via TSConfig
1166 // This hook isn't called anymore from within the core, the whole method is deprecated.
1167 // There are alternative hooks, see FlexFormTools->getDataStructureIdentifier() and ->parseDataStructureByIdentifier()
1168 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'])) {
1169 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'] as $classRef) {
1170 $hookObj = GeneralUtility::getUserObj($classRef);
1171 if (method_exists($hookObj, 'getFlexFormDS_postProcessDS')) {
1172 $hookObj->getFlexFormDS_postProcessDS($dataStructArray, $conf, $row, $table, $fieldName);
1173 }
1174 }
1175 }
1176 return $dataStructArray;
1177 }
1178
1179 /*******************************************
1180 *
1181 * Caching related
1182 *
1183 *******************************************/
1184 /**
1185 * Stores $data in the 'cache_hash' cache with the hash key, $hash
1186 * and visual/symbolic identification, $ident
1187 *
1188 * IDENTICAL to the function by same name found in \TYPO3\CMS\Frontend\Page\PageRepository
1189 *
1190 * @param string $hash 32 bit hash string (eg. a md5 hash of a serialized array identifying the data being stored)
1191 * @param mixed $data The data to store
1192 * @param string $ident $ident is just a textual identification in order to inform about the content!
1193 */
1194 public static function storeHash($hash, $data, $ident)
1195 {
1196 /** @var CacheManager $cacheManager */
1197 $cacheManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
1198 $cacheManager->getCache('cache_hash')->set($hash, $data, ['ident_' . $ident], 0);
1199 }
1200
1201 /**
1202 * Returns data stored for the hash string in the cache "cache_hash"
1203 * Can be used to retrieved a cached value, array or object
1204 *
1205 * IDENTICAL to the function by same name found in \TYPO3\CMS\Frontend\Page\PageRepository
1206 *
1207 * @param string $hash The hash-string which was used to store the data value
1208 * @return mixed The "data" from the cache
1209 */
1210 public static function getHash($hash)
1211 {
1212 /** @var CacheManager $cacheManager */
1213 $cacheManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
1214 $cacheEntry = $cacheManager->getCache('cache_hash')->get($hash);
1215 $hashContent = null;
1216 if ($cacheEntry) {
1217 $hashContent = $cacheEntry;
1218 }
1219 return $hashContent;
1220 }
1221
1222 /*******************************************
1223 *
1224 * TypoScript related
1225 *
1226 *******************************************/
1227 /**
1228 * Returns the Page TSconfig for page with id, $id
1229 *
1230 * @param int $id Page uid for which to create Page TSconfig
1231 * @param array $rootLine If $rootLine is an array, that is used as rootline, otherwise rootline is just calculated
1232 * @param bool $returnPartArray If $returnPartArray is set, then the array with accumulated Page TSconfig is returned non-parsed. Otherwise the output will be parsed by the TypoScript parser.
1233 * @return array Page TSconfig
1234 * @see \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
1235 */
1236 public static function getPagesTSconfig($id, $rootLine = null, $returnPartArray = false)
1237 {
1238 $id = (int)$id;
1239
1240 $cache = self::getRuntimeCache();
1241 if ($returnPartArray === false
1242 && $rootLine === null
1243 && $cache->has('pagesTsConfigIdToHash' . $id)
1244 ) {
1245 return $cache->get('pagesTsConfigHashToContent' . $cache->get('pagesTsConfigIdToHash' . $id));
1246 }
1247 $TSconfig = [];
1248 if (!is_array($rootLine)) {
1249 $useCacheForCurrentPageId = true;
1250 $rootLine = self::BEgetRootLine($id, '', true);
1251 } else {
1252 $useCacheForCurrentPageId = false;
1253 }
1254
1255 // Order correctly
1256 ksort($rootLine);
1257 $TSdataArray = [];
1258 // Setting default configuration
1259 $TSdataArray['defaultPageTSconfig'] = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
1260 foreach ($rootLine as $k => $v) {
1261 if (trim($v['tsconfig_includes'])) {
1262 $includeTsConfigFileList = GeneralUtility::trimExplode(',', $v['tsconfig_includes'], true);
1263 // Traversing list
1264 foreach ($includeTsConfigFileList as $key => $includeTsConfigFile) {
1265 if (strpos($includeTsConfigFile, 'EXT:') === 0) {
1266 list($includeTsConfigFileExtensionKey, $includeTsConfigFilename) = explode(
1267 '/',
1268 substr($includeTsConfigFile, 4),
1269 2
1270 );
1271 if ((string)$includeTsConfigFileExtensionKey !== ''
1272 && ExtensionManagementUtility::isLoaded($includeTsConfigFileExtensionKey)
1273 && (string)$includeTsConfigFilename !== ''
1274 ) {
1275 $includeTsConfigFileAndPath = ExtensionManagementUtility::extPath($includeTsConfigFileExtensionKey) .
1276 $includeTsConfigFilename;
1277 if (file_exists($includeTsConfigFileAndPath)) {
1278 $TSdataArray['uid_' . $v['uid'] . '_static_' . $key] = file_get_contents($includeTsConfigFileAndPath);
1279 }
1280 }
1281 }
1282 }
1283 }
1284 $TSdataArray['uid_' . $v['uid']] = $v['TSconfig'];
1285 }
1286 $TSdataArray = static::emitGetPagesTSconfigPreIncludeSignal($TSdataArray, $id, $rootLine, $returnPartArray);
1287 $TSdataArray = TypoScriptParser::checkIncludeLines_array($TSdataArray);
1288 if ($returnPartArray) {
1289 return $TSdataArray;
1290 }
1291 // Parsing the page TS-Config
1292 $pageTS = implode(LF . '[GLOBAL]' . LF, $TSdataArray);
1293 /* @var $parseObj \TYPO3\CMS\Backend\Configuration\TsConfigParser */
1294 $parseObj = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Configuration\TsConfigParser::class);
1295 $res = $parseObj->parseTSconfig($pageTS, 'PAGES', $id, $rootLine);
1296 if ($res) {
1297 $TSconfig = $res['TSconfig'];
1298 }
1299 $cacheHash = $res['hash'];
1300 // Get User TSconfig overlay
1301 $userTSconfig = static::getBackendUserAuthentication()->userTS['page.'] ?? null;
1302 if (is_array($userTSconfig)) {
1303 ArrayUtility::mergeRecursiveWithOverrule($TSconfig, $userTSconfig);
1304 $cacheHash .= '_user' . $GLOBALS['BE_USER']->user['uid'];
1305 }
1306
1307 if ($useCacheForCurrentPageId) {
1308 // Many pages end up with the same ts config. To reduce memory usage, the cache
1309 // entries are a linked list: One or more pids point to content hashes which then
1310 // contain the cached content.
1311 $cache->set('pagesTsConfigHashToContent' . $cacheHash, $TSconfig, ['pagesTsConfig']);
1312 $cache->set('pagesTsConfigIdToHash' . $id, $cacheHash, ['pagesTsConfig']);
1313 }
1314
1315 return $TSconfig;
1316 }
1317
1318 /*******************************************
1319 *
1320 * Users / Groups related
1321 *
1322 *******************************************/
1323 /**
1324 * Returns an array with be_users records of all user NOT DELETED sorted by their username
1325 * Keys in the array is the be_users uid
1326 *
1327 * @param string $fields Optional $fields list (default: username,usergroup,usergroup_cached_list,uid) can be used to set the selected fields
1328 * @param string $where Optional $where clause (fx. "AND username='pete'") can be used to limit query
1329 * @return array
1330 */
1331 public static function getUserNames($fields = 'username,usergroup,usergroup_cached_list,uid', $where = '')
1332 {
1333 return self::getRecordsSortedByTitle(
1334 GeneralUtility::trimExplode(',', $fields, true),
1335 'be_users',
1336 'username',
1337 'AND pid=0 ' . $where
1338 );
1339 }
1340
1341 /**
1342 * Returns an array with be_groups records (title, uid) of all groups NOT DELETED sorted by their title
1343 *
1344 * @param string $fields Field list
1345 * @param string $where WHERE clause
1346 * @return array
1347 */
1348 public static function getGroupNames($fields = 'title,uid', $where = '')
1349 {
1350 return self::getRecordsSortedByTitle(
1351 GeneralUtility::trimExplode(',', $fields, true),
1352 'be_groups',
1353 'title',
1354 'AND pid=0 ' . $where
1355 );
1356 }
1357
1358 /**
1359 * Returns an array of all non-deleted records of a table sorted by a given title field.
1360 * The value of the title field will be replaced by the return value
1361 * of self::getRecordTitle() before the sorting is performed.
1362 *
1363 * @param array $fields Fields to select
1364 * @param string $table Table name
1365 * @param string $titleField Field that will contain the record title
1366 * @param string $where Additional where clause
1367 * @return array Array of sorted records
1368 */
1369 protected static function getRecordsSortedByTitle(array $fields, $table, $titleField, $where = '')
1370 {
1371 $fieldsIndex = array_flip($fields);
1372 // Make sure the titleField is amongst the fields when getting sorted
1373 $fieldsIndex[$titleField] = 1;
1374
1375 $result = [];
1376
1377 $queryBuilder = static::getQueryBuilderForTable($table);
1378 $queryBuilder->getRestrictions()
1379 ->removeAll()
1380 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
1381
1382 $res = $queryBuilder
1383 ->select('*')
1384 ->from($table)
1385 ->where(QueryHelper::stripLogicalOperatorPrefix($where))
1386 ->execute();
1387
1388 while ($record = $res->fetch()) {
1389 // store the uid, because it might be unset if it's not among the requested $fields
1390 $recordId = $record['uid'];
1391 $record[$titleField] = self::getRecordTitle($table, $record);
1392
1393 // include only the requested fields in the result
1394 $result[$recordId] = array_intersect_key($record, $fieldsIndex);
1395 }
1396
1397 // sort records by $sortField. This is not done in the query because the title might have been overwritten by
1398 // self::getRecordTitle();
1399 return ArrayUtility::sortArraysByKey($result, $titleField);
1400 }
1401
1402 /**
1403 * Returns an array with be_groups records (like ->getGroupNames) but:
1404 * - if the current BE_USER is admin, then all groups are returned, otherwise only groups that the current user is member of (usergroup_cached_list) will be returned.
1405 *
1406 * @param string $fields Field list; $fields specify the fields selected (default: title,uid)
1407 * @return array
1408 */
1409 public static function getListGroupNames($fields = 'title, uid')
1410 {
1411 $beUser = static::getBackendUserAuthentication();
1412 $exQ = ' AND hide_in_lists=0';
1413 if (!$beUser->isAdmin()) {
1414 $exQ .= ' AND uid IN (' . ($beUser->user['usergroup_cached_list'] ?: 0) . ')';
1415 }
1416 return self::getGroupNames($fields, $exQ);
1417 }
1418
1419 /**
1420 * Returns the array $usernames with the names of all users NOT IN $groupArray changed to the uid (hides the usernames!).
1421 * If $excludeBlindedFlag is set, then these records are unset from the array $usernames
1422 * Takes $usernames (array made by \TYPO3\CMS\Backend\Utility\BackendUtility::getUserNames()) and a $groupArray (array with the groups a certain user is member of) as input
1423 *
1424 * @param array $usernames User names
1425 * @param array $groupArray Group names
1426 * @param bool $excludeBlindedFlag If $excludeBlindedFlag is set, then these records are unset from the array $usernames
1427 * @return array User names, blinded
1428 */
1429 public static function blindUserNames($usernames, $groupArray, $excludeBlindedFlag = false)
1430 {
1431 if (is_array($usernames) && is_array($groupArray)) {
1432 foreach ($usernames as $uid => $row) {
1433 $userN = $uid;
1434 $set = 0;
1435 if ($row['uid'] != static::getBackendUserAuthentication()->user['uid']) {
1436 foreach ($groupArray as $v) {
1437 if ($v && GeneralUtility::inList($row['usergroup_cached_list'], $v)) {
1438 $userN = $row['username'];
1439 $set = 1;
1440 }
1441 }
1442 } else {
1443 $userN = $row['username'];
1444 $set = 1;
1445 }
1446 $usernames[$uid]['username'] = $userN;
1447 if ($excludeBlindedFlag && !$set) {
1448 unset($usernames[$uid]);
1449 }
1450 }
1451 }
1452 return $usernames;
1453 }
1454
1455 /**
1456 * Corresponds to blindUserNames but works for groups instead
1457 *
1458 * @param array $groups Group names
1459 * @param array $groupArray Group names (reference)
1460 * @param bool $excludeBlindedFlag If $excludeBlindedFlag is set, then these records are unset from the array $usernames
1461 * @return array
1462 */
1463 public static function blindGroupNames($groups, $groupArray, $excludeBlindedFlag = false)
1464 {
1465 if (is_array($groups) && is_array($groupArray)) {
1466 foreach ($groups as $uid => $row) {
1467 $groupN = $uid;
1468 $set = 0;
1469 if (in_array($uid, $groupArray, false)) {
1470 $groupN = $row['title'];
1471 $set = 1;
1472 }
1473 $groups[$uid]['title'] = $groupN;
1474 if ($excludeBlindedFlag && !$set) {
1475 unset($groups[$uid]);
1476 }
1477 }
1478 }
1479 return $groups;
1480 }
1481
1482 /*******************************************
1483 *
1484 * Output related
1485 *
1486 *******************************************/
1487 /**
1488 * Returns the difference in days between input $tstamp and $EXEC_TIME
1489 *
1490 * @param int $tstamp Time stamp, seconds
1491 * @return int
1492 */
1493 public static function daysUntil($tstamp)
1494 {
1495 $delta_t = $tstamp - $GLOBALS['EXEC_TIME'];
1496 return ceil($delta_t / (3600 * 24));
1497 }
1498
1499 /**
1500 * Returns $tstamp formatted as "ddmmyy" (According to $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'])
1501 *
1502 * @param int $tstamp Time stamp, seconds
1503 * @return string Formatted time
1504 */
1505 public static function date($tstamp)
1506 {
1507 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], (int)$tstamp);
1508 }
1509
1510 /**
1511 * Returns $tstamp formatted as "ddmmyy hhmm" (According to $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] AND $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'])
1512 *
1513 * @param int $value Time stamp, seconds
1514 * @return string Formatted time
1515 */
1516 public static function datetime($value)
1517 {
1518 return date(
1519 $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'],
1520 $value
1521 );
1522 }
1523
1524 /**
1525 * Returns $value (in seconds) formatted as hh:mm:ss
1526 * For instance $value = 3600 + 60*2 + 3 should return "01:02:03"
1527 *
1528 * @param int $value Time stamp, seconds
1529 * @param bool $withSeconds Output hh:mm:ss. If FALSE: hh:mm
1530 * @return string Formatted time
1531 */
1532 public static function time($value, $withSeconds = true)
1533 {
1534 return gmdate('H:i' . ($withSeconds ? ':s' : ''), (int)$value);
1535 }
1536
1537 /**
1538 * Returns the "age" in minutes / hours / days / years of the number of $seconds inputted.
1539 *
1540 * @param int $seconds Seconds could be the difference of a certain timestamp and time()
1541 * @param string $labels Labels should be something like ' min| hrs| days| yrs| min| hour| day| year'. This value is typically delivered by this function call: $GLOBALS["LANG"]->sL("LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears")
1542 * @return string Formatted time
1543 */
1544 public static function calcAge($seconds, $labels = 'min|hrs|days|yrs|min|hour|day|year')
1545 {
1546 $labelArr = GeneralUtility::trimExplode('|', $labels, true);
1547 $absSeconds = abs($seconds);
1548 $sign = $seconds < 0 ? -1 : 1;
1549 if ($absSeconds < 3600) {
1550 $val = round($absSeconds / 60);
1551 $seconds = $sign * $val . ' ' . ($val == 1 ? $labelArr[4] : $labelArr[0]);
1552 } elseif ($absSeconds < 24 * 3600) {
1553 $val = round($absSeconds / 3600);
1554 $seconds = $sign * $val . ' ' . ($val == 1 ? $labelArr[5] : $labelArr[1]);
1555 } elseif ($absSeconds < 365 * 24 * 3600) {
1556 $val = round($absSeconds / (24 * 3600));
1557 $seconds = $sign * $val . ' ' . ($val == 1 ? $labelArr[6] : $labelArr[2]);
1558 } else {
1559 $val = round($absSeconds / (365 * 24 * 3600));
1560 $seconds = $sign * $val . ' ' . ($val == 1 ? $labelArr[7] : $labelArr[3]);
1561 }
1562 return $seconds;
1563 }
1564
1565 /**
1566 * Returns a formatted timestamp if $tstamp is set.
1567 * The date/datetime will be followed by the age in parenthesis.
1568 *
1569 * @param int $tstamp Time stamp, seconds
1570 * @param int $prefix 1/-1 depending on polarity of age.
1571 * @param string $date $date=="date" will yield "dd:mm:yy" formatting, otherwise "dd:mm:yy hh:mm
1572 * @return string
1573 */
1574 public static function dateTimeAge($tstamp, $prefix = 1, $date = '')
1575 {
1576 if (!$tstamp) {
1577 return '';
1578 }
1579 $label = static::getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears');
1580 $age = ' (' . self::calcAge($prefix * ($GLOBALS['EXEC_TIME'] - $tstamp), $label) . ')';
1581 return ($date === 'date' ? self::date($tstamp) : self::datetime($tstamp)) . $age;
1582 }
1583
1584 /**
1585 * Returns alt="" and title="" attributes with the value of $content.
1586 *
1587 * @param string $content Value for 'alt' and 'title' attributes (will be htmlspecialchars()'ed before output)
1588 * @return string
1589 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
1590 */
1591 public static function titleAltAttrib($content)
1592 {
1593 GeneralUtility::logDeprecatedFunction();
1594 $out = '';
1595 $out .= ' alt="' . htmlspecialchars($content) . '"';
1596 $out .= ' title="' . htmlspecialchars($content) . '"';
1597 return $out;
1598 }
1599
1600 /**
1601 * Resolves file references for a given record.
1602 *
1603 * @param string $tableName Name of the table of the record
1604 * @param string $fieldName Name of the field of the record
1605 * @param array $element Record data
1606 * @param int|null $workspaceId Workspace to fetch data for
1607 * @return \TYPO3\CMS\Core\Resource\FileReference[]|null
1608 */
1609 public static function resolveFileReferences($tableName, $fieldName, $element, $workspaceId = null)
1610 {
1611 if (empty($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config'])) {
1612 return null;
1613 }
1614 $configuration = $GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config'];
1615 if (empty($configuration['type']) || $configuration['type'] !== 'inline'
1616 || empty($configuration['foreign_table']) || $configuration['foreign_table'] !== 'sys_file_reference'
1617 ) {
1618 return null;
1619 }
1620
1621 $fileReferences = [];
1622 /** @var $relationHandler RelationHandler */
1623 $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
1624 if ($workspaceId !== null) {
1625 $relationHandler->setWorkspaceId($workspaceId);
1626 }
1627 $relationHandler->start(
1628 $element[$fieldName],
1629 $configuration['foreign_table'],
1630 $configuration['MM'],
1631 $element['uid'],
1632 $tableName,
1633 $configuration
1634 );
1635 $relationHandler->processDeletePlaceholder();
1636 $referenceUids = $relationHandler->tableArray[$configuration['foreign_table']];
1637
1638 foreach ($referenceUids as $referenceUid) {
1639 try {
1640 $fileReference = ResourceFactory::getInstance()->getFileReferenceObject(
1641 $referenceUid,
1642 [],
1643 ($workspaceId === 0)
1644 );
1645 $fileReferences[$fileReference->getUid()] = $fileReference;
1646 } catch (\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $e) {
1647 /**
1648 * We just catch the exception here
1649 * Reasoning: There is nothing an editor or even admin could do
1650 */
1651 } catch (\InvalidArgumentException $e) {
1652 /**
1653 * The storage does not exist anymore
1654 * Log the exception message for admins as they maybe can restore the storage
1655 */
1656 $logMessage = $e->getMessage() . ' (table: "' . $tableName . '", fieldName: "' . $fieldName . '", referenceUid: ' . $referenceUid . ')';
1657 GeneralUtility::sysLog($logMessage, 'core', GeneralUtility::SYSLOG_SEVERITY_ERROR);
1658 }
1659 }
1660
1661 return $fileReferences;
1662 }
1663
1664 /**
1665 * Returns a linked image-tag for thumbnail(s)/fileicons/truetype-font-previews from a database row with a list of image files in a field
1666 * All $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] extension are made to thumbnails + ttf file (renders font-example)
1667 * Thumbsnails are linked to the show_item.php script which will display further details.
1668 *
1669 * @param array $row Row is the database row from the table, $table.
1670 * @param string $table Table name for $row (present in TCA)
1671 * @param string $field Field is pointing to the list of image files
1672 * @param string $backPath Back path prefix for image tag src="" field
1673 * @param string $thumbScript UNUSED since FAL
1674 * @param string $uploaddir Optional: $uploaddir is the directory relative to PATH_site where the image files from the $field value is found (Is by default set to the entry in $GLOBALS['TCA'] for that field! so you don't have to!)
1675 * @param int $abs UNUSED
1676 * @param string $tparams Optional: $tparams is additional attributes for the image tags
1677 * @param int|string $size Optional: $size is [w]x[h] of the thumbnail. 64 is default.
1678 * @param bool $linkInfoPopup Whether to wrap with a link opening the info popup
1679 * @return string Thumbnail image tag.
1680 */
1681 public static function thumbCode(
1682 $row,
1683 $table,
1684 $field,
1685 $backPath = '',
1686 $thumbScript = '',
1687 $uploaddir = null,
1688 $abs = 0,
1689 $tparams = '',
1690 $size = '',
1691 $linkInfoPopup = true
1692 ) {
1693 // Check and parse the size parameter
1694 $size = trim($size);
1695 $sizeParts = [64, 64];
1696 if ($size) {
1697 $sizeParts = explode('x', $size . 'x' . $size);
1698 }
1699 $thumbData = '';
1700 $fileReferences = static::resolveFileReferences($table, $field, $row);
1701 // FAL references
1702 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
1703 if ($fileReferences !== null) {
1704 foreach ($fileReferences as $fileReferenceObject) {
1705 // Do not show previews of hidden references
1706 if ($fileReferenceObject->getProperty('hidden')) {
1707 continue;
1708 }
1709 $fileObject = $fileReferenceObject->getOriginalFile();
1710
1711 if ($fileObject->isMissing()) {
1712 $thumbData .= '<span class="label label-danger">'
1713 . htmlspecialchars(
1714 static::getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing')
1715 )
1716 . '</span>&nbsp;' . htmlspecialchars($fileObject->getName()) . '<br />';
1717 continue;
1718 }
1719
1720 // Preview web image or media elements
1721 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails']
1722 && GeneralUtility::inList(
1723 $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
1724 $fileReferenceObject->getExtension()
1725 )
1726 ) {
1727 $cropVariantCollection = CropVariantCollection::create((string)$fileReferenceObject->getProperty('crop'));
1728 $cropArea = $cropVariantCollection->getCropArea();
1729 $processingInformation = [
1730 'width' => $sizeParts[0],
1731 'height' => $sizeParts[1] . 'c',
1732 'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($fileReferenceObject)
1733 ];
1734 $imageUrl = (string)GeneralUtility::makeInstance(UriBuilder::class)
1735 ->buildUriFromRoute('thumbnails', [
1736 'fileIdentifier' => $fileObject->getCombinedIdentifier(),
1737 'processingInstructions' => $processingInformation
1738 ]);
1739 $attributes = [
1740 'src' => $imageUrl,
1741 'width' => (int)$sizeParts[0],
1742 'height' => (int)$sizeParts[1],
1743 'alt' => $fileReferenceObject->getName(),
1744 ];
1745 $imgTag = '<img ' . GeneralUtility::implodeAttributes($attributes, true) . '/>';
1746 } else {
1747 // Icon
1748 $imgTag = '<span title="' . htmlspecialchars($fileObject->getName()) . '">'
1749 . $iconFactory->getIconForResource($fileObject, Icon::SIZE_SMALL)->render()
1750 . '</span>';
1751 }
1752 if ($linkInfoPopup) {
1753 $onClick = 'top.launchView(\'_FILE\',\'' . (int)$fileObject->getUid() . '\'); return false;';
1754 $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $imgTag . '</a> ';
1755 } else {
1756 $thumbData .= $imgTag;
1757 }
1758 }
1759 } else {
1760 // Find uploaddir automatically
1761 if (is_null($uploaddir)) {
1762 $uploaddir = $GLOBALS['TCA'][$table]['columns'][$field]['config']['uploadfolder'];
1763 }
1764 $uploaddir = rtrim($uploaddir, '/');
1765 // Traverse files:
1766 $thumbs = GeneralUtility::trimExplode(',', $row[$field], true);
1767 $thumbData = '';
1768 foreach ($thumbs as $theFile) {
1769 if ($theFile) {
1770 $fileName = trim($uploaddir . '/' . $theFile, '/');
1771 try {
1772 /** @var File $fileObject */
1773 $fileObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($fileName);
1774 // Skip the resource if it's not of type AbstractFile. One case where this can happen if the
1775 // storage has been externally modified and the field value now points to a folder
1776 // instead of a file.
1777 if (!$fileObject instanceof AbstractFile) {
1778 continue;
1779 }
1780 if ($fileObject->isMissing()) {
1781 $thumbData .= '<span class="label label-danger">'
1782 . htmlspecialchars(static::getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
1783 . '</span>&nbsp;' . htmlspecialchars($fileObject->getName()) . '<br />';
1784 continue;
1785 }
1786 } catch (ResourceDoesNotExistException $exception) {
1787 $thumbData .= '<span class="label label-danger">'
1788 . htmlspecialchars(static::getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
1789 . '</span>&nbsp;' . htmlspecialchars($fileName) . '<br />';
1790 continue;
1791 }
1792
1793 $fileExtension = $fileObject->getExtension();
1794 if ($fileExtension === 'ttf'
1795 || GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)
1796 ) {
1797 $imageUrl = $fileObject->process(
1798 ProcessedFile::CONTEXT_IMAGEPREVIEW,
1799 [
1800 'width' => $sizeParts[0],
1801 'height' => $sizeParts[1]
1802 ]
1803 )->getPublicUrl(true);
1804
1805 $image = '<img src="' . htmlspecialchars($imageUrl) . '" hspace="2" border="0" title="' . htmlspecialchars($fileObject->getName()) . '"' . $tparams . ' alt="" />';
1806 if ($linkInfoPopup) {
1807 $onClick = 'top.launchView(\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileName) . ',\'\');return false;';
1808 $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $image . '</a> ';
1809 } else {
1810 $thumbData .= $image;
1811 }
1812 } else {
1813 // Gets the icon
1814 $fileIcon = '<span title="' . htmlspecialchars($fileObject->getName()) . '">'
1815 . $iconFactory->getIconForResource($fileObject, Icon::SIZE_SMALL)->render()
1816 . '</span>';
1817 if ($linkInfoPopup) {
1818 $onClick = 'top.launchView(\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileName) . ',\'\'); return false;';
1819 $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $fileIcon . '</a> ';
1820 } else {
1821 $thumbData .= $fileIcon;
1822 }
1823 }
1824 }
1825 }
1826 }
1827 return $thumbData;
1828 }
1829
1830 /**
1831 * Returns title-attribute information for a page-record informing about id, alias, doktype, hidden, starttime, endtime, fe_group etc.
1832 *
1833 * @param array $row Input must be a page row ($row) with the proper fields set (be sure - send the full range of fields for the table)
1834 * @param string $perms_clause This is used to get the record path of the shortcut page, if any (and doktype==4)
1835 * @param bool $includeAttrib If $includeAttrib is set, then the 'title=""' attribute is wrapped about the return value, which is in any case htmlspecialchar()'ed already
1836 * @return string
1837 */
1838 public static function titleAttribForPages($row, $perms_clause = '', $includeAttrib = true)
1839 {
1840 $lang = static::getLanguageService();
1841 $parts = [];
1842 $parts[] = 'id=' . $row['uid'];
1843 if ($row['alias']) {
1844 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['alias']['label']) . ' ' . $row['alias'];
1845 }
1846 if ($row['pid'] < 0) {
1847 $parts[] = 'v#1.' . $row['t3ver_id'];
1848 }
1849 switch (VersionState::cast($row['t3ver_state'])) {
1850 case new VersionState(VersionState::NEW_PLACEHOLDER):
1851 $parts[] = 'PLH WSID#' . $row['t3ver_wsid'];
1852 break;
1853 case new VersionState(VersionState::DELETE_PLACEHOLDER):
1854 $parts[] = 'Deleted element!';
1855 break;
1856 case new VersionState(VersionState::MOVE_PLACEHOLDER):
1857 $parts[] = 'NEW LOCATION (PLH) WSID#' . $row['t3ver_wsid'];
1858 break;
1859 case new VersionState(VersionState::MOVE_POINTER):
1860 $parts[] = 'OLD LOCATION (PNT) WSID#' . $row['t3ver_wsid'];
1861 break;
1862 case new VersionState(VersionState::NEW_PLACEHOLDER_VERSION):
1863 $parts[] = 'New element!';
1864 break;
1865 }
1866 if ($row['doktype'] == PageRepository::DOKTYPE_LINK) {
1867 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['url']['label']) . ' ' . $row['url'];
1868 } elseif ($row['doktype'] == PageRepository::DOKTYPE_SHORTCUT) {
1869 if ($perms_clause) {
1870 $label = self::getRecordPath((int)$row['shortcut'], $perms_clause, 20);
1871 } else {
1872 $row['shortcut'] = (int)$row['shortcut'];
1873 $lRec = self::getRecordWSOL('pages', $row['shortcut'], 'title');
1874 $label = $lRec['title'] . ' (id=' . $row['shortcut'] . ')';
1875 }
1876 if ($row['shortcut_mode'] != PageRepository::SHORTCUT_MODE_NONE) {
1877 $label .= ', ' . $lang->sL($GLOBALS['TCA']['pages']['columns']['shortcut_mode']['label']) . ' '
1878 . $lang->sL(self::getLabelFromItemlist('pages', 'shortcut_mode', $row['shortcut_mode']));
1879 }
1880 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['shortcut']['label']) . ' ' . $label;
1881 } elseif ($row['doktype'] == PageRepository::DOKTYPE_MOUNTPOINT) {
1882 if ($perms_clause) {
1883 $label = self::getRecordPath((int)$row['mount_pid'], $perms_clause, 20);
1884 } else {
1885 $lRec = self::getRecordWSOL('pages', (int)$row['mount_pid'], 'title');
1886 $label = $lRec['title'] . ' (id=' . $row['mount_pid'] . ')';
1887 }
1888 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['mount_pid']['label']) . ' ' . $label;
1889 if ($row['mount_pid_ol']) {
1890 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['mount_pid_ol']['label']);
1891 }
1892 }
1893 if ($row['nav_hide']) {
1894 $parts[] = rtrim($lang->sL($GLOBALS['TCA']['pages']['columns']['nav_hide']['label']), ':');
1895 }
1896 if ($row['hidden']) {
1897 $parts[] = $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.hidden');
1898 }
1899 if ($row['starttime']) {
1900 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['starttime']['label'])
1901 . ' ' . self::dateTimeAge($row['starttime'], -1, 'date');
1902 }
1903 if ($row['endtime']) {
1904 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['endtime']['label']) . ' '
1905 . self::dateTimeAge($row['endtime'], -1, 'date');
1906 }
1907 if ($row['fe_group']) {
1908 $fe_groups = [];
1909 foreach (GeneralUtility::intExplode(',', $row['fe_group']) as $fe_group) {
1910 if ($fe_group < 0) {
1911 $fe_groups[] = $lang->sL(self::getLabelFromItemlist('pages', 'fe_group', $fe_group));
1912 } else {
1913 $lRec = self::getRecordWSOL('fe_groups', $fe_group, 'title');
1914 $fe_groups[] = $lRec['title'];
1915 }
1916 }
1917 $label = implode(', ', $fe_groups);
1918 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['fe_group']['label']) . ' ' . $label;
1919 }
1920 $out = htmlspecialchars(implode(' - ', $parts));
1921 return $includeAttrib ? 'title="' . $out . '"' : $out;
1922 }
1923
1924 /**
1925 * Returns the combined markup for Bootstraps tooltips
1926 *
1927 * @param array $row
1928 * @param string $table
1929 * @return string
1930 */
1931 public static function getRecordToolTip(array $row, $table = 'pages')
1932 {
1933 $toolTipText = self::getRecordIconAltText($row, $table);
1934 $toolTipCode = 'data-toggle="tooltip" data-title=" '
1935 . str_replace(' - ', '<br>', $toolTipText)
1936 . '" data-html="true" data-placement="right"';
1937 return $toolTipCode;
1938 }
1939
1940 /**
1941 * Returns title-attribute information for ANY record (from a table defined in TCA of course)
1942 * The included information depends on features of the table, but if hidden, starttime, endtime and fe_group fields are configured for, information about the record status in regard to these features are is included.
1943 * "pages" table can be used as well and will return the result of ->titleAttribForPages() for that page.
1944 *
1945 * @param array $row Table row; $row is a row from the table, $table
1946 * @param string $table Table name
1947 * @return string
1948 */
1949 public static function getRecordIconAltText($row, $table = 'pages')
1950 {
1951 if ($table === 'pages') {
1952 $out = self::titleAttribForPages($row, '', 0);
1953 } else {
1954 $out = !empty(trim($GLOBALS['TCA'][$table]['ctrl']['descriptionColumn'])) ? $row[$GLOBALS['TCA'][$table]['ctrl']['descriptionColumn']] . ' ' : '';
1955 $ctrl = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
1956 // Uid is added
1957 $out .= 'id=' . $row['uid'];
1958 if ($table === 'pages' && $row['alias']) {
1959 $out .= ' / ' . $row['alias'];
1960 }
1961 if (static::isTableWorkspaceEnabled($table) && $row['pid'] < 0) {
1962 $out .= ' - v#1.' . $row['t3ver_id'];
1963 }
1964 if (static::isTableWorkspaceEnabled($table)) {
1965 switch (VersionState::cast($row['t3ver_state'])) {
1966 case new VersionState(VersionState::NEW_PLACEHOLDER):
1967 $out .= ' - PLH WSID#' . $row['t3ver_wsid'];
1968 break;
1969 case new VersionState(VersionState::DELETE_PLACEHOLDER):
1970 $out .= ' - Deleted element!';
1971 break;
1972 case new VersionState(VersionState::MOVE_PLACEHOLDER):
1973 $out .= ' - NEW LOCATION (PLH) WSID#' . $row['t3ver_wsid'];
1974 break;
1975 case new VersionState(VersionState::MOVE_POINTER):
1976 $out .= ' - OLD LOCATION (PNT) WSID#' . $row['t3ver_wsid'];
1977 break;
1978 case new VersionState(VersionState::NEW_PLACEHOLDER_VERSION):
1979 $out .= ' - New element!';
1980 break;
1981 }
1982 }
1983 // Hidden
1984 $lang = static::getLanguageService();
1985 if ($ctrl['disabled']) {
1986 $out .= $row[$ctrl['disabled']] ? ' - ' . $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.hidden') : '';
1987 }
1988 if ($ctrl['starttime']) {
1989 if ($row[$ctrl['starttime']] > $GLOBALS['EXEC_TIME']) {
1990 $out .= ' - ' . $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.starttime') . ':' . self::date($row[$ctrl['starttime']]) . ' (' . self::daysUntil($row[$ctrl['starttime']]) . ' ' . $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.days') . ')';
1991 }
1992 }
1993 if ($row[$ctrl['endtime']]) {
1994 $out .= ' - ' . $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.endtime') . ': ' . self::date($row[$ctrl['endtime']]) . ' (' . self::daysUntil($row[$ctrl['endtime']]) . ' ' . $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.days') . ')';
1995 }
1996 }
1997 return htmlspecialchars($out);
1998 }
1999
2000 /**
2001 * Returns the label of the first found entry in an "items" array from $GLOBALS['TCA'] (tablename = $table/fieldname = $col) where the value is $key
2002 *
2003 * @param string $table Table name, present in $GLOBALS['TCA']
2004 * @param string $col Field name, present in $GLOBALS['TCA']
2005 * @param string $key items-array value to match
2006 * @return string Label for item entry
2007 */
2008 public static function getLabelFromItemlist($table, $col, $key)
2009 {
2010 // Check, if there is an "items" array:
2011 if (is_array($GLOBALS['TCA'][$table]['columns'][$col]['config']['items'] ?? false)) {
2012 // Traverse the items-array...
2013 foreach ($GLOBALS['TCA'][$table]['columns'][$col]['config']['items'] as $v) {
2014 // ... and return the first found label where the value was equal to $key
2015 if ((string)$v[1] === (string)$key) {
2016 return $v[0];
2017 }
2018 }
2019 }
2020 return '';
2021 }
2022
2023 /**
2024 * Return the label of a field by additionally checking TsConfig values
2025 *
2026 * @param int $pageId Page id
2027 * @param string $table Table name
2028 * @param string $column Field Name
2029 * @param string $key item value
2030 * @return string Label for item entry
2031 */
2032 public static function getLabelFromItemListMerged($pageId, $table, $column, $key)
2033 {
2034 $pageTsConfig = static::getPagesTSconfig($pageId);
2035 $label = '';
2036 if (is_array($pageTsConfig['TCEFORM.'])
2037 && is_array($pageTsConfig['TCEFORM.'][$table . '.'])
2038 && is_array($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.'])
2039 ) {
2040 if (is_array($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['addItems.'])
2041 && isset($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['addItems.'][$key])
2042 ) {
2043 $label = $pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['addItems.'][$key];
2044 } elseif (is_array($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['altLabels.'])
2045 && isset($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['altLabels.'][$key])
2046 ) {
2047 $label = $pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['altLabels.'][$key];
2048 }
2049 }
2050 if (empty($label)) {
2051 $tcaValue = self::getLabelFromItemlist($table, $column, $key);
2052 if (!empty($tcaValue)) {
2053 $label = $tcaValue;
2054 }
2055 }
2056 return $label;
2057 }
2058
2059 /**
2060 * Splits the given key with commas and returns the list of all the localized items labels, separated by a comma.
2061 * NOTE: this does not take itemsProcFunc into account
2062 *
2063 * @param string $table Table name, present in TCA
2064 * @param string $column Field name
2065 * @param string $keyList Key or comma-separated list of keys.
2066 * @param array $columnTsConfig page TSConfig for $column (TCEMAIN.<table>.<column>)
2067 * @return string Comma-separated list of localized labels
2068 */
2069 public static function getLabelsFromItemsList($table, $column, $keyList, array $columnTsConfig = [])
2070 {
2071 // Check if there is an "items" array
2072 if (
2073 !isset($GLOBALS['TCA'][$table]['columns'][$column]['config']['items'])
2074 || !is_array($GLOBALS['TCA'][$table]['columns'][$column]['config']['items'])
2075 || $keyList === ''
2076 ) {
2077 return '';
2078 }
2079
2080 $keys = GeneralUtility::trimExplode(',', $keyList, true);
2081 $labels = [];
2082 // Loop on all selected values
2083 foreach ($keys as $key) {
2084 $label = null;
2085 if ($columnTsConfig) {
2086 // Check if label has been defined or redefined via pageTsConfig
2087 if (isset($columnTsConfig['addItems.'][$key])) {
2088 $label = $columnTsConfig['addItems.'][$key];
2089 } elseif (isset($columnTsConfig['altLabels.'][$key])) {
2090 $label = $columnTsConfig['altLabels.'][$key];
2091 }
2092 }
2093 if ($label === null) {
2094 // Otherwise lookup the label in TCA items list
2095 foreach ($GLOBALS['TCA'][$table]['columns'][$column]['config']['items'] as $itemConfiguration) {
2096 list($currentLabel, $currentKey) = $itemConfiguration;
2097 if ((string)$key === (string)$currentKey) {
2098 $label = $currentLabel;
2099 break;
2100 }
2101 }
2102 }
2103 if ($label !== null) {
2104 $labels[] = static::getLanguageService()->sL($label);
2105 }
2106 }
2107 return implode(', ', $labels);
2108 }
2109
2110 /**
2111 * Returns the label-value for fieldname $col in table, $table
2112 * If $printAllWrap is set (to a "wrap") then it's wrapped around the $col value IF THE COLUMN $col DID NOT EXIST in TCA!, eg. $printAllWrap = '<strong>|</strong>' and the fieldname was 'not_found_field' then the return value would be '<strong>not_found_field</strong>'
2113 *
2114 * @param string $table Table name, present in $GLOBALS['TCA']
2115 * @param string $col Field name
2116 * @return string or NULL if $col is not found in the TCA table
2117 */
2118 public static function getItemLabel($table, $col)
2119 {
2120 // Check if column exists
2121 if (is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'][$col])) {
2122 return $GLOBALS['TCA'][$table]['columns'][$col]['label'];
2123 }
2124
2125 return null;
2126 }
2127
2128 /**
2129 * Replace field values in given row with values from the original language
2130 * if l10n_mode TCA settings require to do so.
2131 *
2132 * @param string $table Table name
2133 * @param array $row Row to fill with original language values
2134 * @return array Row with values from the original language
2135 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9
2136 */
2137 protected static function replaceL10nModeFields($table, array $row)
2138 {
2139 GeneralUtility::logDeprecatedFunction();
2140 $originalUidField = isset($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'])
2141 ? $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']
2142 : '';
2143 if (empty($row[$originalUidField])) {
2144 return $row;
2145 }
2146
2147 $originalTable = self::getOriginalTranslationTable($table);
2148 $originalRow = self::getRecord($originalTable, $row[$originalUidField]);
2149 foreach ($row as $field => $_) {
2150 $l10n_mode = isset($GLOBALS['TCA'][$originalTable]['columns'][$field]['l10n_mode'])
2151 ? $GLOBALS['TCA'][$originalTable]['columns'][$field]['l10n_mode']
2152 : '';
2153 if ($l10n_mode === 'exclude') {
2154 $row[$field] = $originalRow[$field];
2155 }
2156 }
2157 return $row;
2158 }
2159
2160 /**
2161 * Returns the "title"-value in record, $row, from table, $table
2162 * The field(s) from which the value is taken is determined by the "ctrl"-entries 'label', 'label_alt' and 'label_alt_force'
2163 *
2164 * @param string $table Table name, present in TCA
2165 * @param array $row Row from table
2166 * @param bool $prep If set, result is prepared for output: The output is cropped to a limited length (depending on BE_USER->uc['titleLen']) and if no value is found for the title, '<em>[No title]</em>' is returned (localized). Further, the output is htmlspecialchars()'ed
2167 * @param bool $forceResult If set, the function always returns an output. If no value is found for the title, '[No title]' is returned (localized).
2168 * @return string
2169 */
2170 public static function getRecordTitle($table, $row, $prep = false, $forceResult = true)
2171 {
2172 $recordTitle = '';
2173 if (is_array($GLOBALS['TCA'][$table])) {
2174 // If configured, call userFunc
2175 if (!empty($GLOBALS['TCA'][$table]['ctrl']['label_userFunc'])) {
2176 $params['table'] = $table;
2177 $params['row'] = $row;
2178 $params['title'] = '';
2179 $params['options'] = $GLOBALS['TCA'][$table]['ctrl']['label_userFunc_options'] ?? [];
2180
2181 // Create NULL-reference
2182 $null = null;
2183 GeneralUtility::callUserFunction($GLOBALS['TCA'][$table]['ctrl']['label_userFunc'], $params, $null);
2184 $recordTitle = $params['title'];
2185 } else {
2186 // No userFunc: Build label
2187 $recordTitle = self::getProcessedValue(
2188 $table,
2189 $GLOBALS['TCA'][$table]['ctrl']['label'],
2190 $row[$GLOBALS['TCA'][$table]['ctrl']['label']],
2191 0,
2192 0,
2193 false,
2194 $row['uid'],
2195 $forceResult
2196 );
2197 if (!empty($GLOBALS['TCA'][$table]['ctrl']['label_alt'])
2198 && (!empty($GLOBALS['TCA'][$table]['ctrl']['label_alt_force']) || (string)$recordTitle === '')
2199 ) {
2200 $altFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['label_alt'], true);
2201 $tA = [];
2202 if (!empty($recordTitle)) {
2203 $tA[] = $recordTitle;
2204 }
2205 foreach ($altFields as $fN) {
2206 $recordTitle = trim(strip_tags($row[$fN]));
2207 if ((string)$recordTitle !== '') {
2208 $recordTitle = self::getProcessedValue($table, $fN, $recordTitle, 0, 0, false, $row['uid']);
2209 if (!$GLOBALS['TCA'][$table]['ctrl']['label_alt_force']) {
2210 break;
2211 }
2212 $tA[] = $recordTitle;
2213 }
2214 }
2215 if ($GLOBALS['TCA'][$table]['ctrl']['label_alt_force']) {
2216 $recordTitle = implode(', ', $tA);
2217 }
2218 }
2219 }
2220 // If the current result is empty, set it to '[No title]' (localized) and prepare for output if requested
2221 if ($prep || $forceResult) {
2222 if ($prep) {
2223 $recordTitle = self::getRecordTitlePrep($recordTitle);
2224 }
2225 if (trim($recordTitle) === '') {
2226 $recordTitle = self::getNoRecordTitle($prep);
2227 }
2228 }
2229 }
2230
2231 return $recordTitle;
2232 }
2233
2234 /**
2235 * Crops a title string to a limited length and if it really was cropped, wrap it in a <span title="...">|</span>,
2236 * which offers a tooltip with the original title when moving mouse over it.
2237 *
2238 * @param string $title The title string to be cropped
2239 * @param int $titleLength Crop title after this length - if not set, BE_USER->uc['titleLen'] is used
2240 * @return string The processed title string, wrapped in <span title="...">|</span> if cropped
2241 */
2242 public static function getRecordTitlePrep($title, $titleLength = 0)
2243 {
2244 // If $titleLength is not a valid positive integer, use BE_USER->uc['titleLen']:
2245 if (!$titleLength || !MathUtility::canBeInterpretedAsInteger($titleLength) || $titleLength < 0) {
2246 $titleLength = static::getBackendUserAuthentication()->uc['titleLen'];
2247 }
2248 $titleOrig = htmlspecialchars($title);
2249 $title = htmlspecialchars(GeneralUtility::fixed_lgd_cs($title, $titleLength));
2250 // If title was cropped, offer a tooltip:
2251 if ($titleOrig != $title) {
2252 $title = '<span title="' . $titleOrig . '">' . $title . '</span>';
2253 }
2254 return $title;
2255 }
2256
2257 /**
2258 * Get a localized [No title] string, wrapped in <em>|</em> if $prep is TRUE.
2259 *
2260 * @param bool $prep Wrap result in <em>|</em>
2261 * @return string Localized [No title] string
2262 */
2263 public static function getNoRecordTitle($prep = false)
2264 {
2265 $noTitle = '[' .
2266 htmlspecialchars(static::getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.no_title'))
2267 . ']';
2268 if ($prep) {
2269 $noTitle = '<em>' . $noTitle . '</em>';
2270 }
2271 return $noTitle;
2272 }
2273
2274 /**
2275 * Returns a human readable output of a value from a record
2276 * For instance a database record relation would be looked up to display the title-value of that record. A checkbox with a "1" value would be "Yes", etc.
2277 * $table/$col is tablename and fieldname
2278 * REMEMBER to pass the output through htmlspecialchars() if you output it to the browser! (To protect it from XSS attacks and be XHTML compliant)
2279 *
2280 * @param string $table Table name, present in TCA
2281 * @param string $col Field name, present in TCA
2282 * @param string $value The value of that field from a selected record
2283 * @param int $fixed_lgd_chars The max amount of characters the value may occupy
2284 * @param bool $defaultPassthrough Flag means that values for columns that has no conversion will just be pass through directly (otherwise cropped to 200 chars or returned as "N/A")
2285 * @param bool $noRecordLookup If set, no records will be looked up, UIDs are just shown.
2286 * @param int $uid Uid of the current record
2287 * @param bool $forceResult If BackendUtility::getRecordTitle is used to process the value, this parameter is forwarded.
2288 * @param int $pid Optional page uid is used to evaluate page TSConfig for the given field
2289 * @throws \InvalidArgumentException
2290 * @return string|null
2291 */
2292 public static function getProcessedValue(
2293 $table,
2294 $col,
2295 $value,
2296 $fixed_lgd_chars = 0,
2297 $defaultPassthrough = false,
2298 $noRecordLookup = false,
2299 $uid = 0,
2300 $forceResult = true,
2301 $pid = 0
2302 ) {
2303 if ($col === 'uid') {
2304 // uid is not in TCA-array
2305 return $value;
2306 }
2307 // Check if table and field is configured
2308 if (!is_array($GLOBALS['TCA'][$table]) || !is_array($GLOBALS['TCA'][$table]['columns'][$col])) {
2309 return null;
2310 }
2311 // Depending on the fields configuration, make a meaningful output value.
2312 $theColConf = $GLOBALS['TCA'][$table]['columns'][$col]['config'];
2313 /*****************
2314 *HOOK: pre-processing the human readable output from a record
2315 ****************/
2316 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['preProcessValue'])) {
2317 // Create NULL-reference
2318 $null = null;
2319 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['preProcessValue'] as $_funcRef) {
2320 GeneralUtility::callUserFunction($_funcRef, $theColConf, $null);
2321 }
2322 }
2323 $l = '';
2324 $lang = static::getLanguageService();
2325 switch ((string)$theColConf['type']) {
2326 case 'radio':
2327 $l = self::getLabelFromItemlist($table, $col, $value);
2328 $l = $lang->sL($l);
2329 break;
2330 case 'inline':
2331 case 'select':
2332 if (!empty($theColConf['MM'])) {
2333 if ($uid) {
2334 // Display the title of MM related records in lists
2335 if ($noRecordLookup) {
2336 $MMfields = [];
2337 $MMfields[] = $theColConf['foreign_table'] . '.uid';
2338 } else {
2339 $MMfields = [$theColConf['foreign_table'] . '.' . $GLOBALS['TCA'][$theColConf['foreign_table']]['ctrl']['label']];
2340 foreach (GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$theColConf['foreign_table']]['ctrl']['label_alt'], true) as $f) {
2341 $MMfields[] = $theColConf['foreign_table'] . '.' . $f;
2342 }
2343 }
2344 /** @var $dbGroup RelationHandler */
2345 $dbGroup = GeneralUtility::makeInstance(RelationHandler::class);
2346 $dbGroup->start(
2347 $value,
2348 $theColConf['foreign_table'],
2349 $theColConf['MM'],
2350 $uid,
2351 $table,
2352 $theColConf
2353 );
2354 $selectUids = $dbGroup->tableArray[$theColConf['foreign_table']];
2355 if (is_array($selectUids) && !empty($selectUids)) {
2356 $queryBuilder = static::getQueryBuilderForTable($theColConf['foreign_table']);
2357 $queryBuilder->getRestrictions()
2358 ->removeAll()
2359 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
2360
2361 $result = $queryBuilder
2362 ->select('uid', ...$MMfields)
2363 ->from($theColConf['foreign_table'])
2364 ->where(
2365 $queryBuilder->expr()->in(
2366 'uid',
2367 $queryBuilder->createNamedParameter($selectUids, Connection::PARAM_INT_ARRAY)
2368 )
2369 )
2370 ->execute();
2371
2372 $mmlA = [];
2373 while ($MMrow = $result->fetch()) {
2374 // Keep sorting of $selectUids
2375 $selectedUid = array_search($MMrow['uid'], $selectUids);
2376 $mmlA[$selectedUid] = $MMrow['uid'];
2377 if (!$noRecordLookup) {
2378 $mmlA[$selectedUid] = static::getRecordTitle(
2379 $theColConf['foreign_table'],
2380 $MMrow,
2381 false,
2382 $forceResult
2383 );
2384 }
2385 }
2386
2387 if (!empty($mmlA)) {
2388 ksort($mmlA);
2389 $l = implode('; ', $mmlA);
2390 } else {
2391 $l = 'N/A';
2392 }
2393 } else {
2394 $l = 'N/A';
2395 }
2396 } else {
2397 $l = 'N/A';
2398 }
2399 } else {
2400 $columnTsConfig = [];
2401 if ($pid) {
2402 $pageTsConfig = self::getPagesTSconfig($pid);
2403 if (isset($pageTsConfig['TCEFORM.'][$table . '.'][$col . '.']) && is_array($pageTsConfig['TCEFORM.'][$table . '.'][$col . '.'])) {
2404 $columnTsConfig = $pageTsConfig['TCEFORM.'][$table . '.'][$col . '.'];
2405 }
2406 }
2407 $l = self::getLabelsFromItemsList($table, $col, $value, $columnTsConfig);
2408 if (!empty($theColConf['foreign_table']) && !$l && !empty($GLOBALS['TCA'][$theColConf['foreign_table']])) {
2409 if ($noRecordLookup) {
2410 $l = $value;
2411 } else {
2412 $rParts = [];
2413 if ($uid && isset($theColConf['foreign_field']) && $theColConf['foreign_field'] !== '') {
2414 $queryBuilder = static::getQueryBuilderForTable($theColConf['foreign_table']);
2415 $queryBuilder->getRestrictions()
2416 ->removeAll()
2417 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
2418 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
2419 $constraints = [
2420 $queryBuilder->expr()->eq(
2421 $theColConf['foreign_field'],
2422 $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
2423 )
2424 ];
2425
2426 if (!empty($theColConf['foreign_table_field'])) {
2427 $constraints[] = $queryBuilder->expr()->eq(
2428 $theColConf['foreign_table_field'],
2429 $queryBuilder->createNamedParameter($table, \PDO::PARAM_STR)
2430 );
2431 }
2432
2433 // Add additional where clause if foreign_match_fields are defined
2434 $foreignMatchFields = [];
2435 if (is_array($theColConf['foreign_match_fields'])) {
2436 $foreignMatchFields = $theColConf['foreign_match_fields'];
2437 }
2438
2439 foreach ($foreignMatchFields as $matchField => $matchValue) {
2440 $constraints[] = $queryBuilder->expr()->eq(
2441 $matchField,
2442 $queryBuilder->createNamedParameter($matchValue)
2443 );
2444 }
2445
2446 $result = $queryBuilder
2447 ->select('*')
2448 ->from($theColConf['foreign_table'])
2449 ->where(...$constraints)
2450 ->execute();
2451
2452 while ($record = $result->fetch()) {
2453 $rParts[] = $record['uid'];
2454 }
2455 }
2456 if (empty($rParts)) {
2457 $rParts = GeneralUtility::trimExplode(',', $value, true);
2458 }
2459 $lA = [];
2460 foreach ($rParts as $rVal) {
2461 $rVal = (int)$rVal;
2462 $r = self::getRecordWSOL($theColConf['foreign_table'], $rVal);
2463 if (is_array($r)) {
2464 $lA[] = $lang->sL($theColConf['foreign_table_prefix'])
2465 . self::getRecordTitle($theColConf['foreign_table'], $r, false, $forceResult);
2466 } else {
2467 $lA[] = $rVal ? '[' . $rVal . '!]' : '';
2468 }
2469 }
2470 $l = implode(', ', $lA);
2471 }
2472 }
2473 if (empty($l) && !empty($value)) {
2474 // Use plain database value when label is empty
2475 $l = $value;
2476 }
2477 }
2478 break;
2479 case 'group':
2480 // resolve the titles for DB records
2481 if ($theColConf['internal_type'] === 'db') {
2482 if ($theColConf['MM']) {
2483 if ($uid) {
2484 // Display the title of MM related records in lists
2485 if ($noRecordLookup) {
2486 $MMfields = [];
2487 $MMfields[] = $theColConf['foreign_table'] . '.uid';
2488 } else {
2489 $MMfields = [$theColConf['foreign_table'] . '.' . $GLOBALS['TCA'][$theColConf['foreign_table']]['ctrl']['label']];
2490 $altLabelFields = explode(
2491 ',',
2492 $GLOBALS['TCA'][$theColConf['foreign_table']]['ctrl']['label_alt']
2493 );
2494 foreach ($altLabelFields as $f) {
2495 $f = trim($f);
2496 if ($f !== '') {
2497 $MMfields[] = $theColConf['foreign_table'] . '.' . $f;
2498 }
2499 }
2500 }
2501 /** @var $dbGroup RelationHandler */
2502 $dbGroup = GeneralUtility::makeInstance(RelationHandler::class);
2503 $dbGroup->start(
2504 $value,
2505 $theColConf['foreign_table'],
2506 $theColConf['MM'],
2507 $uid,
2508 $table,
2509 $theColConf
2510 );
2511 $selectUids = $dbGroup->tableArray[$theColConf['foreign_table']];
2512 if (!empty($selectUids) && is_array($selectUids)) {
2513 $queryBuilder = static::getQueryBuilderForTable($theColConf['foreign_table']);
2514 $queryBuilder->getRestrictions()
2515 ->removeAll()
2516 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
2517
2518 $result = $queryBuilder
2519 ->select('uid', ...$MMfields)
2520 ->from($theColConf['foreign_table'])
2521 ->where(
2522 $queryBuilder->expr()->in(
2523 'uid',
2524 $queryBuilder->createNamedParameter(
2525 $selectUids,
2526 Connection::PARAM_INT_ARRAY
2527 )
2528 )
2529 )
2530 ->execute();
2531
2532 $mmlA = [];
2533 while ($MMrow = $result->fetch()) {
2534 // Keep sorting of $selectUids
2535 $selectedUid = array_search($MMrow['uid'], $selectUids);
2536 $mmlA[$selectedUid] = $MMrow['uid'];
2537 if (!$noRecordLookup) {
2538 $mmlA[$selectedUid] = static::getRecordTitle(
2539 $theColConf['foreign_table'],
2540 $MMrow,
2541 false,
2542 $forceResult
2543 );
2544 }
2545 }
2546
2547 if (!empty($mmlA)) {
2548 ksort($mmlA);
2549 $l = implode('; ', $mmlA);
2550 } else {
2551 $l = 'N/A';
2552 }
2553 } else {
2554 $l = 'N/A';
2555 }
2556 } else {
2557 $l = 'N/A';
2558 }
2559 } else {
2560 $finalValues = [];
2561 $relationTableName = $theColConf['allowed'];
2562 $explodedValues = GeneralUtility::trimExplode(',', $value, true);
2563
2564 foreach ($explodedValues as $explodedValue) {
2565 if (MathUtility::canBeInterpretedAsInteger($explodedValue)) {
2566 $relationTableNameForField = $relationTableName;
2567 } else {
2568 list($relationTableNameForField, $explodedValue) = self::splitTable_Uid($explodedValue);
2569 }
2570
2571 $relationRecord = static::getRecordWSOL($relationTableNameForField, $explodedValue);
2572 $finalValues[] = static::getRecordTitle($relationTableNameForField, $relationRecord);
2573 }
2574 $l = implode(', ', $finalValues);
2575 }
2576 } else {
2577 $l = implode(', ', GeneralUtility::trimExplode(',', $value, true));
2578 }
2579 break;
2580 case 'check':
2581 if (!is_array($theColConf['items']) || count($theColConf['items']) === 1) {
2582 $l = $value ? $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:yes') : $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:no');
2583 } else {
2584 $lA = [];
2585 foreach ($theColConf['items'] as $key => $val) {
2586 if ($value & pow(2, $key)) {
2587 $lA[] = $lang->sL($val[0]);
2588 }
2589 }
2590 $l = implode(', ', $lA);
2591 }
2592 break;
2593 case 'input':
2594 // Hide value 0 for dates, but show it for everything else
2595 if (isset($value)) {
2596 if (GeneralUtility::inList($theColConf['eval'], 'date')) {
2597 // Handle native date field
2598 if (isset($theColConf['dbType']) && $theColConf['dbType'] === 'date') {
2599 $dateTimeFormats = QueryHelper::getDateTimeFormats();
2600 $emptyValue = $dateTimeFormats['date']['empty'];
2601 $value = $value !== $emptyValue ? strtotime($value) : 0;
2602 }
2603 if (!empty($value)) {
2604 $ageSuffix = '';
2605 $dateColumnConfiguration = $GLOBALS['TCA'][$table]['columns'][$col]['config'];
2606 $ageDisplayKey = 'disableAgeDisplay';
2607
2608 // generate age suffix as long as not explicitly suppressed
2609 if (!isset($dateColumnConfiguration[$ageDisplayKey])
2610 // non typesafe comparison on intention
2611 || $dateColumnConfiguration[$ageDisplayKey] == false
2612 ) {
2613 $ageSuffix = ' (' . ($GLOBALS['EXEC_TIME'] - $value > 0 ? '-' : '')
2614 . self::calcAge(
2615 abs(($GLOBALS['EXEC_TIME'] - $value)),
2616 $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears')
2617 )
2618 . ')';
2619 }
2620
2621 $l = self::date($value) . $ageSuffix;
2622 }
2623 } elseif (GeneralUtility::inList($theColConf['eval'], 'time')) {
2624 if (!empty($value)) {
2625 $l = gmdate('H:i', (int)$value);
2626 }
2627 } elseif (GeneralUtility::inList($theColConf['eval'], 'timesec')) {
2628 if (!empty($value)) {
2629 $l = gmdate('H:i:s', (int)$value);
2630 }
2631 } elseif (GeneralUtility::inList($theColConf['eval'], 'datetime')) {
2632 // Handle native date/time field
2633 if (isset($theColConf['dbType']) && $theColConf['dbType'] === 'datetime') {
2634 $dateTimeFormats = QueryHelper::getDateTimeFormats();
2635 $emptyValue = $dateTimeFormats['datetime']['empty'];
2636 $value = $value !== $emptyValue ? strtotime($value) : 0;
2637 }
2638 if (!empty($value)) {
2639 $l = self::datetime($value);
2640 }
2641 } else {
2642 $l = $value;
2643 }
2644 }
2645 break;
2646 case 'flex':
2647 $l = strip_tags($value);
2648 break;
2649 default:
2650 if ($defaultPassthrough) {
2651 $l = $value;
2652 } elseif ($theColConf['MM']) {
2653 $l = 'N/A';
2654 } elseif ($value) {
2655 $l = GeneralUtility::fixed_lgd_cs(strip_tags($value), 200);
2656 }
2657 }
2658 // If this field is a password field, then hide the password by changing it to a random number of asterisk (*)
2659 if (!empty($theColConf['eval']) && stristr($theColConf['eval'], 'password')) {
2660 $l = '';
2661 $randomNumber = rand(5, 12);
2662 for ($i = 0; $i < $randomNumber; $i++) {
2663 $l .= '*';
2664 }
2665 }
2666 /*****************
2667 *HOOK: post-processing the human readable output from a record
2668 ****************/
2669 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['postProcessValue'])) {
2670 // Create NULL-reference
2671 $null = null;
2672 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['postProcessValue'] as $_funcRef) {
2673 $params = [
2674 'value' => $l,
2675 'colConf' => $theColConf
2676 ];
2677 $l = GeneralUtility::callUserFunction($_funcRef, $params, $null);
2678 }
2679 }
2680 if ($fixed_lgd_chars) {
2681 return GeneralUtility::fixed_lgd_cs($l, $fixed_lgd_chars);
2682 }
2683 return $l;
2684 }
2685
2686 /**
2687 * Same as ->getProcessedValue() but will go easy on fields like "tstamp" and "pid" which are not configured in TCA - they will be formatted by this function instead.
2688 *
2689 * @param string $table Table name, present in TCA
2690 * @param string $fN Field name
2691 * @param string $fV Field value
2692 * @param int $fixed_lgd_chars The max amount of characters the value may occupy
2693 * @param int $uid Uid of the current record
2694 * @param bool $forceResult If BackendUtility::getRecordTitle is used to process the value, this parameter is forwarded.
2695 * @param int $pid Optional page uid is used to evaluate page TSConfig for the given field
2696 * @return string
2697 * @see getProcessedValue()
2698 */
2699 public static function getProcessedValueExtra(
2700 $table,
2701 $fN,
2702 $fV,
2703 $fixed_lgd_chars = 0,
2704 $uid = 0,
2705 $forceResult = true,
2706 $pid = 0
2707 ) {
2708 $fVnew = self::getProcessedValue($table, $fN, $fV, $fixed_lgd_chars, 1, 0, $uid, $forceResult, $pid);
2709 if (!isset($fVnew)) {
2710 if (is_array($GLOBALS['TCA'][$table])) {
2711 if ($fN == $GLOBALS['TCA'][$table]['ctrl']['tstamp'] || $fN == $GLOBALS['TCA'][$table]['ctrl']['crdate']) {
2712 $fVnew = self::datetime($fV);
2713 } elseif ($fN === 'pid') {
2714 // Fetches the path with no regard to the users permissions to select pages.
2715 $fVnew = self::getRecordPath($fV, '1=1', 20);
2716 } else {
2717 $fVnew = $fV;
2718 }
2719 }
2720 }
2721 return $fVnew;
2722 }
2723
2724 /**
2725 * Returns fields for a table, $table, which would typically be interesting to select
2726 * This includes uid, the fields defined for title, icon-field.
2727 * Returned as a list ready for query ($prefix can be set to eg. "pages." if you are selecting from the pages table and want the table name prefixed)
2728 *
2729 * @param string $table Table name, present in $GLOBALS['TCA']
2730 * @param string $prefix Table prefix
2731 * @param array $fields Preset fields (must include prefix if that is used)
2732 * @return string List of fields.
2733 */
2734 public static function getCommonSelectFields($table, $prefix = '', $fields = [])
2735 {
2736 $fields[] = $prefix . 'uid';
2737 if (isset($GLOBALS['TCA'][$table]['ctrl']['label']) && $GLOBALS['TCA'][$table]['ctrl']['label'] != '') {
2738 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['label'];
2739 }
2740 if ($GLOBALS['TCA'][$table]['ctrl']['label_alt']) {
2741 $secondFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['label_alt'], true);
2742 foreach ($secondFields as $fieldN) {
2743 $fields[] = $prefix . $fieldN;
2744 }
2745 }
2746 if (static::isTableWorkspaceEnabled($table)) {
2747 $fields[] = $prefix . 't3ver_id';
2748 $fields[] = $prefix . 't3ver_state';
2749 $fields[] = $prefix . 't3ver_wsid';
2750 $fields[] = $prefix . 't3ver_count';
2751 }
2752 if ($GLOBALS['TCA'][$table]['ctrl']['selicon_field']) {
2753 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['selicon_field'];
2754 }
2755 if ($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
2756 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
2757 }
2758 if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
2759 if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']) {
2760 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
2761 }
2762 if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime']) {
2763 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime'];
2764 }
2765 if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime']) {
2766 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime'];
2767 }
2768 if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group']) {
2769 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group'];
2770 }
2771 }
2772 return implode(',', array_unique($fields));
2773 }
2774
2775 /**
2776 * Makes a form for configuration of some values based on configuration found in the array $configArray,
2777 * with default values from $defaults and a data-prefix $dataPrefix
2778 * <form>-tags must be supplied separately
2779 * Needs more documentation and examples, in particular syntax for configuration array. See Inside TYPO3.
2780 * That's were you can expect to find example, if anywhere.
2781 *
2782 * @param array $configArray Field configuration code.
2783 * @param array $defaults Defaults
2784 * @param string $dataPrefix Prefix for formfields
2785 * @return string HTML for a form.
2786 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
2787 */
2788 public static function makeConfigForm($configArray, $defaults, $dataPrefix)
2789 {
2790 GeneralUtility::logDeprecatedFunction();
2791 $params = $defaults;
2792 $lines = [];
2793 if (is_array($configArray)) {
2794 foreach ($configArray as $fname => $config) {
2795 if (is_array($config)) {
2796 $lines[$fname] = '<strong>' . htmlspecialchars($config[1]) . '</strong><br />';
2797 $lines[$fname] .= $config[2] . '<br />';
2798 switch ($config[0]) {
2799 case 'string':
2800
2801 case 'short':
2802 $formEl = '<input type="text" name="' . $dataPrefix . '[' . $fname . ']" value="' . $params[$fname] . '"' . static::getDocumentTemplate()->formWidth(($config[0] === 'short' ? 24 : 48)) . ' />';
2803 break;
2804 case 'check':
2805 $formEl = '<input type="hidden" name="' . $dataPrefix . '[' . $fname . ']" value="0" /><input type="checkbox" name="' . $dataPrefix . '[' . $fname . ']" value="1"' . ($params[$fname] ? ' checked="checked"' : '') . ' />';
2806 break;
2807 case 'comment':
2808 $formEl = '';
2809 break;
2810 case 'select':
2811 $opt = [];
2812 foreach ($config[3] as $k => $v) {
2813 $opt[] = '<option value="' . htmlspecialchars($k) . '"' . ($params[$fname] == $k ? ' selected="selected"' : '') . '>' . htmlspecialchars($v) . '</option>';
2814 }
2815 $formEl = '<select name="' . $dataPrefix . '[' . $fname . ']">'
2816 . implode('', $opt) . '</select>';
2817 break;
2818 default:
2819 $formEl = '<strong>Should not happen. Bug in config.</strong>';
2820 }
2821 $lines[$fname] .= $formEl;
2822 $lines[$fname] .= '<br /><br />';
2823 } else {
2824 $lines[$fname] = '<hr />';
2825 if ($config) {
2826 $lines[$fname] .= '<strong>' . strtoupper(htmlspecialchars($config)) . '</strong><br />';
2827 }
2828 if ($config) {
2829 $lines[$fname] .= '<br />';
2830 }
2831 }
2832 }
2833 }
2834 $out = implode('', $lines);
2835 $out .= '<input class="btn btn-default" type="submit" name="submit" value="Update configuration" />';
2836 return $out;
2837 }
2838
2839 /*******************************************
2840 *
2841 * Backend Modules API functions
2842 *
2843 *******************************************/
2844
2845 /**
2846 * Returns CSH help text (description), if configured for, as an array (title, description)
2847 *
2848 * @param string $table Table name
2849 * @param string $field Field name
2850 * @return array With keys 'description' (raw, as available in locallang), 'title' (optional), 'moreInfo'
2851 */
2852 public static function helpTextArray($table, $field)
2853 {
2854 if (!isset($GLOBALS['TCA_DESCR'][$table]['columns'])) {
2855 static::getLanguageService()->loadSingleTableDescription($table);
2856 }
2857 $output = [
2858 'description' => null,
2859 'title' => null,
2860 'moreInfo' => false
2861 ];