TYPO3 CMS  TYPO3_7-6
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 
21 
31 {
37  protected static $referenceCounts = [];
38 
42  protected $resource;
43 
48  public function __construct(\TYPO3\CMS\Core\Resource\FileInterface $resource)
49  {
50  $this->resource = $resource;
51  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
52  }
53 
57  public function getIcon()
58  {
59  $title = htmlspecialchars($this->resource->getName() . ' [' . (int)$this->resource->getProperty('uid') . ']');
60  return '<span title="' . $title . '">' . $this->iconFactory->getIconForResource($this->resource, Icon::SIZE_SMALL) . '</span>';
61  }
62 
66  public function getResource()
67  {
68  return $this->resource;
69  }
70 
74  public function getIsEditable()
75  {
76  return $this->getIsWritable()
77  && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $this->resource->getExtension());
78  }
79 
83  public function getIsMetadataEditable()
84  {
85  return $this->resource->isIndexed() && $this->getIsWritable() && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata');
86  }
87 
91  public function getMetadataUid()
92  {
93  $uid = 0;
94  $method = '_getMetadata';
95  if (is_callable([$this->resource, $method])) {
96  $metadata = call_user_func([$this->resource, $method]);
97 
98  if (isset($metadata['uid'])) {
99  $uid = (int)$metadata['uid'];
100  }
101  }
102 
103  return $uid;
104  }
105 
109  public function getName()
110  {
111  return $this->resource->getName();
112  }
113 
117  public function getPath()
118  {
119  $method = 'getReadablePath';
120  if (is_callable([$this->resource->getParentFolder(), $method])) {
121  return call_user_func([$this->resource->getParentFolder(), $method]);
122  }
123 
124  return '';
125  }
126 
130  public function getPublicUrl()
131  {
132  return $this->resource->getPublicUrl(true);
133  }
134 
138  public function getExtension()
139  {
140  return strtoupper($this->resource->getExtension());
141  }
142 
146  public function getIdentifier()
147  {
148  return $this->resource->getStorage()->getUid() . ':' . $this->resource->getIdentifier();
149  }
150 
154  public function getLastModified()
155  {
156  return BackendUtility::date($this->resource->getModificationTime());
157  }
158 
162  public function getSize()
163  {
164  return GeneralUtility::formatSize($this->resource->getSize(), $this->getLanguageService()->getLL('byteSizeUnits', true));
165  }
166 
170  public function getIsReadable()
171  {
172  $method = 'checkActionPermission';
173  if (is_callable([$this->resource, $method])) {
174  return call_user_func_array([$this->resource, $method], ['read']);
175  }
176 
177  return false;
178  }
179 
183  public function getIsWritable()
184  {
185  $method = 'checkActionPermission';
186  if (is_callable([$this->resource, $method])) {
187  return call_user_func_array([$this->resource, $method], ['write']);
188  }
189 
190  return false;
191  }
192 
196  public function getIsReplaceable()
197  {
198  $method = 'checkActionPermission';
199  if (is_callable([$this->resource, $method])) {
200  return call_user_func_array([$this->resource, $method], ['replace']);
201  }
202 
203  return false;
204  }
205 
209  public function getIsRenamable()
210  {
211  $method = 'checkActionPermission';
212  if (is_callable([$this->resource, $method])) {
213  return call_user_func_array([$this->resource, $method], ['rename']);
214  }
215 
216  return false;
217  }
218 
222  public function getIsDeletable()
223  {
224  $method = 'checkActionPermission';
225  if (is_callable([$this->resource, $method])) {
226  return call_user_func_array([$this->resource, $method], ['delete']);
227  }
228 
229  return false;
230  }
231 
235  public function getIsImage()
236  {
237  return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($this->getExtension()));
238  }
239 
245  public function getReferenceCount()
246  {
247  $uid = (int)$this->resource->getProperty('uid');
248 
249  if ($uid <= 0) {
250  return 0;
251  }
252 
253  if (!isset(static::$referenceCounts[$uid])) {
254  $count = $this->getDatabaseConnection()->exec_SELECTcountRows(
255  '*',
256  'sys_refindex',
257  'ref_table=\'sys_file\''
258  . ' AND ref_uid=' . (int)$this->resource->getProperty('uid')
259  . ' AND deleted=0'
260  . ' AND tablename != \'sys_file_metadata\''
261  );
262 
263  if (!is_int($count)) {
264  $count = 0;
265  }
266 
267  static::$referenceCounts[$uid] = $count;
268  }
269 
270  return static::$referenceCounts[$uid];
271  }
272 
279  public function __call($method, $arguments)
280  {
281  if (is_callable([$this->resource, $method])) {
282  return call_user_func_array([$this->resource, $method], $arguments);
283  }
284 
285  return null;
286  }
287 
291  protected function getDatabaseConnection()
292  {
293  return $GLOBALS['TYPO3_DB'];
294  }
295 
299  protected function getBackendUser()
300  {
301  return $GLOBALS['BE_USER'];
302  }
303 
307  protected function getLanguageService()
308  {
309  return $GLOBALS['LANG'];
310  }
311 }
__call($method, $arguments)
Definition: FileFacade.php:279
$uid
Definition: server.php:38
static formatSize($sizeInBytes, $labels='', $base=0)
__construct(\TYPO3\CMS\Core\Resource\FileInterface $resource)
Definition: FileFacade.php:48
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']