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 getLastModified()
147  {
148  return BackendUtility::date($this->resource->getModificationTime());
149  }
150 
154  public function getSize()
155  {
156  return GeneralUtility::formatSize($this->resource->getSize(), $this->getLanguageService()->getLL('byteSizeUnits', true));
157  }
158 
162  public function getIsReadable()
163  {
164  $method = 'checkActionPermission';
165  if (is_callable([$this->resource, $method])) {
166  return call_user_func_array([$this->resource, $method], ['read']);
167  }
168 
169  return false;
170  }
171 
175  public function getIsWritable()
176  {
177  $method = 'checkActionPermission';
178  if (is_callable([$this->resource, $method])) {
179  return call_user_func_array([$this->resource, $method], ['write']);
180  }
181 
182  return false;
183  }
184 
188  public function getIsReplaceable()
189  {
190  $method = 'checkActionPermission';
191  if (is_callable([$this->resource, $method])) {
192  return call_user_func_array([$this->resource, $method], ['replace']);
193  }
194 
195  return false;
196  }
197 
201  public function getIsRenamable()
202  {
203  $method = 'checkActionPermission';
204  if (is_callable([$this->resource, $method])) {
205  return call_user_func_array([$this->resource, $method], ['rename']);
206  }
207 
208  return false;
209  }
210 
214  public function getIsDeletable()
215  {
216  $method = 'checkActionPermission';
217  if (is_callable([$this->resource, $method])) {
218  return call_user_func_array([$this->resource, $method], ['delete']);
219  }
220 
221  return false;
222  }
223 
227  public function getIsImage()
228  {
229  return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($this->getExtension()));
230  }
231 
237  public function getReferenceCount()
238  {
239  $uid = (int)$this->resource->getProperty('uid');
240 
241  if ($uid <= 0) {
242  return 0;
243  }
244 
245  if (!isset(static::$referenceCounts[$uid])) {
246  $count = $this->getDatabaseConnection()->exec_SELECTcountRows(
247  '*',
248  'sys_refindex',
249  'ref_table=\'sys_file\''
250  . ' AND ref_uid=' . (int)$this->resource->getProperty('uid')
251  . ' AND deleted=0'
252  . ' AND tablename != \'sys_file_metadata\''
253  );
254 
255  if (!is_int($count)) {
256  $count = 0;
257  }
258 
259  static::$referenceCounts[$uid] = $count;
260  }
261 
262  return static::$referenceCounts[$uid];
263  }
264 
271  public function __call($method, $arguments)
272  {
273  if (is_callable([$this->resource, $method])) {
274  return call_user_func_array([$this->resource, $method], $arguments);
275  }
276 
277  return null;
278  }
279 
283  protected function getDatabaseConnection()
284  {
285  return $GLOBALS['TYPO3_DB'];
286  }
287 
291  protected function getBackendUser()
292  {
293  return $GLOBALS['BE_USER'];
294  }
295 
299  protected function getLanguageService()
300  {
301  return $GLOBALS['LANG'];
302  }
303 }