‪TYPO3CMS  10.4
FileFacade.php
Go to the documentation of this file.
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\Filelist;
17 
27 
38 {
44  protected static ‪$referenceCounts = [];
45 
49  protected ‪$resource;
50 
54  protected ‪$iconFactory;
55 
61  {
62  $this->resource = ‪$resource;
63  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
64  }
65 
69  public function ‪getResource(): ‪FileInterface
70  {
71  return ‪$this->resource;
72  }
73 
77  public function ‪getIsEditable(): bool
78  {
79  return $this->‪getIsWritable()
80  && $this->resource instanceof ‪AbstractFile
81  && $this->resource->‪isTextFile();
82  }
83 
87  public function ‪getIsMetadataEditable(): bool
88  {
89  return $this->resource->isIndexed() && $this->‪getIsWritable() && $this->‪getBackendUser()->‪check('tables_modify', 'sys_file_metadata');
90  }
91 
95  public function ‪getMetadataUid(): int
96  {
97  $uid = 0;
98  $method = '_getMetadata';
99  if (is_callable([$this->resource, $method])) {
100  $metadata = call_user_func([$this->resource, $method]);
101 
102  if (isset($metadata['uid'])) {
103  $uid = (int)$metadata['uid'];
104  }
105  }
106 
107  return $uid;
108  }
109 
113  public function ‪getName(): string
114  {
115  return $this->resource->getName();
116  }
117 
121  public function ‪getPath(): string
122  {
123  $method = 'getReadablePath';
124  if (is_callable([$this->resource->getParentFolder(), $method])) {
125  return call_user_func([$this->resource->getParentFolder(), $method]);
126  }
127 
128  return '';
129  }
130 
134  public function ‪getPublicUrl()
135  {
136  return $this->resource->getPublicUrl(true);
137  }
138 
142  public function ‪getExtension(): string
143  {
144  return strtoupper($this->resource->getExtension());
145  }
146 
150  public function ‪getIdentifier(): string
151  {
152  return $this->resource->getStorage()->getUid() . ':' . $this->resource->getIdentifier();
153  }
154 
158  public function ‪getLastModified(): string
159  {
160  return ‪BackendUtility::date($this->resource->getModificationTime());
161  }
162 
166  public function ‪getSize(): string
167  {
168  return GeneralUtility::formatSize($this->resource->getSize(), htmlspecialchars($this->‪getLanguageService()->getLL('byteSizeUnits')));
169  }
170 
174  public function ‪getIsReadable()
175  {
176  $method = 'checkActionPermission';
177  if (is_callable([$this->resource, $method])) {
178  return call_user_func_array([$this->resource, $method], ['read']);
179  }
180 
181  return false;
182  }
183 
187  public function ‪getIsWritable()
188  {
189  $method = 'checkActionPermission';
190  if (is_callable([$this->resource, $method])) {
191  return call_user_func_array([$this->resource, $method], ['write']);
192  }
193 
194  return false;
195  }
196 
200  public function ‪getIsReplaceable()
201  {
202  $method = 'checkActionPermission';
203  if (is_callable([$this->resource, $method])) {
204  return call_user_func_array([$this->resource, $method], ['replace']);
205  }
206 
207  return false;
208  }
209 
213  public function ‪getIsRenamable()
214  {
215  $method = 'checkActionPermission';
216  if (is_callable([$this->resource, $method])) {
217  return call_user_func_array([$this->resource, $method], ['rename']);
218  }
219 
220  return false;
221  }
222 
226  public function ‪isCopyable()
227  {
228  $method = 'checkActionPermission';
229  if (is_callable([$this->resource, $method])) {
230  return call_user_func_array([$this->resource, $method], ['copy']);
231  }
232 
233  return false;
234  }
235 
239  public function ‪isCuttable()
240  {
241  $method = 'checkActionPermission';
242  if (is_callable([$this->resource, $method])) {
243  return call_user_func_array([$this->resource, $method], ['move']);
244  }
245 
246  return false;
247  }
248 
252  public function ‪getIsDeletable()
253  {
254  $method = 'checkActionPermission';
255  if (is_callable([$this->resource, $method])) {
256  return call_user_func_array([$this->resource, $method], ['delete']);
257  }
258 
259  return false;
260  }
261 
265  public function ‪isSelected()
266  {
267  $fullIdentifier = $this->‪getIdentifier();
268  $md5 = GeneralUtility::shortMD5($fullIdentifier);
269 
271  $clipboard = GeneralUtility::makeInstance(Clipboard::class);
272  $clipboard->initializeClipboard();
273 
274  $isSel = $clipboard->isSelected('_FILE', $md5);
275 
276  if ($isSel) {
277  return $isSel;
278  }
279 
280  return false;
281  }
282 
286  public function ‪getIsImage()
287  {
288  return $this->resource instanceof ‪AbstractFile && $this->resource->‪isImage();
289  }
290 
296  public function ‪getReferenceCount(): int
297  {
298  $uid = (int)$this->resource->getProperty('uid');
299 
300  if ($uid <= 0) {
301  return 0;
302  }
303 
304  if (!isset(static::$referenceCounts[$uid])) {
305  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_refindex');
306  $count = $queryBuilder->count('*')
307  ->from('sys_refindex')
308  ->where(
309  $queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
310  $queryBuilder->expr()->eq(
311  'ref_table',
312  $queryBuilder->createNamedParameter('sys_file', \PDO::PARAM_STR)
313  ),
314  $queryBuilder->expr()->eq(
315  'ref_uid',
316  $queryBuilder->createNamedParameter($this->resource->getProperty('uid'), \PDO::PARAM_INT)
317  ),
318  $queryBuilder->expr()->neq(
319  'tablename',
320  $queryBuilder->createNamedParameter('sys_file_metadata', \PDO::PARAM_STR)
321  )
322  )
323  ->execute()
324  ->fetchColumn();
325 
326  static::$referenceCounts[$uid] = $count;
327  }
328 
329  return static::$referenceCounts[$uid];
330  }
331 
338  public function ‪__call($method, $arguments)
339  {
340  if (is_callable([$this->resource, $method])) {
341  $this->resource->$method(...$arguments);
342  }
343 
344  return null;
345  }
346 
350  protected function ‪getBackendUser(): ‪BackendUserAuthentication
351  {
352  return ‪$GLOBALS['BE_USER'];
353  }
354 
358  protected function ‪getLanguageService(): ‪LanguageService
359  {
360  return ‪$GLOBALS['LANG'];
361  }
362 }
‪TYPO3\CMS\Filelist\FileFacade\getIsMetadataEditable
‪bool getIsMetadataEditable()
Definition: FileFacade.php:84
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:22
‪TYPO3\CMS\Backend\Clipboard\Clipboard
Definition: Clipboard.php:43
‪TYPO3\CMS\Filelist\FileFacade\getBackendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: FileFacade.php:347
‪TYPO3\CMS\Filelist\FileFacade\isCopyable
‪bool isCopyable()
Definition: FileFacade.php:223
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\check
‪bool check($type, $value)
Definition: BackendUserAuthentication.php:624
‪TYPO3\CMS\Filelist\FileFacade\getReferenceCount
‪int getReferenceCount()
Definition: FileFacade.php:293
‪TYPO3\CMS\Filelist\FileFacade\getIsReadable
‪bool getIsReadable()
Definition: FileFacade.php:171
‪TYPO3\CMS\Filelist\FileFacade\getPath
‪string getPath()
Definition: FileFacade.php:118
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Core\Resource\AbstractFile\isImage
‪bool isImage()
Definition: AbstractFile.php:323
‪TYPO3\CMS\Filelist\FileFacade\$iconFactory
‪TYPO3 CMS Core Imaging IconFactory $iconFactory
Definition: FileFacade.php:51
‪TYPO3\CMS\Filelist\FileFacade\getName
‪string getName()
Definition: FileFacade.php:110
‪TYPO3\CMS\Filelist\FileFacade\$referenceCounts
‪static array $referenceCounts
Definition: FileFacade.php:43
‪TYPO3\CMS\Filelist
‪TYPO3\CMS\Filelist\FileFacade\getIsWritable
‪bool getIsWritable()
Definition: FileFacade.php:184
‪TYPO3\CMS\Filelist\FileFacade
Definition: FileFacade.php:38
‪TYPO3\CMS\Filelist\FileFacade\$resource
‪TYPO3 CMS Core Resource FileInterface $resource
Definition: FileFacade.php:47
‪TYPO3\CMS\Core\Resource\AbstractFile
Definition: AbstractFile.php:26
‪TYPO3\CMS\Filelist\FileFacade\getIsDeletable
‪bool getIsDeletable()
Definition: FileFacade.php:249
‪TYPO3\CMS\Filelist\FileFacade\__construct
‪__construct(FileInterface $resource)
Definition: FileFacade.php:57
‪TYPO3\CMS\Filelist\FileFacade\getIsRenamable
‪bool getIsRenamable()
Definition: FileFacade.php:210
‪TYPO3\CMS\Filelist\FileFacade\isSelected
‪bool isSelected()
Definition: FileFacade.php:262
‪TYPO3\CMS\Filelist\FileFacade\getLastModified
‪string getLastModified()
Definition: FileFacade.php:155
‪TYPO3\CMS\Filelist\FileFacade\getLanguageService
‪TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: FileFacade.php:355
‪TYPO3\CMS\Filelist\FileFacade\isCuttable
‪bool isCuttable()
Definition: FileFacade.php:236
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Filelist\FileFacade\getSize
‪string getSize()
Definition: FileFacade.php:163
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Filelist\FileFacade\__call
‪mixed __call($method, $arguments)
Definition: FileFacade.php:335
‪TYPO3\CMS\Filelist\FileFacade\getPublicUrl
‪string null getPublicUrl()
Definition: FileFacade.php:131
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Resource\AbstractFile\isTextFile
‪bool isTextFile()
Definition: AbstractFile.php:342
‪TYPO3\CMS\Filelist\FileFacade\getIsImage
‪bool getIsImage()
Definition: FileFacade.php:283
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Filelist\FileFacade\getMetadataUid
‪int getMetadataUid()
Definition: FileFacade.php:92
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Filelist\FileFacade\getIdentifier
‪string getIdentifier()
Definition: FileFacade.php:147
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Filelist\FileFacade\getExtension
‪string getExtension()
Definition: FileFacade.php:139
‪TYPO3\CMS\Filelist\FileFacade\getIsReplaceable
‪bool getIsReplaceable()
Definition: FileFacade.php:197
‪TYPO3\CMS\Filelist\FileFacade\getResource
‪TYPO3 CMS Core Resource FileInterface getResource()
Definition: FileFacade.php:66
‪TYPO3\CMS\Backend\Utility\BackendUtility\date
‪static string date($tstamp)
Definition: BackendUtility.php:978
‪TYPO3\CMS\Filelist\FileFacade\getIsEditable
‪bool getIsEditable()
Definition: FileFacade.php:74