‪TYPO3CMS  9.5
FileFacade.php
Go to the documentation of this file.
1 <?php
2 namespace ‪TYPO3\CMS\Filelist;
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 
26 
37 {
43  protected static ‪$referenceCounts = [];
44 
48  protected ‪$resource;
49 
53  protected ‪$iconFactory;
54 
60  {
61  $this->resource = ‪$resource;
62  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
63  }
64 
69  public function ‪getIcon(): string
70  {
71  trigger_error('FileFacade->getIcon() will be removed in TYPO3 v10.0, use ViewHelper <core:iconForResource /> instead.', E_USER_DEPRECATED);
72  $title = htmlspecialchars($this->resource->getName() . ' [' . (int)$this->resource->getProperty('uid') . ']');
73  return '<span title="' . $title . '">' . $this->iconFactory->getIconForResource($this->resource, ‪Icon::SIZE_SMALL) . '</span>';
74  }
75 
79  public function ‪getResource(): ‪FileInterface
80  {
81  return ‪$this->resource;
82  }
83 
87  public function ‪getIsEditable(): bool
88  {
89  return $this->‪getIsWritable()
90  && GeneralUtility::inList(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $this->resource->getExtension());
91  }
92 
96  public function ‪getIsMetadataEditable(): bool
97  {
98  return $this->resource->isIndexed() && $this->‪getIsWritable() && $this->‪getBackendUser()->‪check('tables_modify', 'sys_file_metadata');
99  }
100 
104  public function ‪getMetadataUid(): int
105  {
106  $uid = 0;
107  $method = '_getMetadata';
108  if (is_callable([$this->resource, $method])) {
109  $metadata = call_user_func([$this->resource, $method]);
110 
111  if (isset($metadata['uid'])) {
112  $uid = (int)$metadata['uid'];
113  }
114  }
115 
116  return $uid;
117  }
118 
122  public function ‪getName(): string
123  {
124  return $this->resource->getName();
125  }
126 
130  public function ‪getPath(): string
131  {
132  $method = 'getReadablePath';
133  if (is_callable([$this->resource->getParentFolder(), $method])) {
134  return call_user_func([$this->resource->getParentFolder(), $method]);
135  }
136 
137  return '';
138  }
139 
143  public function ‪getPublicUrl()
144  {
145  return $this->resource->getPublicUrl(true);
146  }
147 
151  public function ‪getExtension(): string
152  {
153  return strtoupper($this->resource->getExtension());
154  }
155 
159  public function ‪getIdentifier(): string
160  {
161  return $this->resource->getStorage()->getUid() . ':' . $this->resource->getIdentifier();
162  }
163 
167  public function ‪getLastModified(): string
168  {
169  return ‪BackendUtility::date($this->resource->getModificationTime());
170  }
171 
175  public function ‪getSize(): string
176  {
177  return GeneralUtility::formatSize($this->resource->getSize(), htmlspecialchars($this->‪getLanguageService()->getLL('byteSizeUnits')));
178  }
179 
183  public function ‪getIsReadable()
184  {
185  $method = 'checkActionPermission';
186  if (is_callable([$this->resource, $method])) {
187  return call_user_func_array([$this->resource, $method], ['read']);
188  }
189 
190  return false;
191  }
192 
196  public function ‪getIsWritable()
197  {
198  $method = 'checkActionPermission';
199  if (is_callable([$this->resource, $method])) {
200  return call_user_func_array([$this->resource, $method], ['write']);
201  }
202 
203  return false;
204  }
205 
209  public function ‪getIsReplaceable()
210  {
211  $method = 'checkActionPermission';
212  if (is_callable([$this->resource, $method])) {
213  return call_user_func_array([$this->resource, $method], ['replace']);
214  }
215 
216  return false;
217  }
218 
222  public function ‪getIsRenamable()
223  {
224  $method = 'checkActionPermission';
225  if (is_callable([$this->resource, $method])) {
226  return call_user_func_array([$this->resource, $method], ['rename']);
227  }
228 
229  return false;
230  }
231 
235  public function ‪isCopyable()
236  {
237  $method = 'checkActionPermission';
238  if (is_callable([$this->resource, $method])) {
239  return call_user_func_array([$this->resource, $method], ['copy']);
240  }
241 
242  return false;
243  }
244 
248  public function ‪isCuttable()
249  {
250  $method = 'checkActionPermission';
251  if (is_callable([$this->resource, $method])) {
252  return call_user_func_array([$this->resource, $method], ['move']);
253  }
254 
255  return false;
256  }
257 
261  public function ‪getIsDeletable()
262  {
263  $method = 'checkActionPermission';
264  if (is_callable([$this->resource, $method])) {
265  return call_user_func_array([$this->resource, $method], ['delete']);
266  }
267 
268  return false;
269  }
270 
274  public function ‪isSelected()
275  {
276  $fullIdentifier = $this->‪getIdentifier();
277  $md5 = GeneralUtility::shortMD5($fullIdentifier);
278 
280  $clipboard = GeneralUtility::makeInstance(Clipboard::class);
281  $clipboard->initializeClipboard();
282 
283  $isSel = $clipboard->isSelected('_FILE', $md5);
284 
285  if ($isSel) {
286  return $isSel;
287  }
288 
289  return false;
290  }
291 
295  public function ‪getIsImage()
296  {
297  return GeneralUtility::inList(‪$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($this->‪getExtension()));
298  }
299 
305  public function ‪getReferenceCount(): int
306  {
307  $uid = (int)$this->resource->getProperty('uid');
308 
309  if ($uid <= 0) {
310  return 0;
311  }
312 
313  if (!isset(static::$referenceCounts[$uid])) {
314  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_refindex');
315  $count = $queryBuilder->count('*')
316  ->from('sys_refindex')
317  ->where(
318  $queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
319  $queryBuilder->expr()->eq(
320  'ref_table',
321  $queryBuilder->createNamedParameter('sys_file', \PDO::PARAM_STR)
322  ),
323  $queryBuilder->expr()->eq(
324  'ref_uid',
325  $queryBuilder->createNamedParameter($this->resource->getProperty('uid'), \PDO::PARAM_INT)
326  ),
327  $queryBuilder->expr()->neq(
328  'tablename',
329  $queryBuilder->createNamedParameter('sys_file_metadata', \PDO::PARAM_STR)
330  )
331  )
332  ->execute()
333  ->fetchColumn();
334 
335  static::$referenceCounts[$uid] = $count;
336  }
337 
338  return static::$referenceCounts[$uid];
339  }
340 
347  public function ‪__call($method, $arguments)
348  {
349  if (is_callable([$this->resource, $method])) {
350  return call_user_func_array([$this->resource, $method], $arguments);
351  }
352 
353  return null;
354  }
355 
359  protected function ‪getBackendUser(): ‪BackendUserAuthentication
360  {
361  return ‪$GLOBALS['BE_USER'];
362  }
363 
367  protected function ‪getLanguageService(): ‪LanguageService
368  {
369  return ‪$GLOBALS['LANG'];
370  }
371 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Filelist\FileFacade\getIsMetadataEditable
‪bool getIsMetadataEditable()
Definition: FileFacade.php:93
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:21
‪TYPO3\CMS\Filelist\FileFacade\getIcon
‪string getIcon()
Definition: FileFacade.php:66
‪TYPO3\CMS\Backend\Clipboard\Clipboard
Definition: Clipboard.php:38
‪TYPO3\CMS\Filelist\FileFacade\getBackendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: FileFacade.php:356
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Filelist\FileFacade\isCopyable
‪bool isCopyable()
Definition: FileFacade.php:232
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\check
‪bool check($type, $value)
Definition: BackendUserAuthentication.php:648
‪TYPO3\CMS\Filelist\FileFacade\getReferenceCount
‪int getReferenceCount()
Definition: FileFacade.php:302
‪TYPO3\CMS\Filelist\FileFacade\getIsReadable
‪bool getIsReadable()
Definition: FileFacade.php:180
‪TYPO3\CMS\Filelist\FileFacade\getPath
‪string getPath()
Definition: FileFacade.php:127
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪TYPO3\CMS\Filelist\FileFacade\$iconFactory
‪TYPO3 CMS Core Imaging IconFactory $iconFactory
Definition: FileFacade.php:50
‪TYPO3\CMS\Filelist\FileFacade\getName
‪string getName()
Definition: FileFacade.php:119
‪TYPO3\CMS\Filelist\FileFacade\$referenceCounts
‪static array $referenceCounts
Definition: FileFacade.php:42
‪TYPO3\CMS\Filelist
‪TYPO3\CMS\Filelist\FileFacade\getIsWritable
‪bool getIsWritable()
Definition: FileFacade.php:193
‪TYPO3\CMS\Filelist\FileFacade
Definition: FileFacade.php:37
‪TYPO3\CMS\Filelist\FileFacade\$resource
‪TYPO3 CMS Core Resource FileInterface $resource
Definition: FileFacade.php:46
‪TYPO3\CMS\Filelist\FileFacade\getIsDeletable
‪bool getIsDeletable()
Definition: FileFacade.php:258
‪TYPO3\CMS\Filelist\FileFacade\__construct
‪__construct(FileInterface $resource)
Definition: FileFacade.php:56
‪TYPO3\CMS\Filelist\FileFacade\getIsRenamable
‪bool getIsRenamable()
Definition: FileFacade.php:219
‪TYPO3\CMS\Filelist\FileFacade\isSelected
‪bool isSelected()
Definition: FileFacade.php:271
‪TYPO3\CMS\Filelist\FileFacade\getLastModified
‪string getLastModified()
Definition: FileFacade.php:164
‪TYPO3\CMS\Filelist\FileFacade\getLanguageService
‪TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: FileFacade.php:364
‪TYPO3\CMS\Filelist\FileFacade\isCuttable
‪bool isCuttable()
Definition: FileFacade.php:245
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Filelist\FileFacade\getSize
‪string getSize()
Definition: FileFacade.php:172
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Filelist\FileFacade\__call
‪mixed __call($method, $arguments)
Definition: FileFacade.php:344
‪TYPO3\CMS\Filelist\FileFacade\getPublicUrl
‪string null getPublicUrl()
Definition: FileFacade.php:140
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Filelist\FileFacade\getIsImage
‪bool getIsImage()
Definition: FileFacade.php:292
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Filelist\FileFacade\getMetadataUid
‪int getMetadataUid()
Definition: FileFacade.php:101
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Filelist\FileFacade\getIdentifier
‪string getIdentifier()
Definition: FileFacade.php:156
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Filelist\FileFacade\getExtension
‪string getExtension()
Definition: FileFacade.php:148
‪TYPO3\CMS\Filelist\FileFacade\getIsReplaceable
‪bool getIsReplaceable()
Definition: FileFacade.php:206
‪TYPO3\CMS\Filelist\FileFacade\getResource
‪TYPO3 CMS Core Resource FileInterface getResource()
Definition: FileFacade.php:76
‪TYPO3\CMS\Backend\Utility\BackendUtility\date
‪static string date($tstamp)
Definition: BackendUtility.php:1179
‪TYPO3\CMS\Filelist\FileFacade\getIsEditable
‪bool getIsEditable()
Definition: FileFacade.php:84