TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
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 
23 
33 {
39  protected static $referenceCounts = [];
40 
44  protected $resource;
45 
51  {
52  $this->resource = $resource;
53  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
54  }
55 
59  public function getIcon()
60  {
61  $title = htmlspecialchars($this->resource->getName() . ' [' . (int)$this->resource->getProperty('uid') . ']');
62  return '<span title="' . $title . '">' . $this->iconFactory->getIconForResource($this->resource, Icon::SIZE_SMALL) . '</span>';
63  }
64 
68  public function getResource()
69  {
70  return $this->resource;
71  }
72 
76  public function getIsEditable()
77  {
78  return $this->getIsWritable()
79  && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $this->resource->getExtension());
80  }
81 
85  public function getIsMetadataEditable()
86  {
87  return $this->resource->isIndexed() && $this->getIsWritable() && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata');
88  }
89 
93  public function getMetadataUid()
94  {
95  $uid = 0;
96  $method = '_getMetadata';
97  if (is_callable([$this->resource, $method])) {
98  $metadata = call_user_func([$this->resource, $method]);
99 
100  if (isset($metadata['uid'])) {
101  $uid = (int)$metadata['uid'];
102  }
103  }
104 
105  return $uid;
106  }
107 
111  public function getName()
112  {
113  return $this->resource->getName();
114  }
115 
119  public function getPath()
120  {
121  $method = 'getReadablePath';
122  if (is_callable([$this->resource->getParentFolder(), $method])) {
123  return call_user_func([$this->resource->getParentFolder(), $method]);
124  }
125 
126  return '';
127  }
128 
132  public function getPublicUrl()
133  {
134  return $this->resource->getPublicUrl(true);
135  }
136 
140  public function getExtension()
141  {
142  return strtoupper($this->resource->getExtension());
143  }
144 
148  public function getIdentifier()
149  {
150  return $this->resource->getStorage()->getUid() . ':' . $this->resource->getIdentifier();
151  }
152 
156  public function getLastModified()
157  {
158  return BackendUtility::date($this->resource->getModificationTime());
159  }
160 
164  public function getSize()
165  {
166  return GeneralUtility::formatSize($this->resource->getSize(), htmlspecialchars($this->getLanguageService()->getLL('byteSizeUnits')));
167  }
168 
172  public function getIsReadable()
173  {
174  $method = 'checkActionPermission';
175  if (is_callable([$this->resource, $method])) {
176  return call_user_func_array([$this->resource, $method], ['read']);
177  }
178 
179  return false;
180  }
181 
185  public function getIsWritable()
186  {
187  $method = 'checkActionPermission';
188  if (is_callable([$this->resource, $method])) {
189  return call_user_func_array([$this->resource, $method], ['write']);
190  }
191 
192  return false;
193  }
194 
198  public function getIsReplaceable()
199  {
200  $method = 'checkActionPermission';
201  if (is_callable([$this->resource, $method])) {
202  return call_user_func_array([$this->resource, $method], ['replace']);
203  }
204 
205  return false;
206  }
207 
211  public function getIsRenamable()
212  {
213  $method = 'checkActionPermission';
214  if (is_callable([$this->resource, $method])) {
215  return call_user_func_array([$this->resource, $method], ['rename']);
216  }
217 
218  return false;
219  }
220 
224  public function getIsDeletable()
225  {
226  $method = 'checkActionPermission';
227  if (is_callable([$this->resource, $method])) {
228  return call_user_func_array([$this->resource, $method], ['delete']);
229  }
230 
231  return false;
232  }
233 
237  public function getIsImage()
238  {
239  return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($this->getExtension()));
240  }
241 
247  public function getReferenceCount()
248  {
249  $uid = (int)$this->resource->getProperty('uid');
250 
251  if ($uid <= 0) {
252  return 0;
253  }
254 
255  if (!isset(static::$referenceCounts[$uid])) {
256  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_refindex');
257  $count = $queryBuilder->count('*')
258  ->from('sys_refindex')
259  ->where(
260  $queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
261  $queryBuilder->expr()->eq(
262  'ref_table',
263  $queryBuilder->createNamedParameter('sys_file', \PDO::PARAM_STR)
264  ),
265  $queryBuilder->expr()->eq(
266  'ref_uid',
267  $queryBuilder->createNamedParameter($this->resource->getProperty('uid'), \PDO::PARAM_INT)
268  ),
269  $queryBuilder->expr()->neq(
270  'tablename',
271  $queryBuilder->createNamedParameter('sys_file_metadata', \PDO::PARAM_STR)
272  )
273  )
274  ->execute()
275  ->fetchColumn();
276 
277  static::$referenceCounts[$uid] = $count;
278  }
279 
280  return static::$referenceCounts[$uid];
281  }
282 
289  public function __call($method, $arguments)
290  {
291  if (is_callable([$this->resource, $method])) {
292  return call_user_func_array([$this->resource, $method], $arguments);
293  }
294 
295  return null;
296  }
297 
301  protected function getBackendUser()
302  {
303  return $GLOBALS['BE_USER'];
304  }
305 
309  protected function getLanguageService()
310  {
311  return $GLOBALS['LANG'];
312  }
313 }
__call($method, $arguments)
Definition: FileFacade.php:289
static formatSize($sizeInBytes, $labels= '', $base=0)
__construct(FileInterface $resource)
Definition: FileFacade.php:50
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)