[CLEANUP] Replace strlen() with === for zero length check
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / Service / UserFileInlineLabelService.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Service;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
20
21 /**
22 * User file inline label service
23 */
24 class UserFileInlineLabelService {
25
26 /**
27 * Get the user function label for the file_reference table
28 *
29 * @param array $params
30 * @return void
31 */
32 public function getInlineLabel(array &$params) {
33 $sysFileFields = isset($params['options']['sys_file']) && is_array($params['options']['sys_file'])
34 ? $params['options']['sys_file']
35 : array();
36
37 if (!count($sysFileFields)) {
38 // Nothing to do
39 $params['title'] = $params['row']['uid'];
40 return;
41 }
42
43 $fileInfo = BackendUtility::splitTable_Uid($params['row']['uid_local'], 2);
44 $fileRecord = BackendUtility::getRecord($fileInfo[0], $fileInfo[1]);
45
46 // Configuration
47 $title = array();
48 foreach ($sysFileFields as $field) {
49 $value = '';
50 if ($field === 'title') {
51 if (isset($params['row']['title'])) {
52 $fullTitle = $params['row']['title'];
53 } else {
54 $metaDataRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\MetaDataRepository::class);
55 $metaData = $metaDataRepository->findByFileUid($fileRecord['uid']);
56 $fullTitle = $metaData['title'];
57 }
58
59 $value = BackendUtility::getRecordTitlePrep(htmlspecialchars($fullTitle));
60 } else {
61 if (isset($params['row'][$field])) {
62 $value = htmlspecialchars($params['row'][$field]);
63 } elseif (isset($fileRecord[$field])) {
64 $value = BackendUtility::getRecordTitlePrep($fileRecord[$field]);
65 }
66 }
67 if ((string)$value === '') {
68 continue;
69 }
70 $labelText = LocalizationUtility::translate('LLL:EXT:lang/locallang_tca.xlf:sys_file.' . $field, 'lang');
71 $title[] = '<dt>' . htmlspecialchars($labelText) . '</dt>' . '<dd>' . $value . '</dd>';
72 }
73 $params['title'] = '<dl>' . implode('', $title) . '</dl>';
74 }
75
76 }