[BUGFIX] Use correct runtime cache identifier for locked records
[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($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 null|QueryBuilder $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['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])) {
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])) {
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 static $pagesTSconfig_cacheReference = [];
1239 static $combinedTSconfig_cache = [];
1240
1241 $id = (int)$id;
1242 if ($returnPartArray === false
1243 && $rootLine === null
1244 && isset($pagesTSconfig_cacheReference[$id])
1245 ) {
1246 return $combinedTSconfig_cache[$pagesTSconfig_cacheReference[$id]];
1247 }
1248 $TSconfig = [];
1249 if (!is_array($rootLine)) {
1250 $useCacheForCurrentPageId = true;
1251 $rootLine = self::BEgetRootLine($id, '', true);
1252 } else {
1253 $useCacheForCurrentPageId = false;
1254 }
1255
1256 // Order correctly
1257 ksort($rootLine);
1258 $TSdataArray = [];
1259 // Setting default configuration
1260 $TSdataArray['defaultPageTSconfig'] = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
1261 foreach ($rootLine as $k => $v) {
1262 if (trim($v['tsconfig_includes'])) {
1263 $includeTsConfigFileList = GeneralUtility::trimExplode(',', $v['tsconfig_includes'], true);
1264 // Traversing list
1265 foreach ($includeTsConfigFileList as $key => $includeTsConfigFile) {
1266 if (strpos($includeTsConfigFile, 'EXT:') === 0) {
1267 list($includeTsConfigFileExtensionKey, $includeTsConfigFilename) = explode(
1268 '/',
1269 substr($includeTsConfigFile, 4),
1270 2
1271 );
1272 if ((string)$includeTsConfigFileExtensionKey !== ''
1273 && ExtensionManagementUtility::isLoaded($includeTsConfigFileExtensionKey)
1274 && (string)$includeTsConfigFilename !== ''
1275 ) {
1276 $includeTsConfigFileAndPath = ExtensionManagementUtility::extPath($includeTsConfigFileExtensionKey) .
1277 $includeTsConfigFilename;
1278 if (file_exists($includeTsConfigFileAndPath)) {
1279 $TSdataArray['uid_' . $v['uid'] . '_static_' . $key] = file_get_contents($includeTsConfigFileAndPath);
1280 }
1281 }
1282 }
1283 }
1284 }
1285 $TSdataArray['uid_' . $v['uid']] = $v['TSconfig'];
1286 }
1287 $TSdataArray = static::emitGetPagesTSconfigPreIncludeSignal($TSdataArray, $id, $rootLine, $returnPartArray);
1288 $TSdataArray = TypoScriptParser::checkIncludeLines_array($TSdataArray);
1289 if ($returnPartArray) {
1290 return $TSdataArray;
1291 }
1292 // Parsing the page TS-Config
1293 $pageTS = implode(LF . '[GLOBAL]' . LF, $TSdataArray);
1294 /* @var $parseObj \TYPO3\CMS\Backend\Configuration\TsConfigParser */
1295 $parseObj = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Configuration\TsConfigParser::class);
1296 $res = $parseObj->parseTSconfig($pageTS, 'PAGES', $id, $rootLine);
1297 if ($res) {
1298 $TSconfig = $res['TSconfig'];
1299 }
1300 $cacheHash = $res['hash'];
1301 // Get User TSconfig overlay
1302 $userTSconfig = static::getBackendUserAuthentication()->userTS['page.'];
1303 if (is_array($userTSconfig)) {
1304 ArrayUtility::mergeRecursiveWithOverrule($TSconfig, $userTSconfig);
1305 $cacheHash .= '_user' . $GLOBALS['BE_USER']->user['uid'];
1306 }
1307
1308 if ($useCacheForCurrentPageId) {
1309 if (!isset($combinedTSconfig_cache[$cacheHash])) {
1310 $combinedTSconfig_cache[$cacheHash] = $TSconfig;
1311 }
1312 $pagesTSconfig_cacheReference[$id] = $cacheHash;
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 = explode('|', $labels);
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 NULL|int $workspaceId Workspace to fetch data for
1607 * @return NULL|\TYPO3\CMS\Core\Resource\FileReference[]
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 $processedImage = $fileObject->process(
1730 ProcessedFile::CONTEXT_IMAGECROPSCALEMASK,
1731 [
1732 'width' => $sizeParts[0],
1733 'height' => $sizeParts[1] . 'c',
1734 'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($fileReferenceObject)
1735 ]
1736 );
1737 $imageUrl = $processedImage->getPublicUrl(true);
1738 $imgTag = '<img src="' . $imageUrl . '" '
1739 . 'width="' . $processedImage->getProperty('width') . '" '
1740 . 'height="' . $processedImage->getProperty('height') . '" '
1741 . 'alt="' . htmlspecialchars($fileReferenceObject->getName()) . '" />';
1742 } else {
1743 // Icon
1744 $imgTag = '<span title="' . htmlspecialchars($fileObject->getName()) . '">'
1745 . $iconFactory->getIconForResource($fileObject, Icon::SIZE_SMALL)->render()
1746 . '</span>';
1747 }
1748 if ($linkInfoPopup) {
1749 $onClick = 'top.launchView(\'_FILE\',\'' . (int)$fileObject->getUid() . '\'); return false;';
1750 $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $imgTag . '</a> ';
1751 } else {
1752 $thumbData .= $imgTag;
1753 }
1754 }
1755 } else {
1756 // Find uploaddir automatically
1757 if (is_null($uploaddir)) {
1758 $uploaddir = $GLOBALS['TCA'][$table]['columns'][$field]['config']['uploadfolder'];
1759 }
1760 $uploaddir = rtrim($uploaddir, '/');
1761 // Traverse files:
1762 $thumbs = GeneralUtility::trimExplode(',', $row[$field], true);
1763 $thumbData = '';
1764 foreach ($thumbs as $theFile) {
1765 if ($theFile) {
1766 $fileName = trim($uploaddir . '/' . $theFile, '/');
1767 try {
1768 /** @var File $fileObject */
1769 $fileObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($fileName);
1770 // Skip the resource if it's not of type AbstractFile. One case where this can happen if the
1771 // storage has been externally modified and the field value now points to a folder
1772 // instead of a file.
1773 if (!$fileObject instanceof AbstractFile) {
1774 continue;
1775 }
1776 if ($fileObject->isMissing()) {
1777 $thumbData .= '<span class="label label-danger">'
1778 . htmlspecialchars(static::getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
1779 . '</span>&nbsp;' . htmlspecialchars($fileObject->getName()) . '<br />';
1780 continue;
1781 }
1782 } catch (ResourceDoesNotExistException $exception) {
1783 $thumbData .= '<span class="label label-danger">'
1784 . htmlspecialchars(static::getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
1785 . '</span>&nbsp;' . htmlspecialchars($fileName) . '<br />';
1786 continue;
1787 }
1788
1789 $fileExtension = $fileObject->getExtension();
1790 if ($fileExtension === 'ttf'
1791 || GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)
1792 ) {
1793 $imageUrl = $fileObject->process(
1794 ProcessedFile::CONTEXT_IMAGEPREVIEW,
1795 [
1796 'width' => $sizeParts[0],
1797 'height' => $sizeParts[1]
1798 ]
1799 )->getPublicUrl(true);
1800
1801 $image = '<img src="' . htmlspecialchars($imageUrl) . '" hspace="2" border="0" title="' . htmlspecialchars($fileObject->getName()) . '"' . $tparams . ' alt="" />';
1802 if ($linkInfoPopup) {
1803 $onClick = 'top.launchView(\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileName) . ',\'\');return false;';
1804 $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $image . '</a> ';
1805 } else {
1806 $thumbData .= $image;
1807 }
1808 } else {
1809 // Gets the icon
1810 $fileIcon = '<span title="' . htmlspecialchars($fileObject->getName()) . '">'
1811 . $iconFactory->getIconForResource($fileObject, Icon::SIZE_SMALL)->render()
1812 . '</span>';
1813 if ($linkInfoPopup) {
1814 $onClick = 'top.launchView(\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileName) . ',\'\'); return false;';
1815 $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $fileIcon . '</a> ';
1816 } else {
1817 $thumbData .= $fileIcon;
1818 }
1819 }
1820 }
1821 }
1822 }
1823 return $thumbData;
1824 }
1825
1826 /**
1827 * Returns title-attribute information for a page-record informing about id, alias, doktype, hidden, starttime, endtime, fe_group etc.
1828 *
1829 * @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)
1830 * @param string $perms_clause This is used to get the record path of the shortcut page, if any (and doktype==4)
1831 * @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
1832 * @return string
1833 */
1834 public static function titleAttribForPages($row, $perms_clause = '', $includeAttrib = true)
1835 {
1836 $lang = static::getLanguageService();
1837 $parts = [];
1838 $parts[] = 'id=' . $row['uid'];
1839 if ($row['alias']) {
1840 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['alias']['label']) . ' ' . $row['alias'];
1841 }
1842 if ($row['pid'] < 0) {
1843 $parts[] = 'v#1.' . $row['t3ver_id'];
1844 }
1845 switch (VersionState::cast($row['t3ver_state'])) {
1846 case new VersionState(VersionState::NEW_PLACEHOLDER):
1847 $parts[] = 'PLH WSID#' . $row['t3ver_wsid'];
1848 break;
1849 case new VersionState(VersionState::DELETE_PLACEHOLDER):
1850 $parts[] = 'Deleted element!';
1851 break;
1852 case new VersionState(VersionState::MOVE_PLACEHOLDER):
1853 $parts[] = 'NEW LOCATION (PLH) WSID#' . $row['t3ver_wsid'];
1854 break;
1855 case new VersionState(VersionState::MOVE_POINTER):
1856 $parts[] = 'OLD LOCATION (PNT) WSID#' . $row['t3ver_wsid'];
1857 break;
1858 case new VersionState(VersionState::NEW_PLACEHOLDER_VERSION):
1859 $parts[] = 'New element!';
1860 break;
1861 }
1862 if ($row['doktype'] == PageRepository::DOKTYPE_LINK) {
1863 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['url']['label']) . ' ' . $row['url'];
1864 } elseif ($row['doktype'] == PageRepository::DOKTYPE_SHORTCUT) {
1865 if ($perms_clause) {
1866 $label = self::getRecordPath((int)$row['shortcut'], $perms_clause, 20);
1867 } else {
1868 $row['shortcut'] = (int)$row['shortcut'];
1869 $lRec = self::getRecordWSOL('pages', $row['shortcut'], 'title');
1870 $label = $lRec['title'] . ' (id=' . $row['shortcut'] . ')';
1871 }
1872 if ($row['shortcut_mode'] != PageRepository::SHORTCUT_MODE_NONE) {
1873 $label .= ', ' . $lang->sL($GLOBALS['TCA']['pages']['columns']['shortcut_mode']['label']) . ' '
1874 . $lang->sL(self::getLabelFromItemlist('pages', 'shortcut_mode', $row['shortcut_mode']));
1875 }
1876 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['shortcut']['label']) . ' ' . $label;
1877 } elseif ($row['doktype'] == PageRepository::DOKTYPE_MOUNTPOINT) {
1878 if ($perms_clause) {
1879 $label = self::getRecordPath((int)$row['mount_pid'], $perms_clause, 20);
1880 } else {
1881 $lRec = self::getRecordWSOL('pages', (int)$row['mount_pid'], 'title');
1882 $label = $lRec['title'] . ' (id=' . $row['mount_pid'] . ')';
1883 }
1884 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['mount_pid']['label']) . ' ' . $label;
1885 if ($row['mount_pid_ol']) {
1886 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['mount_pid_ol']['label']);
1887 }
1888 }
1889 if ($row['nav_hide']) {
1890 $parts[] = rtrim($lang->sL($GLOBALS['TCA']['pages']['columns']['nav_hide']['label']), ':');
1891 }
1892 if ($row['hidden']) {
1893 $parts[] = $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.hidden');
1894 }
1895 if ($row['starttime']) {
1896 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['starttime']['label'])
1897 . ' ' . self::dateTimeAge($row['starttime'], -1, 'date');
1898 }
1899 if ($row['endtime']) {
1900 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['endtime']['label']) . ' '
1901 . self::dateTimeAge($row['endtime'], -1, 'date');
1902 }
1903 if ($row['fe_group']) {
1904 $fe_groups = [];
1905 foreach (GeneralUtility::intExplode(',', $row['fe_group']) as $fe_group) {
1906 if ($fe_group < 0) {
1907 $fe_groups[] = $lang->sL(self::getLabelFromItemlist('pages', 'fe_group', $fe_group));
1908 } else {
1909 $lRec = self::getRecordWSOL('fe_groups', $fe_group, 'title');
1910 $fe_groups[] = $lRec['title'];
1911 }
1912 }
1913 $label = implode(', ', $fe_groups);
1914 $parts[] = $lang->sL($GLOBALS['TCA']['pages']['columns']['fe_group']['label']) . ' ' . $label;
1915 }
1916 $out = htmlspecialchars(implode(' - ', $parts));
1917 return $includeAttrib ? 'title="' . $out . '"' : $out;
1918 }
1919
1920 /**
1921 * Returns the combined markup for Bootstraps tooltips
1922 *
1923 * @param array $row
1924 * @param string $table
1925 * @return string
1926 */
1927 public static function getRecordToolTip(array $row, $table = 'pages')
1928 {
1929 $toolTipText = self::getRecordIconAltText($row, $table);
1930 $toolTipCode = 'data-toggle="tooltip" data-title=" '
1931 . str_replace(' - ', '<br>', $toolTipText)
1932 . '" data-html="true" data-placement="right"';
1933 return $toolTipCode;
1934 }
1935
1936 /**
1937 * Returns title-attribute information for ANY record (from a table defined in TCA of course)
1938 * 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.
1939 * "pages" table can be used as well and will return the result of ->titleAttribForPages() for that page.
1940 *
1941 * @param array $row Table row; $row is a row from the table, $table
1942 * @param string $table Table name
1943 * @return string
1944 */
1945 public static function getRecordIconAltText($row, $table = 'pages')
1946 {
1947 if ($table === 'pages') {
1948 $out = self::titleAttribForPages($row, '', 0);
1949 } else {
1950 $out = !empty(trim($GLOBALS['TCA'][$table]['ctrl']['descriptionColumn'])) ? $row[$GLOBALS['TCA'][$table]['ctrl']['descriptionColumn']] . ' ' : '';
1951 $ctrl = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
1952 // Uid is added
1953 $out .= 'id=' . $row['uid'];
1954 if ($table === 'pages' && $row['alias']) {
1955 $out .= ' / ' . $row['alias'];
1956 }
1957 if (static::isTableWorkspaceEnabled($table) && $row['pid'] < 0) {
1958 $out .= ' - v#1.' . $row['t3ver_id'];
1959 }
1960 if (static::isTableWorkspaceEnabled($table)) {
1961 switch (VersionState::cast($row['t3ver_state'])) {
1962 case new VersionState(VersionState::NEW_PLACEHOLDER):
1963 $out .= ' - PLH WSID#' . $row['t3ver_wsid'];
1964 break;
1965 case new VersionState(VersionState::DELETE_PLACEHOLDER):
1966 $out .= ' - Deleted element!';
1967 break;
1968 case new VersionState(VersionState::MOVE_PLACEHOLDER):
1969 $out .= ' - NEW LOCATION (PLH) WSID#' . $row['t3ver_wsid'];
1970 break;
1971 case new VersionState(VersionState::MOVE_POINTER):
1972 $out .= ' - OLD LOCATION (PNT) WSID#' . $row['t3ver_wsid'];
1973 break;
1974 case new VersionState(VersionState::NEW_PLACEHOLDER_VERSION):
1975 $out .= ' - New element!';
1976 break;
1977 }
1978 }
1979 // Hidden
1980 $lang = static::getLanguageService();
1981 if ($ctrl['disabled']) {
1982 $out .= $row[$ctrl['disabled']] ? ' - ' . $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.hidden') : '';
1983 }
1984 if ($ctrl['starttime']) {
1985 if ($row[$ctrl['starttime']] > $GLOBALS['EXEC_TIME']) {
1986 $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') . ')';
1987 }
1988 }
1989 if ($row[$ctrl['endtime']]) {
1990 $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') . ')';
1991 }
1992 }
1993 return htmlspecialchars($out);
1994 }
1995
1996 /**
1997 * Returns the label of the first found entry in an "items" array from $GLOBALS['TCA'] (tablename = $table/fieldname = $col) where the value is $key
1998 *
1999 * @param string $table Table name, present in $GLOBALS['TCA']
2000 * @param string $col Field name, present in $GLOBALS['TCA']
2001 * @param string $key items-array value to match
2002 * @return string Label for item entry
2003 */
2004 public static function getLabelFromItemlist($table, $col, $key)
2005 {
2006 // Check, if there is an "items" array:
2007 if (is_array($GLOBALS['TCA'][$table])
2008 && is_array($GLOBALS['TCA'][$table]['columns'][$col])
2009 && is_array($GLOBALS['TCA'][$table]['columns'][$col]['config']['items'])
2010 ) {
2011 // Traverse the items-array...
2012 foreach ($GLOBALS['TCA'][$table]['columns'][$col]['config']['items'] as $v) {
2013 // ... and return the first found label where the value was equal to $key
2014 if ((string)$v[1] === (string)$key) {
2015 return $v[0];
2016 }
2017 }
2018 }
2019 return '';
2020 }
2021
2022 /**
2023 * Return the label of a field by additionally checking TsConfig values
2024 *
2025 * @param int $pageId Page id
2026 * @param string $table Table name
2027 * @param string $column Field Name
2028 * @param string $key item value
2029 * @return string Label for item entry
2030 */
2031 public static function getLabelFromItemListMerged($pageId, $table, $column, $key)
2032 {
2033 $pageTsConfig = static::getPagesTSconfig($pageId);
2034 $label = '';
2035 if (is_array($pageTsConfig['TCEFORM.'])
2036 && is_array($pageTsConfig['TCEFORM.'][$table . '.'])
2037 && is_array($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.'])
2038 ) {
2039 if (is_array($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['addItems.'])
2040 && isset($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['addItems.'][$key])
2041 ) {
2042 $label = $pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['addItems.'][$key];
2043 } elseif (is_array($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['altLabels.'])
2044 && isset($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['altLabels.'][$key])
2045 ) {
2046 $label = $pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['altLabels.'][$key];
2047 }
2048 }
2049 if (empty($label)) {
2050 $tcaValue = self::getLabelFromItemlist($table, $column, $key);
2051 if (!empty($tcaValue)) {
2052 $label = $tcaValue;
2053 }
2054 }
2055 return $label;
2056 }
2057
2058 /**
2059 * Splits the given key with commas and returns the list of all the localized items labels, separated by a comma.
2060 * NOTE: this does not take itemsProcFunc into account
2061 *
2062 * @param string $table Table name, present in TCA
2063 * @param string $column Field name
2064 * @param string $keyList Key or comma-separated list of keys.
2065 * @param array $columnTsConfig page TSConfig for $column (TCEMAIN.<table>.<column>)
2066 * @return string Comma-separated list of localized labels
2067 */
2068 public static function getLabelsFromItemsList($table, $column, $keyList, array $columnTsConfig = [])
2069 {
2070 // Check if there is an "items" array
2071 if (
2072 !isset($GLOBALS['TCA'][$table]['columns'][$column]['config']['items'])
2073 || !is_array($GLOBALS['TCA'][$table]['columns'][$column]['config']['items'])
2074 || $keyList === ''
2075 ) {
2076 return '';
2077 }
2078
2079 $keys = GeneralUtility::trimExplode(',', $keyList, true);
2080 $labels = [];
2081 // Loop on all selected values
2082 foreach ($keys as $key) {
2083 $label = null;
2084 if ($columnTsConfig) {
2085 // Check if label has been defined or redefined via pageTsConfig
2086 if (isset($columnTsConfig['addItems.'][$key])) {
2087 $label = $columnTsConfig['addItems.'][$key];
2088 } elseif (isset($columnTsConfig['altLabels.'][$key])) {
2089 $label = $columnTsConfig['altLabels.'][$key];
2090 }
2091 }
2092 if ($label === null) {
2093 // Otherwise lookup the label in TCA items list
2094 foreach ($GLOBALS['TCA'][$table]['columns'][$column]['config']['items'] as $itemConfiguration) {
2095 list($currentLabel, $currentKey) = $itemConfiguration;
2096 if ((string)$key === (string)$currentKey) {
2097 $label = $currentLabel;
2098 break;
2099 }
2100 }
2101 }
2102 if ($label !== null) {
2103 $labels[] = static::getLanguageService()->sL($label);
2104 }
2105 }
2106 return implode(', ', $labels);
2107 }
2108
2109 /**
2110 * Returns the label-value for fieldname $col in table, $table
2111 * 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>'
2112 *
2113 * @param string $table Table name, present in $GLOBALS['TCA']
2114 * @param string $col Field name
2115 * @return string or NULL if $col is not found in the TCA table
2116 */
2117 public static function getItemLabel($table, $col)
2118 {
2119 // Check if column exists
2120 if (is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'][$col])) {
2121 return $GLOBALS['TCA'][$table]['columns'][$col]['label'];
2122 }
2123
2124 return null;
2125 }
2126
2127 /**
2128 * Replace field values in given row with values from the original language
2129 * if l10n_mode TCA settings require to do so.
2130 *
2131 * @param string $table Table name
2132 * @param array $row Row to fill with original language values
2133 * @return array Row with values from the original language
2134 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9
2135 */
2136 protected static function replaceL10nModeFields($table, array $row)
2137 {
2138 GeneralUtility::logDeprecatedFunction();
2139 $originalUidField = isset($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'])
2140 ? $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']
2141 : '';
2142 if (empty($row[$originalUidField])) {
2143 return $row;
2144 }
2145
2146 $originalTable = self::getOriginalTranslationTable($table);
2147 $originalRow = self::getRecord($originalTable, $row[$originalUidField]);
2148 foreach ($row as $field => $_) {
2149 $l10n_mode = isset($GLOBALS['TCA'][$originalTable]['columns'][$field]['l10n_mode'])
2150 ? $GLOBALS['TCA'][$originalTable]['columns'][$field]['l10n_mode']
2151 : '';
2152 if ($l10n_mode === 'exclude') {
2153 $row[$field] = $originalRow[$field];
2154 }
2155 }
2156 return $row;
2157 }
2158
2159 /**
2160 * Returns the "title"-value in record, $row, from table, $table
2161 * The field(s) from which the value is taken is determined by the "ctrl"-entries 'label', 'label_alt' and 'label_alt_force'
2162 *
2163 * @param string $table Table name, present in TCA
2164 * @param array $row Row from table
2165 * @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
2166 * @param bool $forceResult If set, the function always returns an output. If no value is found for the title, '[No title]' is returned (localized).
2167 * @return string
2168 */
2169 public static function getRecordTitle($table, $row, $prep = false, $forceResult = true)
2170 {
2171 $recordTitle = '';
2172 if (is_array($GLOBALS['TCA'][$table])) {
2173 // If configured, call userFunc
2174 if ($GLOBALS['TCA'][$table]['ctrl']['label_userFunc']) {
2175 $params['table'] = $table;
2176 $params['row'] = $row;
2177 $params['title'] = '';
2178 $params['options'] = $GLOBALS['TCA'][$table]['ctrl']['label_userFunc_options'] ?? [];
2179
2180 // Create NULL-reference
2181 $null = null;
2182 GeneralUtility::callUserFunction($GLOBALS['TCA'][$table]['ctrl']['label_userFunc'], $params, $null);
2183 $recordTitle = $params['title'];
2184 } else {
2185 // No userFunc: Build label
2186 $recordTitle = self::getProcessedValue(
2187 $table,
2188 $GLOBALS['TCA'][$table]['ctrl']['label'],
2189 $row[$GLOBALS['TCA'][$table]['ctrl']['label']],
2190 0,
2191 0,
2192 false,
2193 $row['uid'],
2194 $forceResult
2195 );
2196 if ($GLOBALS['TCA'][$table]['ctrl']['label_alt']
2197 && ($GLOBALS['TCA'][$table]['ctrl']['label_alt_force'] || (string)$recordTitle === '')
2198 ) {
2199 $altFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['label_alt'], true);
2200 $tA = [];
2201 if (!empty($recordTitle)) {
2202 $tA[] = $recordTitle;
2203 }
2204 foreach ($altFields as $fN) {
2205 $recordTitle = trim(strip_tags($row[$fN]));
2206 if ((string)$recordTitle !== '') {
2207 $recordTitle = self::getProcessedValue($table, $fN, $recordTitle, 0, 0, false, $row['uid']);
2208 if (!$GLOBALS['TCA'][$table]['ctrl']['label_alt_force']) {
2209 break;
2210 }
2211 $tA[] = $recordTitle;
2212 }
2213 }
2214 if ($GLOBALS['TCA'][$table]['ctrl']['label_alt_force']) {
2215 $recordTitle = implode(', ', $tA);
2216 }
2217 }
2218 }
2219 // If the current result is empty, set it to '[No title]' (localized) and prepare for output if requested
2220 if ($prep || $forceResult) {
2221 if ($prep) {
2222 $recordTitle = self::getRecordTitlePrep($recordTitle);
2223 }
2224 if (trim($recordTitle) === '') {
2225 $recordTitle = self::getNoRecordTitle($prep);
2226 }
2227 }
2228 }
2229
2230 return $recordTitle;
2231 }
2232
2233 /**
2234 * Crops a title string to a limited length and if it really was cropped, wrap it in a <span title="...">|</span>,
2235 * which offers a tooltip with the original title when moving mouse over it.
2236 *
2237 * @param string $title The title string to be cropped
2238 * @param int $titleLength Crop title after this length - if not set, BE_USER->uc['titleLen'] is used
2239 * @return string The processed title string, wrapped in <span title="...">|</span> if cropped
2240 */
2241 public static function getRecordTitlePrep($title, $titleLength = 0)
2242 {
2243 // If $titleLength is not a valid positive integer, use BE_USER->uc['titleLen']:
2244 if (!$titleLength || !MathUtility::canBeInterpretedAsInteger($titleLength) || $titleLength < 0) {
2245 $titleLength = static::getBackendUserAuthentication()->uc['titleLen'];
2246 }
2247 $titleOrig = htmlspecialchars($title);
2248 $title = htmlspecialchars(GeneralUtility::fixed_lgd_cs($title, $titleLength));
2249 // If title was cropped, offer a tooltip:
2250 if ($titleOrig != $title) {
2251 $title = '<span title="' . $titleOrig . '">' . $title . '</span>';
2252 }
2253 return $title;
2254 }
2255
2256 /**
2257 * Get a localized [No title] string, wrapped in <em>|</em> if $prep is TRUE.
2258 *
2259 * @param bool $prep Wrap result in <em>|</em>
2260 * @return string Localized [No title] string
2261 */
2262 public static function getNoRecordTitle($prep = false)
2263 {
2264 $noTitle = '[' .
2265 htmlspecialchars(static::getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.no_title'))
2266 . ']';
2267 if ($prep) {
2268 $noTitle = '<em>' . $noTitle . '</em>';
2269 }
2270 return $noTitle;
2271 }
2272
2273 /**
2274 * Returns a human readable output of a value from a record
2275 * 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.
2276 * $table/$col is tablename and fieldname
2277 * REMEMBER to pass the output through htmlspecialchars() if you output it to the browser! (To protect it from XSS attacks and be XHTML compliant)
2278 *
2279 * @param string $table Table name, present in TCA
2280 * @param string $col Field name, present in TCA
2281 * @param string $value The value of that field from a selected record
2282 * @param int $fixed_lgd_chars The max amount of characters the value may occupy
2283 * @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")
2284 * @param bool $noRecordLookup If set, no records will be looked up, UIDs are just shown.
2285 * @param int $uid Uid of the current record
2286 * @param bool $forceResult If BackendUtility::getRecordTitle is used to process the value, this parameter is forwarded.
2287 * @param int $pid Optional page uid is used to evaluate page TSConfig for the given field
2288 * @throws \InvalidArgumentException
2289 * @return string|NULL
2290 */
2291 public static function getProcessedValue(
2292 $table,
2293 $col,
2294 $value,
2295 $fixed_lgd_chars = 0,
2296 $defaultPassthrough = false,
2297 $noRecordLookup = false,
2298 $uid = 0,
2299 $forceResult = true,
2300 $pid = 0
2301 ) {
2302 if ($col === 'uid') {
2303 // uid is not in TCA-array
2304 return $value;
2305 }
2306 // Check if table and field is configured
2307 if (!is_array($GLOBALS['TCA'][$table]) || !is_array($GLOBALS['TCA'][$table]['columns'][$col])) {
2308 return null;
2309 }
2310 // Depending on the fields configuration, make a meaningful output value.
2311 $theColConf = $GLOBALS['TCA'][$table]['columns'][$col]['config'];
2312 /*****************
2313 *HOOK: pre-processing the human readable output from a record
2314 ****************/
2315 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['preProcessValue'])) {
2316 // Create NULL-reference
2317 $null = null;
2318 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['preProcessValue'] as $_funcRef) {
2319 GeneralUtility::callUserFunction($_funcRef, $theColConf, $null);
2320 }
2321 }
2322 $l = '';
2323 $lang = static::getLanguageService();
2324 switch ((string)$theColConf['type']) {
2325 case 'radio':
2326 $l = self::getLabelFromItemlist($table, $col, $value);
2327 $l = $lang->sL($l);
2328 break;
2329 case 'inline':
2330 case 'select':
2331 if ($theColConf['MM']) {
2332 if ($uid) {
2333 // Display the title of MM related records in lists
2334 if ($noRecordLookup) {
2335 $MMfields = [];
2336 $MMfields[] = $theColConf['foreign_table'] . '.uid';
2337 } else {
2338 $MMfields = [$theColConf['foreign_table'] . '.' . $GLOBALS['TCA'][$theColConf['foreign_table']]['ctrl']['label']];
2339 foreach (GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$theColConf['foreign_table']]['ctrl']['label_alt'], true) as $f) {
2340 $MMfields[] = $theColConf['foreign_table'] . '.' . $f;
2341 }
2342 }
2343 /** @var $dbGroup RelationHandler */
2344 $dbGroup = GeneralUtility::makeInstance(RelationHandler::class);
2345 $dbGroup->start(
2346 $value,
2347 $theColConf['foreign_table'],
2348 $theColConf['MM'],
2349 $uid,
2350 $table,
2351 $theColConf
2352 );
2353 $selectUids = $dbGroup->tableArray[$theColConf['foreign_table']];
2354 if (is_array($selectUids) && !empty($selectUids)) {
2355 $queryBuilder = static::getQueryBuilderForTable($theColConf['foreign_table']);
2356 $queryBuilder->getRestrictions()
2357 ->removeAll()
2358 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
2359
2360 $result = $queryBuilder
2361 ->select('uid', ...$MMfields)
2362 ->from($theColConf['foreign_table'])
2363 ->where(
2364 $queryBuilder->expr()->in(
2365 'uid',
2366 $queryBuilder->createNamedParameter($selectUids, Connection::PARAM_INT_ARRAY)
2367 )
2368 )
2369 ->execute();
2370
2371 $mmlA = [];
2372 while ($MMrow = $result->fetch()) {
2373 // Keep sorting of $selectUids
2374 $selectedUid = array_search($MMrow['uid'], $selectUids);
2375 $mmlA[$selectedUid] = $MMrow['uid'];
2376 if (!$noRecordLookup) {
2377 $mmlA[$selectedUid] = static::getRecordTitle(
2378 $theColConf['foreign_table'],
2379 $MMrow,
2380 false,
2381 $forceResult
2382 );
2383 }
2384 }
2385
2386 if (!empty($mmlA)) {
2387 ksort($mmlA);
2388 $l = implode('; ', $mmlA);
2389 } else {
2390 $l = 'N/A';
2391 }
2392 } else {
2393 $l = 'N/A';
2394 }
2395 } else {
2396 $l = 'N/A';
2397 }
2398 } else {
2399 $columnTsConfig = [];
2400 if ($pid) {
2401 $pageTsConfig = self::getPagesTSconfig($pid);
2402 if (isset($pageTsConfig['TCEFORM.'][$table . '.'][$col . '.']) && is_array($pageTsConfig['TCEFORM.'][$table . '.'][$col . '.'])) {
2403 $columnTsConfig = $pageTsConfig['TCEFORM.'][$table . '.'][$col . '.'];
2404 }
2405 }
2406 $l = self::getLabelsFromItemsList($table, $col, $value, $columnTsConfig);
2407 if ($theColConf['foreign_table'] && !$l && $GLOBALS['TCA'][$theColConf['foreign_table']]) {
2408 if ($noRecordLookup) {
2409 $l = $value;
2410 } else {
2411 $rParts = [];
2412 if ($uid && isset($theColConf['foreign_field']) && $theColConf['foreign_field'] !== '') {
2413 $queryBuilder = static::getQueryBuilderForTable($theColConf['foreign_table']);
2414 $queryBuilder->getRestrictions()
2415 ->removeAll()
2416 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
2417 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
2418 $constraints = [
2419 $queryBuilder->expr()->eq(
2420 $theColConf['foreign_field'],
2421 $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
2422 )
2423 ];
2424
2425 if (!empty($theColConf['foreign_table_field'])) {
2426 $constraints[] = $queryBuilder->expr()->eq(
2427 $theColConf['foreign_table_field'],
2428 $queryBuilder->createNamedParameter($table, \PDO::PARAM_STR)
2429 );
2430 }
2431
2432 // Add additional where clause if foreign_match_fields are defined
2433 $foreignMatchFields = [];
2434 if (is_array($theColConf['foreign_match_fields'])) {
2435 $foreignMatchFields = $theColConf['foreign_match_fields'];
2436 }
2437
2438 foreach ($foreignMatchFields as $matchField => $matchValue) {
2439 $constraints[] = $queryBuilder->expr()->eq(
2440 $matchField,
2441 $queryBuilder->createNamedParameter($matchValue)
2442 );
2443 }
2444
2445 $result = $queryBuilder
2446 ->select('*')
2447 ->from($theColConf['foreign_table'])
2448 ->where(...$constraints)
2449 ->execute();
2450
2451 while ($record = $result->fetch()) {
2452 $rParts[] = $record['uid'];
2453 }
2454 }
2455 if (empty($rParts)) {
2456 $rParts = GeneralUtility::trimExplode(',', $value, true);
2457 }
2458 $lA = [];
2459 foreach ($rParts as $rVal) {
2460 $rVal = (int)$rVal;
2461 $r = self::getRecordWSOL($theColConf['foreign_table'], $rVal);
2462 if (is_array($r)) {
2463 $lA[] = $lang->sL($theColConf['foreign_table_prefix'])
2464 . self::getRecordTitle($theColConf['foreign_table'], $r, false, $forceResult);
2465 } else {
2466 $lA[] = $rVal ? '[' . $rVal . '!]' : '';
2467 }
2468 }
2469 $l = implode(', ', $lA);
2470 }
2471 }
2472 if (empty($l) && !empty($value)) {
2473 // Use plain database value when label is empty
2474 $l = $value;
2475 }
2476 }
2477 break;
2478 case 'group':
2479 // resolve the titles for DB records
2480 if ($theColConf['internal_type'] === 'db') {
2481 if ($theColConf['MM']) {
2482 if ($uid) {
2483 // Display the title of MM related records in lists
2484 if ($noRecordLookup) {
2485 $MMfields = [];
2486 $MMfields[] = $theColConf['foreign_table'] . '.uid';
2487 } else {
2488 $MMfields = [$theColConf['foreign_table'] . '.' . $GLOBALS['TCA'][$theColConf['foreign_table']]['ctrl']['label']];
2489 $altLabelFields = explode(
2490 ',',
2491 $GLOBALS['TCA'][$theColConf['foreign_table']]['ctrl']['label_alt']
2492 );
2493 foreach ($altLabelFields as $f) {
2494 $f = trim($f);
2495 if ($f !== '') {
2496 $MMfields[] = $theColConf['foreign_table'] . '.' . $f;
2497 }
2498 }
2499 }
2500 /** @var $dbGroup RelationHandler */
2501 $dbGroup = GeneralUtility::makeInstance(RelationHandler::class);
2502 $dbGroup->start(
2503 $value,
2504 $theColConf['foreign_table'],
2505 $theColConf['MM'],
2506 $uid,
2507 $table,
2508 $theColConf
2509 );
2510 $selectUids = $dbGroup->tableArray[$theColConf['foreign_table']];
2511 if (!empty($selectUids) && is_array($selectUids)) {
2512 $queryBuilder = static::getQueryBuilderForTable($theColConf['foreign_table']);
2513 $queryBuilder->getRestrictions()
2514 ->removeAll()
2515 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
2516
2517 $result = $queryBuilder
2518 ->select('uid', ...$MMfields)
2519 ->from($theColConf['foreign_table'])
2520 ->where(
2521 $queryBuilder->expr()->in(
2522 'uid',
2523 $queryBuilder->createNamedParameter(
2524 $selectUids,
2525 Connection::PARAM_INT_ARRAY
2526 )
2527 )
2528 )
2529 ->execute();
2530
2531 $mmlA = [];
2532 while ($MMrow = $result->fetch()) {
2533 // Keep sorting of $selectUids
2534 $selectedUid = array_search($MMrow['uid'], $selectUids);
2535 $mmlA[$selectedUid] = $MMrow['uid'];
2536 if (!$noRecordLookup) {
2537 $mmlA[$selectedUid] = static::getRecordTitle(
2538 $theColConf['foreign_table'],
2539 $MMrow,
2540 false,
2541 $forceResult
2542 );
2543 }
2544 }
2545
2546 if (!empty($mmlA)) {
2547 ksort($mmlA);
2548 $l = implode('; ', $mmlA);
2549 } else {
2550 $l = 'N/A';
2551 }
2552 } else {
2553 $l = 'N/A';
2554 }
2555 } else {
2556 $l = 'N/A';
2557 }
2558 } else {
2559 $finalValues = [];
2560 $relationTableName = $theColConf['allowed'];
2561 $explodedValues = GeneralUtility::trimExplode(',', $value, true);
2562
2563 foreach ($explodedValues as $explodedValue) {
2564 if (MathUtility::canBeInterpretedAsInteger($explodedValue)) {
2565 $relationTableNameForField = $relationTableName;
2566 } else {
2567 list($relationTableNameForField, $explodedValue) = self::splitTable_Uid($explodedValue);
2568 }
2569
2570 $relationRecord = static::getRecordWSOL($relationTableNameForField, $explodedValue);
2571 $finalValues[] = static::getRecordTitle($relationTableNameForField, $relationRecord);
2572 }
2573 $l = implode(', ', $finalValues);
2574 }
2575 } else {
2576 $l = implode(', ', GeneralUtility::trimExplode(',', $value, true));
2577 }
2578 break;
2579 case 'check':
2580 if (!is_array($theColConf['items']) || count($theColConf['items']) === 1) {
2581 $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');
2582 } else {
2583 $lA = [];
2584 foreach ($theColConf['items'] as $key => $val) {
2585 if ($value & pow(2, $key)) {
2586 $lA[] = $lang->sL($val[0]);
2587 }
2588 }
2589 $l = implode(', ', $lA);
2590 }
2591 break;
2592 case 'input':
2593 // Hide value 0 for dates, but show it for everything else
2594 if (isset($value)) {
2595 if (GeneralUtility::inList($theColConf['eval'], 'date')) {
2596 // Handle native date field
2597 if (isset($theColConf['dbType']) && $theColConf['dbType'] === 'date') {
2598 $dateTimeFormats = QueryHelper::getDateTimeFormats();
2599 $emptyValue = $dateTimeFormats['date']['empty'];
2600 $value = $value !== $emptyValue ? strtotime($value) : 0;
2601 }
2602 if (!empty($value)) {
2603 $ageSuffix = '';
2604 $dateColumnConfiguration = $GLOBALS['TCA'][$table]['columns'][$col]['config'];
2605 $ageDisplayKey = 'disableAgeDisplay';
2606
2607 // generate age suffix as long as not explicitly suppressed
2608 if (!isset($dateColumnConfiguration[$ageDisplayKey])
2609 // non typesafe comparison on intention
2610 || $dateColumnConfiguration[$ageDisplayKey] == false
2611 ) {
2612 $ageSuffix = ' (' . ($GLOBALS['EXEC_TIME'] - $value > 0 ? '-' : '')
2613 . self::calcAge(
2614 abs(($GLOBALS['EXEC_TIME'] - $value)),
2615 $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears')
2616 )
2617 . ')';
2618 }
2619
2620 $l = self::date($value) . $ageSuffix;
2621 }
2622 } elseif (GeneralUtility::inList($theColConf['eval'], 'time')) {
2623 if (!empty($value)) {
2624 $l = gmdate('H:i', (int)$value);
2625 }
2626 } elseif (GeneralUtility::inList($theColConf['eval'], 'timesec')) {
2627 if (!empty($value)) {
2628 $l = gmdate('H:i:s', (int)$value);
2629 }
2630 } elseif (GeneralUtility::inList($theColConf['eval'], 'datetime')) {
2631 // Handle native date/time field
2632 if (isset($theColConf['dbType']) && $theColConf['dbType'] === 'datetime') {
2633 $dateTimeFormats = QueryHelper::getDateTimeFormats();
2634 $emptyValue = $dateTimeFormats['datetime']['empty'];
2635 $value = $value !== $emptyValue ? strtotime($value) : 0;
2636 }
2637 if (!empty($value)) {
2638 $l = self::datetime($value);
2639 }
2640 } else {
2641 $l = $value;
2642 }
2643 }
2644 break;
2645 case 'flex':
2646 $l = strip_tags($value);
2647 break;
2648 default:
2649 if ($defaultPassthrough) {
2650 $l = $value;
2651 } elseif ($theColConf['MM']) {
2652 $l = 'N/A';
2653 } elseif ($value) {
2654 $l = GeneralUtility::fixed_lgd_cs(strip_tags($value), 200);
2655 }
2656 }
2657 // If this field is a password field, then hide the password by changing it to a random number of asterisk (*)
2658 if (stristr($theColConf['eval'], 'password')) {
2659 $l = '';
2660 $randomNumber = rand(5, 12);
2661 for ($i = 0; $i < $randomNumber; $i++) {
2662 $l .= '*';
2663 }
2664 }
2665 /*****************
2666 *HOOK: post-processing the human readable output from a record
2667 ****************/
2668 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['postProcessValue'])) {
2669 // Create NULL-reference
2670 $null = null;
2671 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['postProcessValue'] as $_funcRef) {
2672 $params = [
2673 'value' => $l,
2674 'colConf' => $theColConf
2675 ];
2676 $l = GeneralUtility::callUserFunction($_funcRef, $params, $null);
2677 }
2678 }
2679 if ($fixed_lgd_chars) {
2680 return GeneralUtility::fixed_lgd_cs($l, $fixed_lgd_chars);
2681 }
2682 return $l;
2683 }
2684
2685 /**
2686 * 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.
2687 *
2688 * @param string $table Table name, present in TCA
2689 * @param string $fN Field name
2690 * @param string $fV Field value
2691 * @param int $fixed_lgd_chars The max amount of characters the value may occupy
2692 * @param int $uid Uid of the current record
2693 * @param bool $forceResult If BackendUtility::getRecordTitle is used to process the value, this parameter is forwarded.
2694 * @param int $pid Optional page uid is used to evaluate page TSConfig for the given field
2695 * @return string
2696 * @see getProcessedValue()
2697 */
2698 public static function getProcessedValueExtra(
2699 $table,
2700 $fN,
2701 $fV,
2702 $fixed_lgd_chars = 0,
2703 $uid = 0,
2704 $forceResult = true,
2705 $pid = 0
2706 ) {
2707 $fVnew = self::getProcessedValue($table, $fN, $fV, $fixed_lgd_chars, 1, 0, $uid, $forceResult, $pid);
2708 if (!isset($fVnew)) {
2709 if (is_array($GLOBALS['TCA'][$table])) {
2710 if ($fN == $GLOBALS['TCA'][$table]['ctrl']['tstamp'] || $fN == $GLOBALS['TCA'][$table]['ctrl']['crdate']) {
2711 $fVnew = self::datetime($fV);
2712 } elseif ($fN === 'pid') {
2713 // Fetches the path with no regard to the users permissions to select pages.
2714 $fVnew = self::getRecordPath($fV, '1=1', 20);
2715 } else {
2716 $fVnew = $fV;
2717 }
2718 }
2719 }
2720 return $fVnew;
2721 }
2722
2723 /**
2724 * Returns fields for a table, $table, which would typically be interesting to select
2725 * This includes uid, the fields defined for title, icon-field.
2726 * 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)
2727 *
2728 * @param string $table Table name, present in $GLOBALS['TCA']
2729 * @param string $prefix Table prefix
2730 * @param array $fields Preset fields (must include prefix if that is used)
2731 * @return string List of fields.
2732 */
2733 public static function getCommonSelectFields($table, $prefix = '', $fields = [])
2734 {
2735 $fields[] = $prefix . 'uid';
2736 if (isset($GLOBALS['TCA'][$table]['ctrl']['label']) && $GLOBALS['TCA'][$table]['ctrl']['label'] != '') {
2737 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['label'];
2738 }
2739 if ($GLOBALS['TCA'][$table]['ctrl']['label_alt']) {
2740 $secondFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['label_alt'], true);
2741 foreach ($secondFields as $fieldN) {
2742 $fields[] = $prefix . $fieldN;
2743 }
2744 }
2745 if (static::isTableWorkspaceEnabled($table)) {
2746 $fields[] = $prefix . 't3ver_id';
2747 $fields[] = $prefix . 't3ver_state';
2748 $fields[] = $prefix . 't3ver_wsid';
2749 $fields[] = $prefix . 't3ver_count';
2750 }
2751 if ($GLOBALS['TCA'][$table]['ctrl']['selicon_field']) {
2752 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['selicon_field'];
2753 }
2754 if ($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
2755 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
2756 }
2757 if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
2758 if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']) {
2759 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
2760 }
2761 if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime']) {
2762 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime'];
2763 }
2764 if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime']) {
2765 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime'];
2766 }
2767 if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group']) {
2768 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group'];
2769 }
2770 }
2771 return implode(',', array_unique($fields));
2772 }
2773
2774 /**
2775 * Makes a form for configuration of some values based on configuration found in the array $configArray,
2776 * with default values from $defaults and a data-prefix $dataPrefix
2777 * <form>-tags must be supplied separately
2778 * Needs more documentation and examples, in particular syntax for configuration array. See Inside TYPO3.
2779 * That's were you can expect to find example, if anywhere.
2780 *
2781 * @param array $configArray Field configuration code.
2782 * @param array $defaults Defaults
2783 * @param string $dataPrefix Prefix for formfields
2784 * @return string HTML for a form.
2785 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
2786 */
2787 public static function makeConfigForm($configArray, $defaults, $dataPrefix)
2788 {
2789 GeneralUtility::logDeprecatedFunction();
2790 $params = $defaults;
2791 $lines = [];
2792 if (is_array($configArray)) {
2793 foreach ($configArray as $fname => $config) {
2794 if (is_array($config)) {
2795 $lines[$fname] = '<strong>' . htmlspecialchars($config[1]) . '</strong><br />';
2796 $lines[$fname] .= $config[2] . '<br />';
2797 switch ($config[0]) {
2798 case 'string':
2799
2800 case 'short':
2801 $formEl = '<input type="text" name="' . $dataPrefix . '[' . $fname . ']" value="' . $params[$fname] . '"' . static::getDocumentTemplate()->formWidth(($config[0] === 'short' ? 24 : 48)) . ' />';
2802 break;
2803 case 'check':
2804 $formEl = '<input type="hidden" name="' . $dataPrefix . '[' . $fname . ']" value="0" /><input type="checkbox" name="' . $dataPrefix . '[' . $fname . ']" value="1"' . ($params[$fname] ? ' checked="checked"' : '') . ' />';
2805 break;
2806 case 'comment':
2807 $formEl = '';
2808 break;
2809 case 'select':
2810 $opt = [];
2811 foreach ($config[3] as $k => $v) {
2812 $opt[] = '<option value="' . htmlspecialchars($k) . '"' . ($params[$fname] == $k ? ' selected="selected"' : '') . '>' . htmlspecialchars($v) . '</option>';
2813 }
2814 $formEl = '<select name="' . $dataPrefix . '[' . $fname . ']">'
2815 . implode('', $opt) . '</select>';
2816 break;
2817 default:
2818 $formEl = '<strong>Should not happen. Bug in config.</strong>';
2819 }
2820 $lines[$fname] .= $formEl;
2821 $lines[$fname] .= '<br /><br />';
2822 } else {
2823 $lines[$fname] = '<hr />';
2824 if ($config) {
2825 $lines[$fname] .= '<strong>' . strtoupper(htmlspecialchars($config)) . '</strong><br />';
2826 }
2827 if ($config) {
2828 $lines[$fname] .= '<br />';
2829 }
2830 }
2831 }
2832 }
2833 $out = implode('', $lines);
2834 $out .= '<input class="btn btn-default" type="submit" name="submit" value="Update configuration" />';
2835 return $out;
2836 }
2837
2838 /*******************************************
2839 *
2840 * Backend Modules API functions
2841 *
2842 *******************************************/
2843
2844 /**
2845 * Returns CSH help text (description), if configured for, as an array (title, description)
2846 *
2847 * @param string $table Table name
2848 * @param string $field Field name
2849 * @return array With keys 'description' (raw, as available in locallang), 'title' (optional), 'moreInfo'
2850 */
2851 public static function helpTextArray($table, $field)
2852 {
2853 if (!isset($GLOBALS['TCA_DESCR'][$table]['columns'])) {
2854 static::getLanguageService()->loadSingleTableDescription($table);
2855 }
2856 $output = [
2857 'description' => null,
2858 'title' => null,
2859 'moreInfo' => false
2860 ];
2861 if (is_array($GLOBALS['TCA_DESCR'][$table]) && is_array($GLOBALS['TCA_DESCR'][$table]['columns'][$field])) {
2862 $data = $GLOBALS['TCA_DESCR'][$table]['columns'][$field];
2863 // Add alternative title, if defined