forked from MihailDev/yii2-elfinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathController.php
146 lines (110 loc) · 3.72 KB
/
Controller.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* Created by PhpStorm.
* User: Администратор
* Date: 20.01.14
* Time: 13:26
*/
namespace mihaildev\elfinder;
use Yii;
use yii\filters\AccessControl;
use yii\helpers\Json;
use yii\helpers\Url;
use yii\web\Controller as BaseController;
use yii\web\JsExpression;
/**
* Class Controller
* @package mihaildev\elfinder
* @property array $options
*/
class Controller extends BaseController{
public $roots = [];
public $access = ['@'];
public $disabledCommands = ['netmount'];
public $watermark;
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => $this->access,
],
],
],
];
}
private $_options;
public function getOptions()
{
if($this->_options !== null)
return $this->_options;
$this->_options['roots'] = [];
foreach($this->roots as $root){
if(is_string($root))
$root = ['path' => $root];
if(!isset($root['class']))
$root['class'] = 'mihaildev\elfinder\LocalPath';
$root = Yii::createObject($root);
/** @var \mihaildev\elfinder\LocalPath $root*/
if($root->isAvailable())
$this->_options['roots'][] = $root->getRoot();
}
if(!empty($this->watermark)){
$this->_options['bind']['upload.presave'] = 'Plugin.Watermark.onUpLoadPreSave';
if(is_string($this->watermark)){
$watermark = [
'source' => $this->watermark
];
}else{
$watermark = $this->watermark;
}
$this->_options['plugin']['Watermark'] = $watermark;
}
return $this->_options;
}
public function actionConnect(){
return $this->renderFile(__DIR__."/views/connect.php", ['options'=>$this->getOptions()]);
}
public function actionManager(){
$options = [
'url'=> Url::toRoute('connect'),
'customData' => [
Yii::$app->request->csrfParam => Yii::$app->request->csrfToken
],
'resizable' => false
];
if(isset($_GET['CKEditor'])){
$options['getFileCallback'] = new JsExpression('function(file){ '.
'window.opener.CKEDITOR.tools.callFunction('.Json::encode($_GET['CKEditorFuncNum']).', file.url); '.
'window.close(); }');
$options['lang'] = $_GET['langCode'];
}
if(isset($_GET['tinyMCE'])){
$options['getFileCallback'] = new JsExpression('function(file) { FileBrowserDialogue.mySubmit(file); }');
}
if(isset($_GET['filter'])){
if(is_array($_GET['filter']))
$options['onlyMimes'] = $_GET['filter'];
else
$options['onlyMimes'] = [$_GET['filter']];
}
if(isset($_GET['lang']))
$options['lang'] = $_GET['lang'];
if(isset($_GET['callback'])){
if(isset($_GET['multiple']))
$options['commandsOptions']['getfile']['multiple'] = true;
$options['getFileCallback'] = new JsExpression('function(file){ '.
'if (window!=window.top) {var parent = window.parent;}else{var parent = window.opener;}'.
'if(parent.mihaildev.elFinder.callFunction('.Json::encode($_GET['callback']).', file))'.
'window.close(); }');
}
if(!isset($options['lang']))
$options['lang'] = Yii::$app->language;
if(!empty($this->disabledCommands))
$options['commands'] = new JsExpression('ElFinderGetCommands('.Json::encode($this->disabledCommands).')');
return $this->renderFile(__DIR__."/views/manager.php", ['options'=>$options]);
}
}