|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package Cadmium\System\Modules\Filemanager |
|
5
|
|
|
* @author Anton Romanov |
|
6
|
|
|
* @copyright Copyright (c) 2015-2017, Anton Romanov |
|
7
|
|
|
* @link http://cadmium-cms.com |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Modules\Filemanager\Utils\Lister { |
|
11
|
|
|
|
|
12
|
|
|
use Modules\Filemanager, Utils\View, Number, Template; |
|
13
|
|
|
|
|
14
|
|
|
abstract class File { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Get a file item block |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
public static function getBlock(Filemanager\Utils\Entity $entity, bool $ajax) : Template\Block { |
|
21
|
|
|
|
|
22
|
|
|
$view = View::get(!$ajax ? 'Blocks/Filemanager/Lister/Item/File' : 'Blocks/Filemanager/Ajax/Item/File'); |
|
23
|
|
|
|
|
24
|
|
|
$parent = $entity->getParent(); $permissions = $parent->getPermissions(); |
|
25
|
|
|
|
|
26
|
|
|
$name = $entity->getName(); $path = $entity->getPath(); |
|
27
|
|
|
|
|
28
|
|
|
$mime = Filemanager\Utils\Mime::get($entity->getExtension()); |
|
29
|
|
|
|
|
30
|
|
|
$format = Filemanager\Utils\Mime::getFormat($entity->getExtension()); |
|
31
|
|
|
|
|
32
|
|
|
$query = ('?parent=' . $parent->getPath() . '&name=' . $name); |
|
33
|
|
|
|
|
34
|
|
|
$link = (INSTALL_PATH . '/admin/content/filemanager/' . $parent->getOrigin() . '/file' . $query); |
|
35
|
|
|
|
|
36
|
|
|
# Set data |
|
37
|
|
|
|
|
38
|
|
|
$view->name = $name; $view->path = $path; $view->mime = $mime; $view->format = $format; |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
# Set link |
|
41
|
|
|
|
|
42
|
|
|
$view->link = ($permissions['browse'] ? (INSTALL_PATH . '/uploads/' . $path) : $link); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
$view->target = ($permissions['browse'] ? '_blank' : '_self'); |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
# Set info |
|
47
|
|
|
|
|
48
|
|
|
$view->size = Number::size($entity->getSize()); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
# Set buttons |
|
51
|
|
|
|
|
52
|
|
|
if (!$ajax) { |
|
53
|
|
|
|
|
54
|
|
|
$view->getBlock('edit')->link = $link; |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$view->getBlock('remove')->class = ($permissions['manage'] ? 'negative' : 'disabled'); |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
} else { |
|
59
|
|
|
|
|
60
|
|
|
$is_media = (in_array($format, ['image', 'audio', 'video'], true)); |
|
61
|
|
|
|
|
62
|
|
|
$view->getBlock('media')->class = ($is_media ? 'grey' : 'disabled'); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
# ------------------------ |
|
66
|
|
|
|
|
67
|
|
|
return $view; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.