-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathElFinderHelper.php
149 lines (136 loc) · 3.18 KB
/
ElFinderHelper.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
147
148
149
<?php
/**
* Helper class for elFinder widgets.
*
* @author Robert Korulczyk <[email protected]>
* @license http://opensource.org/licenses/BSD-3-Clause
*/
class ElFinderHelper extends CComponent {
/**
* Available elFinder translations.
*
* @see directory: vendor/assets/js/i18n
* @var array
*/
public static $availableLanguages = [
'ar',
'bg',
'ca',
'cs',
'da',
'de',
'el',
'es',
'fa',
'fo',
'fr',
'fr_CA',
'he',
'hu',
'id',
'it',
'ja',
'ko',
'nl',
'no',
'pl',
'pt_BR',
'ro',
'ru',
'si',
'sk',
'sl',
'sr',
'sv',
'tr',
'ug_CN',
'uk',
'vi',
'zh_CN',
'zh_TW',
];
/** @var string */
private static $_assetsDir;
/**
* Register necessary elFinder scripts and styles.
*/
public static function registerAssets() {
$assetsDir = self::getAssetsDir();
$cs = Yii::app()->getClientScript();
// jQuery and jQuery UI
$cs->registerCoreScript('jquery');
$cs->registerCoreScript('jquery.ui');
$cs->registerCssFile($cs->getCoreScriptUrl() . '/jui/css/base/jquery-ui.css');
// elFinder CSS
if (YII_DEBUG) {
$cs->registerCssFile($assetsDir . '/css/elfinder.full.css');
} else {
$cs->registerCssFile($assetsDir . '/css/elfinder.min.css');
}
// elFinder JS
if (YII_DEBUG) {
$cs->registerScriptFile($assetsDir . '/js/elfinder.full.js');
} else {
$cs->registerScriptFile($assetsDir . '/js/elfinder.min.js');
}
// some css fixes
Yii::app()->clientScript->registerCss(
'elfinder-file-bg-fixer',
'.elfinder-cwd-file,.elfinder-cwd-file .elfinder-cwd-file-wrapper,.elfinder-cwd-file .elfinder-cwd-filename{background-image:none !important;}'
. '.elfinder-resize-preview{max-width: 50%}'
);
}
/**
* Register default elFinder aliases if needed.
*/
public static function registerAlias() {
if (!Yii::getPathOfAlias('elFinder')) {
Yii::setPathOfAlias('elFinder', __DIR__);
}
if (!Yii::getPathOfAlias('elFindervendor')) {
Yii::setPathOfAlias('elFindervendor', Yii::getPathOfAlias('elFinder.vendor'));
}
}
/**
* Register assets directory and return assets url path.
*
* @return string
*/
public static function getAssetsDir() {
if (self::$_assetsDir === null) {
self::registerAlias();
$dir = Yii::getPathOfAlias('elFindervendor.assets');
self::$_assetsDir = Yii::app()->getAssetManager()->publish($dir);
}
return self::$_assetsDir;
}
/**
* Try import TinyMceFileManager class.
*/
public static function importTinyMceFileManager() {
/* @noinspection MissingOrEmptyGroupStatementInspection */
if (@class_exists('TinyMceFileManager')) {
// class already imported or declared
} elseif (Yii::getPathOfAlias('tinymce')) {
// try import by declared alias
Yii::import('tinymce.TinyMceFileManager');
} else {
// try import by default extension directory
Yii::import('ext.tinymce.TinyMceFileManager');
}
}
public static function getLanguage() {
$lang = Yii::app()->language;
if (!in_array($lang, self::$availableLanguages, true)) {
if (strpos($lang, '_')) {
$lang = substr($lang, 0, strpos($lang, '_'));
if (!in_array($lang, self::$availableLanguages, true)) {
$lang = 'en';
}
} else {
$lang = 'en';
}
}
return $lang;
}
}