forked from MihailDev/yii2-elfinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasePath.php
81 lines (60 loc) · 1.94 KB
/
BasePath.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* Date: 22.01.14
* Time: 10:39
*/
namespace mihaildev\elfinder;
use Yii;
use yii\base\Component as BaseComponent;
class BasePath extends BaseComponent{
public $driver = 'LocalFileSystem';
public $name = 'Root';
public $options = [];
public $access = ['read' => '*', 'write' => '*'];
public function getAlias(){
if(is_array($this->name)){
return Yii::t($this->name['category'], $this->name['message']);
}
return $this->name;
}
public function isAvailable(){
return $this->defaults['read'];
}
private $_defults;
public function getDefaults(){
if($this->_defults !== null)
return $this->_defults;
$this->_defults['read'] = false;
$this->_defults['write'] = false;
if(isset($this->access['write'])){
$this->_defults['write'] = true;
if($this->access['write'] != '*'){
$this->_defults['write'] = Yii::$app->user->can($this->access['write']);
}
}
if($this->_defults['write']){
$this->_defults['read'] = true;
}elseif(isset($this->access['read'])){
$this->_defults['read'] = true;
if($this->access['read'] != '*'){
$this->_defults['read'] = Yii::$app->user->can($this->access['read']);
}
}
return $this->_defults;
}
public function getRoot(){
$options['driver'] = $this->driver;
$options['defaults'] = $this->getDefaults();
$options['alias'] = $this->getAlias();
$options['mimeDetect'] = 'internal';
$options['imgLib'] = 'gd';
$options['attributes'][] = [
'pattern' => '#.*(\.tmb|\.quarantine)$#i',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
];
return \yii\helpers\ArrayHelper::merge($options, $this->options);
}
}