TYPO3 CMS  TYPO3_8-7
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 
49  protected $iconFactory;
50 
56  {
57  $this->resource = $resource;
58  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
59  }
60 
64  public function getIcon()
65  {
66  $title = htmlspecialchars($this->resource->getName() . ' [' . (int)$this->resource->getProperty('uid') . ']');
67  return '<span title="' . $title . '">' . $this->iconFactory->getIconForResource($this->resource, Icon::SIZE_SMALL) . '</span>';
68  }
69 
73  public function getResource()
74  {
75  return $this->resource;
76  }
77 
81  public function getIsEditable()
82  {
83  return $this->getIsWritable()
84  && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $this->resource->getExtension());
85  }
86 
90  public function getIsMetadataEditable()
91  {
92  return $this->resource->isIndexed() && $this->getIsWritable() && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata');
93  }
94 
98  public function getMetadataUid()
99  {
100  $uid = 0;
101  $method = '_getMetadata';
102  if (is_callable([$this->resource, $method])) {
103  $metadata = call_user_func([$this->resource, $method]);
104 
105  if (isset($metadata['uid'])) {
106  $uid = (int)$metadata['uid'];
107  }
108  }
109 
110  return $uid;
111  }
112 
116  public function getName()
117  {
118  return $this->resource->getName();
119  }
120 
124  public function getPath()
125  {
126  $method = 'getReadablePath';
127  if (is_callable([$this->resource->getParentFolder(), $method])) {
128  return call_user_func([$this->resource->getParentFolder(), $method]);
129  }
130 
131  return '';
132  }
133 
137  public function getPublicUrl()
138  {
139  return $this->resource->getPublicUrl(true);
140  }
141 
145  public function getExtension()
146  {
147  return strtoupper($this->resource->getExtension());
148  }
149 
153  public function getIdentifier()
154  {
155  return $this->resource->getStorage()->getUid() . ':' . $this->resource->getIdentifier();
156  }
157 
161  public function getLastModified()
162  {
163  return BackendUtility::date($this->resource->getModificationTime());
164  }
165 
169  public function getSize()
170  {
171  return GeneralUtility::formatSize($this->resource->getSize(), htmlspecialchars($this->getLanguageService()->getLL('byteSizeUnits')));
172  }
173 
177  public function getIsReadable()
178  {
179  $method = 'checkActionPermission';
180  if (is_callable([$this->resource, $method])) {
181  return call_user_func_array([$this->resource, $method], ['read']);
182  }
183 
184  return false;
185  }
186 
190  public function getIsWritable()
191  {
192  $method = 'checkActionPermission';
193  if (is_callable([$this->resource, $method])) {
194  return call_user_func_array([$this->resource, $method], ['write']);
195  }
196 
197  return false;
198  }
199 
203  public function getIsReplaceable()
204  {
205  $method = 'checkActionPermission';
206  if (is_callable([$this->resource, $method])) {
207  return call_user_func_array([$this->resource, $method], ['replace']);
208  }
209 
210  return false;
211  }
212 
216  public function getIsRenamable()
217  {
218  $method = 'checkActionPermission';
219  if (is_callable([$this->resource, $method])) {
220  return call_user_func_array([$this->resource, $method], ['rename']);
221  }
222 
223  return false;
224  }
225 
229  public function getIsDeletable()
230  {
231  $method = 'checkActionPermission';
232  if (is_callable([$this->resource, $method])) {
233  return call_user_func_array([$this->resource, $method], ['delete']);
234  }
235 
236  return false;
237  }
238 
242  public function getIsImage()
243  {
244  return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($this->getExtension()));
245  }
246 
252  public function getReferenceCount()
253  {
254  $uid = (int)$this->resource->getProperty('uid');
255 
256  if ($uid <= 0) {
257  return 0;
258  }
259 
260  if (!isset(static::$referenceCounts[$uid])) {
261  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_refindex');
262  $count = $queryBuilder->count('*')
263  ->from('sys_refindex')
264  ->where(
265  $queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
266  $queryBuilder->expr()->eq(
267  'ref_table',
268  $queryBuilder->createNamedParameter('sys_file', \PDO::PARAM_STR)
269  ),
270  $queryBuilder->expr()->eq(
271  'ref_uid',
272  $queryBuilder->createNamedParameter($this->resource->getProperty('uid'), \PDO::PARAM_INT)
273  ),
274  $queryBuilder->expr()->neq(
275  'tablename',
276  $queryBuilder->createNamedParameter('sys_file_metadata', \PDO::PARAM_STR)
277  )
278  )
279  ->execute()
280  ->fetchColumn();
281 
282  static::$referenceCounts[$uid] = $count;
283  }
284 
285  return static::$referenceCounts[$uid];
286  }
287 
294  public function __call($method, $arguments)
295  {
296  if (is_callable([$this->resource, $method])) {
297  return call_user_func_array([$this->resource, $method], $arguments);
298  }
299 
300  return null;
301  }
302 
306  protected function getBackendUser()
307  {
308  return $GLOBALS['BE_USER'];
309  }
310 
314  protected function getLanguageService()
315  {
316  return $GLOBALS['LANG'];
317  }
318 }
__construct(FileInterface $resource)
Definition: FileFacade.php:55
__call($method, $arguments)
Definition: FileFacade.php:294
static makeInstance($className,... $constructorArguments)
static formatSize($sizeInBytes, $labels='', $base=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']