Skip to content

Commit 501d19f

Browse files
committed
Update version of elfinder (requires composer update)
1 parent 2ed95ed commit 501d19f

File tree

5 files changed

+156
-34
lines changed

5 files changed

+156
-34
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"szymach/c-pchart": "1.*",
4747
"aferrandini/phpqrcode": "1.0.1",
4848
"mpdf/mpdf": "5.7.4",
49-
"barryvdh/elfinder-builds": "2.1.0.3",
49+
"studio-42/elfinder": "2.1.*",
5050
"jbroadway/urlify": "dev-master",
5151
"monolog/monolog": "~1.0",
5252
"doctrine/orm": "~2.2,>=2.2.3,<2.5",

main/template/default/javascript/editor/elfinder_standalone.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% set finderFolder = _p.web ~ 'vendor/barryvdh/elfinder-builds/' %}
1+
{% set finderFolder = _p.web ~ 'vendor/studio-42/elfinder/' %}
22
<!-- elFinder CSS (REQUIRED) -->
33
<link rel="stylesheet" type="text/css" media="screen" href="{{ finderFolder }}css/elfinder.full.css">
44
<link rel="stylesheet" type="text/css" media="screen" href="{{ finderFolder }}css/theme.css">

src/Chamilo/CoreBundle/Component/Editor/Driver/CourseDriver.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,11 @@ public function getCourseDirectory()
210210
/**
211211
* {@inheritdoc}
212212
*/
213-
public function upload($fp, $dst, $name, $tmpname)
213+
public function upload($fp, $dst, $name, $tmpname, $hashes = array())
214214
{
215215
$this->setConnectorFromPlugin();
216216

217217
if ($this->allowToEdit()) {
218-
219218
// upload file by elfinder.
220219
$result = parent::upload($fp, $dst, $name, $tmpname);
221220
$name = $result['name'];

src/Chamilo/CoreBundle/Component/Editor/Driver/PersonalDriver.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,11 @@ public function setup()
3737
public function getConfiguration()
3838
{
3939
if ($this->allow()) {
40-
4140
$userId = api_get_user_id();
4241

4342
if (!empty($userId)) {
44-
4543
// Adding user personal files
4644
$dir = \UserManager::getUserPathById($userId, 'system');
47-
4845
$dirWeb = \UserManager::getUserPathById($userId, 'rel');
4946

5047
$driver = array(
@@ -79,12 +76,11 @@ public function getConfiguration()
7976
/**
8077
* {@inheritdoc}
8178
*/
82-
public function upload($fp, $dst, $name, $tmpname)
79+
public function upload($fp, $dst, $name, $tmpname, $hashes = array())
8380
{
8481
$this->setConnectorFromPlugin();
8582

8683
if ($this->allow()) {
87-
8884
return parent::upload($fp, $dst, $name, $tmpname);
8985
}
9086
}
@@ -97,7 +93,6 @@ public function rm($hash)
9793
$this->setConnectorFromPlugin();
9894

9995
if ($this->allow()) {
100-
10196
return parent::rm($hash);
10297
}
10398
}

src/Chamilo/CoreBundle/Component/Editor/Finder.php

Lines changed: 152 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33

44
namespace Chamilo\CoreBundle\Component\Editor;
55

6+
use elFinder;
7+
use elFinderSession;
8+
use Exception;
9+
use elFinderSessionInterface;
10+
611
/**
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+
*
716
* Class Finder
817
*
918
* This class just modifies this line:
@@ -14,32 +23,123 @@
1423
*/
1524
class Finder extends \elFinder
1625
{
17-
1826
/**
1927
* Constructor
2028
*
2129
* @param array elFinder and roots configurations
22-
* @return void
2330
* @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;
2937
}
38+
set_error_handler('elFinder::phpErrorHandler', $errLevel);
3039

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
3265
$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);
33107
$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'] : '');
35109
$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+
}
36133

37134
// setlocale and global locale regists to elFinder::locale
38135
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)) {
40137
self::$locale = setlocale(LC_ALL, '');
41138
}
42139

140+
// set defaultMimefile
141+
elFinder::$defaultMimefile = (isset($opts['defaultMimefile']) ? $opts['defaultMimefile'] : '');
142+
43143
// bind events listeners
44144
if (!empty($opts['bind']) && is_array($opts['bind'])) {
45145
$_req = $_SERVER["REQUEST_METHOD"] == 'POST' ? $_POST : $_GET;
@@ -51,16 +151,21 @@ public function __construct($opts)
51151
$doRegist = ($_reqCmd && in_array($_reqCmd, array_map($_getcmd, explode(' ', $cmd))));
52152
}
53153
if ($doRegist) {
54-
if (! is_array($handlers) || is_object($handlers[0])) {
154+
// for backward compatibility
155+
if (! is_array($handlers)) {
55156
$handlers = array($handlers);
157+
} else {
158+
if (count($handlers) === 2 && is_object($handlers[0])) {
159+
$handlers = array($handlers);
160+
}
56161
}
57162
foreach($handlers as $handler) {
58163
if ($handler) {
59164
if (is_string($handler) && strpos($handler, '.')) {
60165
list($_domain, $_name, $_method) = array_pad(explode('.', $handler), 3, '');
61166
if (strcasecmp($_domain, 'plugin') === 0) {
62167
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)) {
64169
$this->bind($cmd, array($plugin, $_method));
65170
}
66171
}
@@ -78,35 +183,58 @@ public function __construct($opts)
78183
}
79184

80185
// 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;
83196
}
84197

85198
// "mount" volumes
86199
foreach ($opts['roots'] as $i => $o) {
87200
//$class = 'elFinderVolume'.(isset($o['driver']) ? $o['driver'] : '');
88-
$class = isset($o['driver']) ? $o['driver'] : '';
201+
// Chamilo change
202+
$class = (isset($o['driver']) ? $o['driver'] : '');
89203

90204
if (class_exists($class)) {
91205
$volume = new $class();
92206

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();
96216

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());
100224
}
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();
103228
}
104229
} else {
105-
$this->mountErrors[] = 'Driver "'.$class.'" does not exists';
230+
$this->mountErrors[] = 'Driver "'.$class.'" does not exist';
106231
}
107232
}
108233

109234
// if at least one readable volume - ii desu >_<
110235
$this->loaded = !empty($this->default);
236+
237+
// restore error handler for now
238+
restore_error_handler();
111239
}
112240
}

0 commit comments

Comments
 (0)