1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the package typo3/cms-digital-asset-management. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please read the |
8
|
|
|
* LICENSE file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace TYPO3\CMS\DigitalAssetManagement\Entity; |
12
|
|
|
|
13
|
|
|
use TYPO3\CMS\Backend\Routing\UriBuilder; |
14
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
15
|
|
|
use TYPO3\CMS\Core\Imaging\Icon; |
16
|
|
|
use TYPO3\CMS\Core\Imaging\IconFactory; |
17
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
18
|
|
|
use TYPO3\CMS\Core\Resource\File; |
19
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Immutable file object (not an image recognized by TYPO3), used by getFolderItemsAction(). |
23
|
|
|
* |
24
|
|
|
* @see FolderItemFolder |
25
|
|
|
* @see FolderItemImage |
26
|
|
|
*/ |
27
|
|
|
class FolderItemFile implements \JsonSerializable |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var string Always set to "file" |
31
|
|
|
*/ |
32
|
|
|
protected $type = 'file'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var int FAL identifier, eg. "42:/path/to/file" |
36
|
|
|
*/ |
37
|
|
|
protected $identifier; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string Full file name without path, eg. "myFile.txt" |
41
|
|
|
*/ |
42
|
|
|
protected $name; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var int File modification timestamp, eg. 1553705583 |
46
|
|
|
*/ |
47
|
|
|
protected $mtime; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string $mtime formatted for display, eg. "30.02.2042" |
51
|
|
|
*/ |
52
|
|
|
protected $mtimeDisplay; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var FilePermission Entity representing access permissions |
56
|
|
|
*/ |
57
|
|
|
protected $permissions; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var string File extension / ending, eg. "txt" |
61
|
|
|
*/ |
62
|
|
|
protected $extension; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var int File size in bytes, eg. 12345 |
66
|
|
|
*/ |
67
|
|
|
protected $size; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var string $size formatted for display, eg. "42KB" |
71
|
|
|
*/ |
72
|
|
|
protected $sizeDisplay; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var array @TODO Details of translated meta data of this file, to be defined |
76
|
|
|
*/ |
77
|
|
|
protected $translations; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var int Number of other records referencing this file, eg. 5 |
81
|
|
|
*/ |
82
|
|
|
protected $references; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var string Icon identifier matching mime type or extension, eg. "mimetypes-text-text" |
86
|
|
|
*/ |
87
|
|
|
protected $iconIdentifier; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Url to edit meta data of file, eg. |
91
|
|
|
* "/typo3/index.php?route=/record/edit&token=06db97b96d1e73ec14bf5d1f35604b20843d54f4&edit[sys_file_metadata][108]=edit" |
92
|
|
|
* |
93
|
|
|
* @var string |
94
|
|
|
*/ |
95
|
|
|
protected $editMetaUrl; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Url to edit editable files like text files. Empty if file is not editable. eg. "" |
99
|
|
|
* |
100
|
|
|
* @todo Not yet implemented |
101
|
|
|
* @var string |
102
|
|
|
*/ |
103
|
|
|
protected $editContentUrl; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @var string |
107
|
|
|
*/ |
108
|
|
|
protected $publicUrl; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param File $file |
112
|
|
|
*/ |
113
|
|
|
public function __construct(File $file) |
114
|
|
|
{ |
115
|
|
|
$this->identifier = $file->getCombinedIdentifier(); |
|
|
|
|
116
|
|
|
$this->name = $file->getName(); |
117
|
|
|
$this->mtime = $file->getModificationTime(); |
118
|
|
|
$this->mtimeDisplay = BackendUtility::date($this->mtime) ?? ''; |
119
|
|
|
$this->permissions = new FilePermission($file); |
120
|
|
|
$this->extension = $file->getExtension(); |
121
|
|
|
$this->size = $file->getSize(); |
122
|
|
|
$this->sizeDisplay = GeneralUtility::formatSize( |
123
|
|
|
$this->size, |
124
|
|
|
$this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:byteSizeUnits') |
125
|
|
|
); |
126
|
|
|
$this->translations = []; |
127
|
|
|
$this->references = (int)BackendUtility::referenceCount('sys_file', $file->getUid()); |
128
|
|
|
$this->iconIdentifier = GeneralUtility::makeInstance(IconFactory::class) |
129
|
|
|
->getIconForResource($file, Icon::SIZE_SMALL) |
130
|
|
|
->getIdentifier(); |
131
|
|
|
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
132
|
|
|
$urlParameters = [ |
133
|
|
|
'edit' => [ |
134
|
|
|
'sys_file_metadata' => [ |
135
|
|
|
$file->getMetaData()['uid'] => 'edit', |
|
|
|
|
136
|
|
|
], |
137
|
|
|
], |
138
|
|
|
'returnUrl' => (string)$uriBuilder->buildUriFromRoute('file_DigitalAssetManagement'), |
139
|
|
|
]; |
140
|
|
|
$this->editMetaUrl = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters); |
141
|
|
|
$this->editContentUrl = ''; |
142
|
|
|
$this->publicUrl = $file->getPublicUrl(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function jsonSerialize() |
146
|
|
|
{ |
147
|
|
|
return [ |
148
|
|
|
'type' => $this->type, |
149
|
|
|
'identifier' => $this->identifier, |
150
|
|
|
'name' => $this->name, |
151
|
|
|
'mtime' => $this->mtime, |
152
|
|
|
'mtimeDisplay' => $this->mtimeDisplay, |
153
|
|
|
'permissions' => $this->permissions, |
154
|
|
|
'extension' => $this->extension, |
155
|
|
|
'size' => $this->size, |
156
|
|
|
'sizeDisplay' => $this->sizeDisplay, |
157
|
|
|
'translations' => $this->translations, |
158
|
|
|
'references' => $this->references, |
159
|
|
|
'iconIdentifier' => $this->iconIdentifier, |
160
|
|
|
'editMetaUrl' => $this->editMetaUrl, |
161
|
|
|
'editContentUrl' => $this->editContentUrl, |
162
|
|
|
'publicUrl' => $this->publicUrl, |
163
|
|
|
]; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return LanguageService |
168
|
|
|
*/ |
169
|
|
|
protected function getLanguageService() |
170
|
|
|
{ |
171
|
|
|
return $GLOBALS['LANG']; |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.