-
Notifications
You must be signed in to change notification settings - Fork 1
/
ElFinderWidget.php
47 lines (41 loc) · 1.28 KB
/
ElFinderWidget.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
<?php
/**
* elFinder widget.
*
* @author Robert Korulczyk <[email protected]>
* @author Bogdan Savluk <[email protected]>
* @license http://opensource.org/licenses/BSD-3-Clause
*/
class ElFinderWidget extends CWidget {
/**
* Client settings.
*
* @see https://github.com/Studio-42/elFinder/wiki/Client-configuration-options
* @var array
*/
public $settings = [];
/** @var string */
public $connectorRoute = false;
/** @var array */
public $connectorParams = [];
public function run() {
require_once __DIR__ . '/ElFinderHelper.php';
ElFinderHelper::registerAssets();
// set required options
if (empty($this->connectorRoute)) {
throw new CException('$connectorRoute must be set!');
}
$this->settings['url'] = $this->controller->createUrl($this->connectorRoute, $this->connectorParams);
$this->settings['lang'] = ElFinderHelper::getLanguage();
if (Yii::app()->getRequest()->enableCsrfValidation) {
$this->settings['customData'] = [
Yii::app()->request->csrfTokenName => Yii::app()->request->csrfToken,
];
}
$id = $this->getId();
$settings = CJavaScript::encode($this->settings);
$cs = Yii::app()->getClientScript();
$cs->registerScript("elFinder#$id", "$('#$id').elfinder($settings);");
echo CHtml::tag('div', ['id' => $id], '');
}
}