3
3
4
4
namespace Chamilo \CoreBundle \Component \Editor ;
5
5
6
+ use elFinder ;
7
+ use elFinderSession ;
8
+ use Exception ;
9
+ use elFinderSessionInterface ;
10
+
6
11
/**
12
+ *
13
+ * Based in \elFinder this class only has a small change that allows use
14
+ * drivers with out adding elFinderVolume as class name.
15
+ *
7
16
* Class Finder
8
17
*
9
18
* This class just modifies this line:
14
23
*/
15
24
class Finder extends \elFinder
16
25
{
17
-
18
26
/**
19
27
* Constructor
20
28
*
21
29
* @param array elFinder and roots configurations
22
- * @return void
23
30
* @author Dmitry (dio) Levashov
24
- **/
25
- public function __construct ($ opts )
26
- {
27
- if (session_id () == '' ) {
28
- session_start ();
31
+ */
32
+ public function __construct ($ opts ) {
33
+ // set error handler of WARNING, NOTICE
34
+ $ errLevel = E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE | E_STRICT | E_RECOVERABLE_ERROR ;
35
+ if (defined ('E_DEPRECATED ' )) {
36
+ $ errLevel |= E_DEPRECATED | E_USER_DEPRECATED ;
29
37
}
38
+ set_error_handler ('elFinder::phpErrorHandler ' , $ errLevel );
30
39
31
- $ this ->time = $ this ->utime ();
40
+ // convert PATH_INFO to GET query
41
+ if (! empty ($ _SERVER ['PATH_INFO ' ])) {
42
+ $ _ps = explode ('/ ' , trim ($ _SERVER ['PATH_INFO ' ], '/ ' ));
43
+ if (! isset ($ _GET ['cmd ' ])) {
44
+ $ _cmd = $ _ps [0 ];
45
+ if (isset ($ this ->commands [$ _cmd ])) {
46
+ $ _GET ['cmd ' ] = $ _cmd ;
47
+ $ _i = 1 ;
48
+ foreach (array_keys ($ this ->commands [$ _cmd ]) as $ _k ) {
49
+ if (isset ($ _ps [$ _i ])) {
50
+ if (! isset ($ _GET [$ _k ])) {
51
+ $ _GET [$ _k ] = $ _ps [$ _i ];
52
+ }
53
+ } else {
54
+ break ;
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ // set elFinder instance
62
+ elFinder::$ instance = $ this ;
63
+
64
+ // setup debug mode
32
65
$ this ->debug = (isset ($ opts ['debug ' ]) && $ opts ['debug ' ] ? true : false );
66
+ if ($ this ->debug ) {
67
+ error_reporting (defined ('ELFINDER_DEBUG_ERRORLEVEL ' )? ELFINDER_DEBUG_ERRORLEVEL : -1 );
68
+ ini_set ('diaplay_errors ' , '1 ' );
69
+ }
70
+
71
+ if (! interface_exists ('elFinderSessionInterface ' )) {
72
+ include_once dirname (__FILE__ ).'/elFinderSessionInterface.php ' ;
73
+ }
74
+
75
+ // session handler
76
+ if (!empty ($ opts ['session ' ]) && $ opts ['session ' ] instanceof elFinderSessionInterface) {
77
+ $ this ->session = $ opts ['session ' ];
78
+ } else {
79
+ $ sessionOpts = array (
80
+ 'base64encode ' => !empty ($ opts ['base64encodeSessionData ' ]),
81
+ 'keys ' => array (
82
+ 'default ' => !empty ($ opts ['sessionCacheKey ' ]) ? $ opts ['sessionCacheKey ' ] : 'elFinderCaches ' ,
83
+ 'netvolume ' => !empty ($ opts ['netVolumesSessionKey ' ])? $ opts ['netVolumesSessionKey ' ] : 'elFinderNetVolumes '
84
+ )
85
+ );
86
+ if (! class_exists ('elFinderSession ' )) {
87
+ include_once dirname (__FILE__ ) . '/elFinderSession.php ' ;
88
+ }
89
+ $ this ->session = new elFinderSession ($ sessionOpts );
90
+ }
91
+ // try session start | restart
92
+ $ this ->session ->start ();
93
+
94
+ $ sessionUseCmds = array ();
95
+ if (isset ($ opts ['sessionUseCmds ' ]) && is_array ($ opts ['sessionUseCmds ' ])) {
96
+ $ sessionUseCmds = $ opts ['sessionUseCmds ' ];
97
+ }
98
+
99
+ // set self::$volumesCnt by HTTP header "X-elFinder-VolumesCntStart"
100
+ if (isset ($ _SERVER ['HTTP_X_ELFINDER_VOLUMESCNTSTART ' ]) && ($ volumesCntStart = intval ($ _SERVER ['HTTP_X_ELFINDER_VOLUMESCNTSTART ' ]))) {
101
+ self ::$ volumesCnt = $ volumesCntStart ;
102
+ }
103
+
104
+ $ this ->time = $ this ->utime ();
105
+ $ this ->sessionCloseEarlier = isset ($ opts ['sessionCloseEarlier ' ])? (bool )$ opts ['sessionCloseEarlier ' ] : true ;
106
+ $ this ->sessionUseCmds = array_flip ($ sessionUseCmds );
33
107
$ this ->timeout = (isset ($ opts ['timeout ' ]) ? $ opts ['timeout ' ] : 0 );
34
- $ this ->netVolumesSessionKey = ! empty ( $ opts ['netVolumesSessionKey ' ])? $ opts ['netVolumesSessionKey ' ] : 'elFinderNetVolumes ' ;
108
+ $ this ->uploadTempPath = ( isset ( $ opts ['uploadTempPath ' ]) ? $ opts ['uploadTempPath ' ] : '' ) ;
35
109
$ this ->callbackWindowURL = (isset ($ opts ['callbackWindowURL ' ]) ? $ opts ['callbackWindowURL ' ] : '' );
110
+ $ this ->maxTargets = (isset ($ opts ['maxTargets ' ]) ? intval ($ opts ['maxTargets ' ]) : $ this ->maxTargets );
111
+ elFinder::$ commonTempPath = (isset ($ opts ['commonTempPath ' ]) ? $ opts ['commonTempPath ' ] : './.tmp ' );
112
+ if (!is_writable (elFinder::$ commonTempPath )) {
113
+ elFinder::$ commonTempPath = sys_get_temp_dir ();
114
+ if (!is_writable (elFinder::$ commonTempPath )) {
115
+ elFinder::$ commonTempPath = '' ;
116
+ }
117
+ }
118
+ $ this ->maxArcFilesSize = isset ($ opts ['maxArcFilesSize ' ])? intval ($ opts ['maxArcFilesSize ' ]) : 0 ;
119
+ $ this ->optionsNetVolumes = (isset ($ opts ['optionsNetVolumes ' ]) && is_array ($ opts ['optionsNetVolumes ' ]))? $ opts ['optionsNetVolumes ' ] : array ();
120
+ if (isset ($ opts ['itemLockExpire ' ])) {
121
+ $ this ->itemLockExpire = intval ($ opts ['itemLockExpire ' ]);
122
+ }
123
+
124
+ // deprecated settings
125
+ $ this ->netVolumesSessionKey = !empty ($ opts ['netVolumesSessionKey ' ])? $ opts ['netVolumesSessionKey ' ] : 'elFinderNetVolumes ' ;
126
+ self ::$ sessionCacheKey = !empty ($ opts ['sessionCacheKey ' ]) ? $ opts ['sessionCacheKey ' ] : 'elFinderCaches ' ;
127
+
128
+ // check session cache
129
+ $ _optsMD5 = md5 (json_encode ($ opts ['roots ' ]));
130
+ if ($ this ->session ->get ('_optsMD5 ' ) !== $ _optsMD5 ) {
131
+ $ this ->session ->set ('_optsMD5 ' , $ _optsMD5 );
132
+ }
36
133
37
134
// setlocale and global locale regists to elFinder::locale
38
135
self ::$ locale = !empty ($ opts ['locale ' ]) ? $ opts ['locale ' ] : 'en_US.UTF-8 ' ;
39
- if (false === @ setlocale (LC_ALL , self ::$ locale )) {
136
+ if (false === setlocale (LC_ALL , self ::$ locale )) {
40
137
self ::$ locale = setlocale (LC_ALL , '' );
41
138
}
42
139
140
+ // set defaultMimefile
141
+ elFinder::$ defaultMimefile = (isset ($ opts ['defaultMimefile ' ]) ? $ opts ['defaultMimefile ' ] : '' );
142
+
43
143
// bind events listeners
44
144
if (!empty ($ opts ['bind ' ]) && is_array ($ opts ['bind ' ])) {
45
145
$ _req = $ _SERVER ["REQUEST_METHOD " ] == 'POST ' ? $ _POST : $ _GET ;
@@ -51,16 +151,21 @@ public function __construct($opts)
51
151
$ doRegist = ($ _reqCmd && in_array ($ _reqCmd , array_map ($ _getcmd , explode (' ' , $ cmd ))));
52
152
}
53
153
if ($ doRegist ) {
54
- if (! is_array ($ handlers ) || is_object ($ handlers [0 ])) {
154
+ // for backward compatibility
155
+ if (! is_array ($ handlers )) {
55
156
$ handlers = array ($ handlers );
157
+ } else {
158
+ if (count ($ handlers ) === 2 && is_object ($ handlers [0 ])) {
159
+ $ handlers = array ($ handlers );
160
+ }
56
161
}
57
162
foreach ($ handlers as $ handler ) {
58
163
if ($ handler ) {
59
164
if (is_string ($ handler ) && strpos ($ handler , '. ' )) {
60
165
list ($ _domain , $ _name , $ _method ) = array_pad (explode ('. ' , $ handler ), 3 , '' );
61
166
if (strcasecmp ($ _domain , 'plugin ' ) === 0 ) {
62
167
if ($ plugin = $ this ->getPluginInstance ($ _name , isset ($ opts ['plugin ' ][$ _name ])? $ opts ['plugin ' ][$ _name ] : array ())
63
- and method_exists ($ plugin , $ _method )) {
168
+ and method_exists ($ plugin , $ _method )) {
64
169
$ this ->bind ($ cmd , array ($ plugin , $ _method ));
65
170
}
66
171
}
@@ -78,35 +183,58 @@ public function __construct($opts)
78
183
}
79
184
80
185
// check for net volumes stored in session
81
- foreach ($ this ->getNetVolumes () as $ root ) {
82
- $ opts ['roots ' ][] = $ root ;
186
+ $ netVolumes = $ this ->getNetVolumes ();
187
+ foreach ($ netVolumes as $ key => $ root ) {
188
+ if (! isset ($ root ['id ' ])) {
189
+ // given fixed unique id
190
+ if (! $ root ['id ' ] = $ this ->getNetVolumeUniqueId ($ netVolumes )) {
191
+ $ this ->mountErrors [] = 'Netmount Driver " ' .$ root ['driver ' ].'" : Could \'t given volume id. ' ;
192
+ continue ;
193
+ }
194
+ }
195
+ $ opts ['roots ' ][$ key ] = $ root ;
83
196
}
84
197
85
198
// "mount" volumes
86
199
foreach ($ opts ['roots ' ] as $ i => $ o ) {
87
200
//$class = 'elFinderVolume'.(isset($o['driver']) ? $o['driver'] : '');
88
- $ class = isset ($ o ['driver ' ]) ? $ o ['driver ' ] : '' ;
201
+ // Chamilo change
202
+ $ class = (isset ($ o ['driver ' ]) ? $ o ['driver ' ] : '' );
89
203
90
204
if (class_exists ($ class )) {
91
205
$ volume = new $ class ();
92
206
93
- if ($ volume ->mount ($ o )) {
94
- // unique volume id (ends on "_") - used as prefix to files hash
95
- $ id = $ volume ->id ();
207
+ try {
208
+ if ($ this ->maxArcFilesSize && (empty ($ o ['maxArcFilesSize ' ]) || $ this ->maxArcFilesSize < $ o ['maxArcFilesSize ' ])) {
209
+ $ o ['maxArcFilesSize ' ] = $ this ->maxArcFilesSize ;
210
+ }
211
+ // pass session handler
212
+ $ volume ->setSession ($ this ->session );
213
+ if ($ volume ->mount ($ o )) {
214
+ // unique volume id (ends on "_") - used as prefix to files hash
215
+ $ id = $ volume ->id ();
96
216
97
- $ this ->volumes [$ id ] = $ volume ;
98
- if (!$ this ->default && $ volume ->isReadable ()) {
99
- $ this ->default = $ this ->volumes [$ id ];
217
+ $ this ->volumes [$ id ] = $ volume ;
218
+ if ((!$ this ->default || $ volume ->root () !== $ volume ->defaultPath ()) && $ volume ->isReadable ()) {
219
+ $ this ->default = $ this ->volumes [$ id ];
220
+ }
221
+ } else {
222
+ $ this ->removeNetVolume ($ i , $ volume );
223
+ $ this ->mountErrors [] = 'Driver " ' .$ class .'" : ' .implode (' ' , $ volume ->error ());
100
224
}
101
- } else {
102
- $ this ->mountErrors [] = 'Driver " ' .$ class .'" : ' .implode (' ' , $ volume ->error ());
225
+ } catch (Exception $ e ) {
226
+ $ this ->removeNetVolume ($ i , $ volume );
227
+ $ this ->mountErrors [] = 'Driver " ' .$ class .'" : ' .$ e ->getMessage ();
103
228
}
104
229
} else {
105
- $ this ->mountErrors [] = 'Driver " ' .$ class .'" does not exists ' ;
230
+ $ this ->mountErrors [] = 'Driver " ' .$ class .'" does not exist ' ;
106
231
}
107
232
}
108
233
109
234
// if at least one readable volume - ii desu >_<
110
235
$ this ->loaded = !empty ($ this ->default );
236
+
237
+ // restore error handler for now
238
+ restore_error_handler ();
111
239
}
112
240
}
0 commit comments