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\Localization\LanguageService; |
16
|
|
|
use TYPO3\CMS\Core\Resource\File; |
17
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
18
|
|
|
use TYPO3\CMS\Filelist\Configuration\ThumbnailConfiguration; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Immutable image object (a file recognized as image by TYPO3), used by getFolderItemsAction(). |
22
|
|
|
* |
23
|
|
|
* @see FolderItemFile |
24
|
|
|
*/ |
25
|
|
|
class FolderItemImage implements \JsonSerializable |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var string Always set to "image" |
29
|
|
|
*/ |
30
|
|
|
protected $type = 'image'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var int FAL identifier, eg. "42:/path/to/file" |
34
|
|
|
*/ |
35
|
|
|
protected $identifier; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string Full file name without path, eg. "myFile.txt" |
39
|
|
|
*/ |
40
|
|
|
protected $name; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var int File modification timestamp, eg. 1553705583 |
44
|
|
|
*/ |
45
|
|
|
protected $mtime; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string $mtime formatted for display, eg. "30.02.2042" |
49
|
|
|
*/ |
50
|
|
|
protected $mtimeDisplay; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var FilePermission Entity representing access permissions |
54
|
|
|
*/ |
55
|
|
|
protected $permissions; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string File extension / ending, eg. "txt" |
59
|
|
|
*/ |
60
|
|
|
protected $extension; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var int File size in bytes, eg. 12345 |
64
|
|
|
*/ |
65
|
|
|
protected $size; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var string $size formatted for display, eg. "42KB" |
69
|
|
|
*/ |
70
|
|
|
protected $sizeDisplay; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var array @TODO Details of translated meta data of this file, to be defined |
74
|
|
|
*/ |
75
|
|
|
protected $translations; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var int Number of other records referencing this file, eg. 5 |
79
|
|
|
*/ |
80
|
|
|
protected $references; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Url to edit meta data of file, eg. |
84
|
|
|
* "/typo3/index.php?route=/record/edit&token=06db97b96d1e73ec14bf5d1f35604b20843d54f4&edit[sys_file_metadata][108]=edit" |
85
|
|
|
* |
86
|
|
|
* @var string |
87
|
|
|
*/ |
88
|
|
|
protected $editMetaUrl; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Url to get thumbnail of image, eg. |
92
|
|
|
* "/typo3/index.php?route=/thumbnails&token=2ef7aa2f65b713771165b3dba9fb2f2aee6d6005¶meters=..." |
93
|
|
|
* |
94
|
|
|
* @var string |
95
|
|
|
*/ |
96
|
|
|
protected $thumbnailUrl; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @var string |
100
|
|
|
*/ |
101
|
|
|
protected $publicUrl; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param File $image |
105
|
|
|
*/ |
106
|
|
|
public function __construct(File $image) |
107
|
|
|
{ |
108
|
|
|
$this->identifier = $image->getCombinedIdentifier(); |
|
|
|
|
109
|
|
|
$this->name = $image->getName(); |
110
|
|
|
$this->mtime = $image->getModificationTime(); |
111
|
|
|
$this->mtimeDisplay = BackendUtility::date($this->mtime) ?? ''; |
112
|
|
|
$this->permissions = new FilePermission($image); |
113
|
|
|
$this->extension = $image->getExtension(); |
114
|
|
|
$this->size = $image->getSize(); |
115
|
|
|
$this->sizeDisplay = GeneralUtility::formatSize( |
116
|
|
|
$this->size, |
117
|
|
|
$this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:byteSizeUnits') |
118
|
|
|
); |
119
|
|
|
$this->translations = []; |
120
|
|
|
$this->references = (int)BackendUtility::referenceCount('sys_file', $image->getUid()); |
121
|
|
|
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
122
|
|
|
$urlParameters = [ |
123
|
|
|
'edit' => [ |
124
|
|
|
'sys_file_metadata' => [ |
125
|
|
|
$image->getMetaData()['uid'] => 'edit', |
|
|
|
|
126
|
|
|
] |
127
|
|
|
], |
128
|
|
|
'returnUrl' => (string)$uriBuilder->buildUriFromRoute('file_DigitalAssetManagement'), |
129
|
|
|
]; |
130
|
|
|
$this->editMetaUrl = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters); |
131
|
|
|
// @todo: This use an internal class of ext:filelist |
132
|
|
|
$thumbnailConfiguration = GeneralUtility::makeInstance(ThumbnailConfiguration::class); |
133
|
|
|
$this->thumbnailUrl = BackendUtility::getThumbnailUrl($image->getUid(), [ |
|
|
|
|
134
|
|
|
'width' => $thumbnailConfiguration->getWidth(), |
135
|
|
|
'height' => $thumbnailConfiguration->getHeight() |
136
|
|
|
]); |
137
|
|
|
$this->publicUrl = $image->getPublicUrl(); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function jsonSerialize() |
141
|
|
|
{ |
142
|
|
|
return [ |
143
|
|
|
'type' => $this->type, |
144
|
|
|
'identifier' => $this->identifier, |
145
|
|
|
'name' => $this->name, |
146
|
|
|
'mtime' => $this->mtime, |
147
|
|
|
'mtimeDisplay' => $this->mtimeDisplay, |
148
|
|
|
'permissions' => $this->permissions, |
149
|
|
|
'extension' => $this->extension, |
150
|
|
|
'size' => $this->size, |
151
|
|
|
'sizeDisplay' => $this->sizeDisplay, |
152
|
|
|
'translations' => $this->translations, |
153
|
|
|
'references' => $this->references, |
154
|
|
|
'editMetaUrl' => $this->editMetaUrl, |
155
|
|
|
'thumbnailUrl' => $this->thumbnailUrl, |
156
|
|
|
'publicUrl' => $this->publicUrl, |
157
|
|
|
]; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return LanguageService |
162
|
|
|
*/ |
163
|
|
|
protected function getLanguageService() |
164
|
|
|
{ |
165
|
|
|
return $GLOBALS['LANG']; |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
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.