BasePath.php
2.41 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Date: 22.01.14
* Time: 10:39
*/
namespace mihaildev\elfinder;
use Yii;
use yii\base\Component as BaseComponent;
use yii\helpers\FileHelper;
/**
* @property array defaults
*/
class BasePath extends BaseComponent{
public $driver = 'LocalFileSystem';
public $name = 'Root';
public $options = [];
public $access = ['read' => '*', 'write' => '*'];
public $tmbPath;
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 $_defaults;
public function getDefaults(){
if($this->_defaults !== null)
return $this->_defaults;
$this->_defaults['read'] = false;
$this->_defaults['write'] = false;
if(isset($this->access['write'])){
$this->_defaults['write'] = true;
if($this->access['write'] != '*'){
$this->_defaults['write'] = Yii::$app->user->can($this->access['write']);
}
}
if($this->_defaults['write']){
$this->_defaults['read'] = true;
}elseif(isset($this->access['read'])){
$this->_defaults['read'] = true;
if($this->access['read'] != '*'){
$this->_defaults['read'] = Yii::$app->user->can($this->access['read']);
}
}
return $this->_defaults;
}
public function getRoot(){
$options['driver'] = $this->driver;
$options['defaults'] = $this->getDefaults();
$options['alias'] = $this->getAlias();
$options['tmpPath'] = Yii::getAlias('@runtime/elFinderTmpPath');
if(!empty($this->tmbPath)){
$this->tmbPath = trim($this->tmbPath, '/');
$options['tmbPath'] = \Yii::getAlias('@webroot/'.$this->tmbPath);
$options['tmbURL'] = \Yii::$app->request->hostInfo.\Yii::getAlias('@web/'.$this->tmbPath);
}else{
$subPath = md5($this->className().'|'.serialize($this->name));
$options['tmbPath'] = Yii::$app->assetManager->getPublishedPath(__DIR__).DIRECTORY_SEPARATOR.$subPath;
$options['tmbURL'] = \Yii::$app->request->hostInfo.Yii::$app->assetManager->getPublishedUrl(__DIR__).'/'.$subPath;
}
FileHelper::createDirectory($options['tmbPath']);
$options['mimeDetect'] = 'internal';
$options['imgLib'] = 'auto';
$options['attributes'][] = [
'pattern' => '#.*(\.tmb|\.quarantine)$#i',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
];
//var_export($options);exit;
return \yii\helpers\ArrayHelper::merge($options, $this->options);
}
}