[TASK] Fix CGL errors
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Template / Components / MetaInformation.php
1 <?php
2 namespace TYPO3\CMS\Backend\Template\Components;
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\Core\Resource\Exception\InsufficientFolderAccessPermissionsException;
18 use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
19 use TYPO3\CMS\Core\Resource\Folder;
20 use TYPO3\CMS\Core\Resource\FolderInterface;
21 use TYPO3\CMS\Core\Resource\ResourceFactory;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Imaging\Icon;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Lang\LanguageService;
26 use TYPO3\CMS\Core\Imaging\IconFactory;
27
28 /**
29 * MetaInformation
30 */
31 class MetaInformation
32 {
33 /**
34 * The recordArray.
35 * Typically this is a page record
36 *
37 * @var array
38 */
39 protected $recordArray = [];
40
41 /**
42 * Set the RecordArray
43 *
44 * @param array $recordArray RecordArray
45 *
46 * @return void
47 */
48 public function setRecordArray(array $recordArray)
49 {
50 $this->recordArray = $recordArray;
51 }
52
53 /**
54 * Generate the page path for docHeader
55 *
56 * @return string The page path
57 */
58 public function getPath()
59 {
60 $pageRecord = $this->recordArray;
61 $title = '';
62 // Is this a real page
63 if (is_array($pageRecord) && $pageRecord['uid']) {
64 $title = substr($pageRecord['_thePathFull'], 0, -1);
65 // Remove current page title
66 $pos = strrpos($title, $pageRecord['title']);
67 if ($pos !== false) {
68 $title = substr($title, 0, $pos);
69 }
70 } elseif (!empty($pageRecord['combined_identifier'])) {
71 try {
72 $resourceObject = ResourceFactory::getInstance()->getInstance()->getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
73 $title = $resourceObject->getStorage()->getName() . ':';
74 $title .= $resourceObject->getParentFolder()->getReadablePath();
75 } catch (ResourceDoesNotExistException $e) {
76 } catch (InsufficientFolderAccessPermissionsException $e) {
77 }
78 }
79 // Setting the path of the page
80 // crop the title to title limit (or 50, if not defined)
81 $beUser = $this->getBackendUser();
82 $cropLength = empty($beUser->uc['titleLen']) ? 50 : $beUser->uc['titleLen'];
83 $croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength);
84 if ($croppedTitle !== $title) {
85 $pagePath = '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
86 } else {
87 $pagePath = htmlspecialchars($title);
88 }
89 return $pagePath;
90 }
91
92 /**
93 * Setting page icon with clickMenu + uid for docheader
94 *
95 * @return string Record info
96 */
97 public function getRecordInformation()
98 {
99 $pageRecord = $this->recordArray;
100 if (empty($pageRecord)) {
101 return '';
102 }
103
104 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
105 $uid = '';
106 $title = '';
107 $additionalInfo = (!empty($pageRecord['_additional_info']) ? $pageRecord['_additional_info'] : '');
108 // Add icon with clickMenu, etc:
109 // If there IS a real page
110 if (is_array($pageRecord) && $pageRecord['uid']) {
111 $toolTip = BackendUtility::getRecordToolTip($pageRecord, 'pages');
112 $iconImg = '<span ' . $toolTip . '>' . $iconFactory->getIconForRecord('pages', $pageRecord, Icon::SIZE_SMALL)->render() . '</span>';
113 // Make Icon:
114 $theIcon = BackendUtility::wrapClickMenuOnIcon($iconImg, 'pages', $pageRecord['uid']);
115 $uid = $pageRecord['uid'];
116 $title = BackendUtility::getRecordTitle('pages', $pageRecord);
117 // If the module is about a FAL resource
118 } elseif (is_array($pageRecord) && !empty($pageRecord['combined_identifier'])) {
119 try {
120 $resourceObject = ResourceFactory::getInstance()->getInstance()->getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
121 $fileMountTitle = $resourceObject->getStorage()->getFileMounts()[$resourceObject->getIdentifier()]['title'];
122 $title = $fileMountTitle ?: $resourceObject->getName();
123 // If this is a folder but not in within file mount boundaries this is the root folder
124 if ($resourceObject instanceof FolderInterface && !$resourceObject->getStorage()->isWithinFileMountBoundaries($resourceObject)) {
125 $iconImg = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForResource(
126 $resourceObject,
127 Icon::SIZE_SMALL,
128 null,
129 array('mount-root' => true)
130 )->render() . '</span>';
131 } else {
132 $iconImg = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForResource(
133 $resourceObject,
134 Icon::SIZE_SMALL
135 )->render() . '</span>';
136 }
137 $theIcon = BackendUtility::wrapClickMenuOnIcon($iconImg, $pageRecord['combined_identifier']);
138 } catch (ResourceDoesNotExistException $e) {
139 $theIcon = '';
140 }
141 } else {
142 // On root-level of page tree
143 // Make Icon
144 $iconImg = '<span title="' .
145 htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) .
146 '">' .
147 $iconFactory->getIcon('apps-pagetree-root', Icon::SIZE_SMALL)->render() . '</span>';
148 if ($this->getBackendUser()->isAdmin()) {
149 $theIcon = BackendUtility::wrapClickMenuOnIcon($iconImg, 'pages', 0);
150 } else {
151 $theIcon = $iconImg;
152 }
153 $uid = '0';
154 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
155 }
156 // Setting icon with clickMenu + uid
157 return $theIcon .
158 ' <strong>' . htmlspecialchars($title) . ($uid !== '' ? '&nbsp;[' . $uid . ']' : '') . '</strong>' .
159 (!empty($additionalInfo) ? ' ' . htmlspecialchars($additionalInfo) : '');
160 }
161
162 /**
163 * Get LanguageService Object
164 *
165 * @return LanguageService
166 */
167 protected function getLanguageService()
168 {
169 return $GLOBALS['LANG'];
170 }
171
172 /**
173 * Get the Backend User Object
174 *
175 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
176 */
177 protected function getBackendUser()
178 {
179 return $GLOBALS['BE_USER'];
180 }
181 }