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