-
Notifications
You must be signed in to change notification settings - Fork 2
/
ElFinderWidget.php
83 lines (73 loc) · 3.09 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
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
<?php
/**
* Created by JetBrains PhpStorm.
* User: z_bodya
* Date: 6/20/12
* Time: 7:41 PM
* To change this template use File | Settings | File Templates.
*/
class ElFinderWidget extends CWidget
{
/**
* Client settings.
* More about this: https://github.com/Studio-42/elFinder/wiki/Client-configuration-options
* @var array
*/
public $settings = array();
public $connectorRoute = false;
private $assetsDir;
public function init()
{
$dir = dirname(__FILE__) . '/assets';
$this->assetsDir = Yii::app()->assetManager->publish($dir);
$cs = Yii::app()->getClientScript();
if (Yii::app()->getRequest()->enableCsrfValidation) {
$csrfTokenName = Yii::app()->request->csrfTokenName;
$csrfToken = Yii::app()->request->csrfToken;
Yii::app()->clientScript->registerMetaTag($csrfToken, 'csrf-token', null, array(),'csrf-token');
Yii::app()->clientScript->registerMetaTag($csrfTokenName, 'csrf-param', null, array(), 'csrf-param');
}
// jQuery and jQuery UI
$cs->registerCssFile($cs->getCoreScriptUrl() . '/jui/css/base/jquery-ui.css');
// $cs->registerCssFile($this->assetsDir . '/smoothness/jquery-ui-1.8.21.custom.css');
// $cs->registerCssFile('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/themes/smoothness/jquery-ui.css');
$cs->registerCoreScript('jquery');
$cs->registerCoreScript('jquery.ui');
// $cs->registerScriptFile('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js');
// elFinder CSS
$cs->registerCssFile($this->assetsDir . '/css/elfinder.css');
// elFinder JS
if (YII_DEBUG) {
$cs->registerScriptFile($this->assetsDir . '/js/elfinder.full.js');
} else {
$cs->registerScriptFile($this->assetsDir . '/js/elfinder.min.js');
}
// elFinder translation
$langs = array('bg', 'jp', 'sk', 'cs', 'ko', 'th', 'de', 'lv', 'tr', 'el', 'nl', 'uk',
'es', 'no', 'vi', 'fr', 'pl', 'zh_CN', 'hr', 'pt_BR', 'zh_TW', 'hu', 'ro', 'it', 'ru');
$lang = Yii::app()->language;
if (!in_array($lang, $langs)) {
if (strpos($lang, '_')) {
$lang = substr($lang, 0, strpos($lang, '_'));
if (!in_array($lang, $langs)) $lang = false;
} else {
$lang = false;
}
}
if ($lang !== false)
$cs->registerScriptFile($this->assetsDir . '/js/i18n/elfinder.' . $lang . '.js');
// set required options
if (empty($this->connectorRoute))
throw new CException('$connectorRoute must be set!');
$this->settings['url'] = Yii::app()->createUrl($this->connectorRoute);
$this->settings['lang'] = Yii::app()->language;
}
public function run()
{
$id = $this->getId();
$settings = CJavaScript::encode($this->settings);
$cs = Yii::app()->getClientScript();
$cs->registerScript("elFinder#$id", "$('#$id').elfinder($settings);");
echo "<div id=\"$id\"></div>";
}
}