1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the TYPO3 CMS project. |
5
|
|
|
* |
6
|
|
|
* It is free software; you can redistribute it and/or modify it under |
7
|
|
|
* the terms of the GNU General Public License, either version 2 |
8
|
|
|
* of the License, or any later version. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please read the |
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* The TYPO3 project - inspiring people to share! |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace TYPO3\CMS\Backend\Template\Components; |
17
|
|
|
|
18
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
19
|
|
|
use TYPO3\CMS\Core\Imaging\Icon; |
20
|
|
|
use TYPO3\CMS\Core\Imaging\IconFactory; |
21
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
22
|
|
|
use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException; |
23
|
|
|
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException; |
24
|
|
|
use TYPO3\CMS\Core\Resource\FolderInterface; |
25
|
|
|
use TYPO3\CMS\Core\Resource\ResourceInterface; |
26
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Shows the path to the current record or file / folder. |
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
|
|
|
protected ?ResourceInterface $resource = null; |
42
|
|
|
|
43
|
|
|
public function setResource(ResourceInterface $resource): void |
44
|
|
|
{ |
45
|
|
|
$this->resource = $resource; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Set the RecordArray |
50
|
|
|
* |
51
|
|
|
* @param array $recordArray RecordArray |
52
|
|
|
*/ |
53
|
|
|
public function setRecordArray(array $recordArray) |
54
|
|
|
{ |
55
|
|
|
$this->recordArray = $recordArray; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Generate the page path for docHeader |
60
|
|
|
* |
61
|
|
|
* @return string The page path |
62
|
|
|
*/ |
63
|
|
|
public function getPath() |
64
|
|
|
{ |
65
|
|
|
$pageRecord = $this->recordArray; |
66
|
|
|
$title = ''; |
67
|
|
|
if ($this->resource) { |
68
|
|
|
try { |
69
|
|
|
$title = $this->resource->getStorage()->getName(); |
70
|
|
|
$title .= $this->resource->getParentFolder()->getReadablePath(); |
|
|
|
|
71
|
|
|
} catch (ResourceDoesNotExistException|InsufficientFolderAccessPermissionsException $e) { |
|
|
|
|
72
|
|
|
} |
73
|
|
|
} elseif (is_array($pageRecord) && !empty($pageRecord['uid'])) { |
74
|
|
|
// Is this a real page |
75
|
|
|
$title = substr($pageRecord['_thePathFull'] ?? '', 0, -1); |
76
|
|
|
// Remove current page title |
77
|
|
|
$pos = strrpos($title, $pageRecord['title']); |
78
|
|
|
if ($pos !== false) { |
79
|
|
|
$title = substr($title, 0, $pos); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
// Setting the path of the page |
83
|
|
|
// crop the title to title limit (or 50, if not defined) |
84
|
|
|
$beUser = $this->getBackendUser(); |
85
|
|
|
$cropLength = empty($beUser->uc['titleLen']) ? 50 : (int)$beUser->uc['titleLen']; |
86
|
|
|
$croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength); |
87
|
|
|
if ($croppedTitle !== $title) { |
88
|
|
|
$pagePath = '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>'; |
89
|
|
|
} else { |
90
|
|
|
$pagePath = htmlspecialchars($title); |
91
|
|
|
} |
92
|
|
|
return $pagePath; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Setting page icon with context menu + uid for docheader |
97
|
|
|
* |
98
|
|
|
* @return string Record info |
99
|
|
|
*/ |
100
|
|
|
public function getRecordInformation() |
101
|
|
|
{ |
102
|
|
|
$recordInformations = $this->getRecordInformations(); |
103
|
|
|
if (!empty($recordInformations)) { |
104
|
|
|
$recordInformation = $recordInformations['icon'] . |
105
|
|
|
' <strong>' . htmlspecialchars($recordInformations['title']) . ($recordInformations['uid'] !== '' ? ' [' . $recordInformations['uid'] . ']' : '') . '</strong>' . |
106
|
|
|
(!empty($recordInformations['additionalInfo']) ? ' ' . htmlspecialchars($recordInformations['additionalInfo']) : ''); |
107
|
|
|
} else { |
108
|
|
|
$recordInformation = ''; |
109
|
|
|
} |
110
|
|
|
return $recordInformation; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Setting page icon |
115
|
|
|
* |
116
|
|
|
* @return string Record icon |
117
|
|
|
*/ |
118
|
|
|
public function getRecordInformationIcon() |
119
|
|
|
{ |
120
|
|
|
$recordInformations = $this->getRecordInformations(); |
121
|
|
|
if (!empty($recordInformations)) { |
122
|
|
|
$recordInformationIcon = $recordInformations['icon']; |
123
|
|
|
} else { |
124
|
|
|
$recordInformationIcon = null; |
125
|
|
|
} |
126
|
|
|
return $recordInformationIcon; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Setting page title |
131
|
|
|
* |
132
|
|
|
* @return string Record title, already htmlspecialchar()'ed |
133
|
|
|
*/ |
134
|
|
|
public function getRecordInformationTitle() |
135
|
|
|
{ |
136
|
|
|
$recordInformations = $this->getRecordInformations(); |
137
|
|
|
if (!empty($recordInformations)) { |
138
|
|
|
$title = $recordInformations['title']; |
139
|
|
|
} else { |
140
|
|
|
$title = ''; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
// crop the title to title limit (or 50, if not defined) |
144
|
|
|
$beUser = $this->getBackendUser(); |
145
|
|
|
$cropLength = empty($beUser->uc['titleLen']) ? 50 : $beUser->uc['titleLen']; |
146
|
|
|
return htmlspecialchars(GeneralUtility::fixed_lgd_cs($title, $cropLength)); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Setting page uid |
151
|
|
|
* |
152
|
|
|
* @return int|null Record uid |
153
|
|
|
*/ |
154
|
|
|
public function getRecordInformationUid() |
155
|
|
|
{ |
156
|
|
|
$recordInformations = $this->getRecordInformations(); |
157
|
|
|
if (!empty($recordInformations)) { |
158
|
|
|
$recordInformationUid = $recordInformations['uid']; |
159
|
|
|
} else { |
160
|
|
|
$recordInformationUid = null; |
161
|
|
|
} |
162
|
|
|
return $recordInformationUid; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Returns record additional information |
167
|
|
|
* |
168
|
|
|
* @return string Record additional information |
169
|
|
|
*/ |
170
|
|
|
public function getRecordInformationAdditionalInfo(): string |
171
|
|
|
{ |
172
|
|
|
$recordInformations = $this->getRecordInformations(); |
173
|
|
|
return $recordInformations['additionalInfo'] ?? ''; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function isFileOrFolder(): bool |
177
|
|
|
{ |
178
|
|
|
return $this->resource !== null; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Setting page array |
183
|
|
|
* |
184
|
|
|
* @return array Record info |
185
|
|
|
*/ |
186
|
|
|
protected function getRecordInformations() |
187
|
|
|
{ |
188
|
|
|
$pageRecord = $this->recordArray; |
189
|
|
|
if (empty($pageRecord) && $this->resource === null) { |
190
|
|
|
return []; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
$iconFactory = GeneralUtility::makeInstance(IconFactory::class); |
194
|
|
|
$uid = ''; |
195
|
|
|
$title = ''; |
196
|
|
|
$additionalInfo = (!empty($pageRecord['_additional_info'] ?? '') ? $pageRecord['_additional_info'] : ''); |
197
|
|
|
// Add icon with context menu, etc: |
198
|
|
|
// If the module is about a FAL resource |
199
|
|
|
if ($this->resource) { |
200
|
|
|
try { |
201
|
|
|
$fileMountTitle = $this->resource->getStorage()->getFileMounts()[$this->resource->getIdentifier()]['title'] ?? ''; |
202
|
|
|
$title = $fileMountTitle ?: $this->resource->getName(); |
203
|
|
|
// If this is a folder but not in within file mount boundaries this is the root folder |
204
|
|
|
if ($this->resource instanceof FolderInterface && !$this->resource->getStorage()->isWithinFileMountBoundaries($this->resource)) { |
205
|
|
|
$theIcon = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForResource( |
206
|
|
|
$this->resource, |
207
|
|
|
Icon::SIZE_SMALL, |
208
|
|
|
null, |
209
|
|
|
['mount-root' => true] |
210
|
|
|
)->render() . '</span>'; |
211
|
|
|
} else { |
212
|
|
|
$theIcon = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForResource( |
213
|
|
|
$this->resource, |
214
|
|
|
Icon::SIZE_SMALL |
215
|
|
|
)->render() . '</span>'; |
216
|
|
|
} |
217
|
|
|
$tableName = ($this->resource->getIdentifier() === $this->resource->getStorage()->getRootLevelFolder()->getIdentifier()) |
218
|
|
|
? 'sys_filemounts' : 'sys_file'; |
219
|
|
|
if (method_exists($this->resource, 'getCombinedIdentifier')) { |
220
|
|
|
$theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, $tableName, $this->resource->getCombinedIdentifier()); |
221
|
|
|
} |
222
|
|
|
} catch (ResourceDoesNotExistException|InsufficientFolderAccessPermissionsException $e) { |
223
|
|
|
$theIcon = ''; |
224
|
|
|
} |
225
|
|
|
} elseif (is_array($pageRecord) && !empty($pageRecord['uid'])) { |
226
|
|
|
// If there IS a real page |
227
|
|
|
$toolTip = BackendUtility::getRecordToolTip($pageRecord, 'pages'); |
228
|
|
|
$theIcon = '<span ' . $toolTip . '>' . $iconFactory->getIconForRecord('pages', $pageRecord, Icon::SIZE_SMALL)->render() . '</span>'; |
229
|
|
|
// Make Icon: |
230
|
|
|
$theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'pages', $pageRecord['uid']); |
231
|
|
|
$uid = $pageRecord['uid']; |
232
|
|
|
$title = BackendUtility::getRecordTitle('pages', $pageRecord); |
233
|
|
|
} else { |
234
|
|
|
// On root-level of page tree |
235
|
|
|
// Make Icon |
236
|
|
|
$theIcon = '<span title="' . |
237
|
|
|
htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) . |
238
|
|
|
'">' . |
239
|
|
|
$iconFactory->getIcon('apps-pagetree-root', Icon::SIZE_SMALL)->render() . '</span>'; |
240
|
|
|
if ($this->getBackendUser()->isAdmin()) { |
241
|
|
|
$theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'pages'); |
242
|
|
|
} |
243
|
|
|
$uid = '0'; |
244
|
|
|
$title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']; |
245
|
|
|
} |
246
|
|
|
// returns array for icon, title, uid and additional info |
247
|
|
|
return [ |
248
|
|
|
'uid' => $uid, |
249
|
|
|
'icon' => $theIcon, |
250
|
|
|
'title' => $title, |
251
|
|
|
'additionalInfo' => $additionalInfo |
252
|
|
|
]; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Get LanguageService Object |
257
|
|
|
* |
258
|
|
|
* @return LanguageService |
259
|
|
|
*/ |
260
|
|
|
protected function getLanguageService() |
261
|
|
|
{ |
262
|
|
|
return $GLOBALS['LANG']; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Get the Backend User Object |
267
|
|
|
* |
268
|
|
|
* @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
269
|
|
|
*/ |
270
|
|
|
protected function getBackendUser() |
271
|
|
|
{ |
272
|
|
|
return $GLOBALS['BE_USER']; |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
|