Update elfinder to latest version Important: requires composer update.

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent 5607ff69c8
commit ac8a66b240
  1. 2
      composer.json
  2. 2
      main/template/default/javascript/editor/elfinder_standalone.tpl
  3. 2
      src/Chamilo/CoreBundle/Component/Editor/Driver/CourseDriver.php
  4. 9
      src/Chamilo/CoreBundle/Component/Editor/Driver/PersonalDriver.php
  5. 314
      src/Chamilo/CoreBundle/Component/Editor/Finder.php

@ -78,7 +78,7 @@
"szymach/c-pchart": "1.*", "szymach/c-pchart": "1.*",
"aferrandini/phpqrcode": "1.0.1", "aferrandini/phpqrcode": "1.0.1",
"mpdf/mpdf": "6.1.*", "mpdf/mpdf": "6.1.*",
"barryvdh/elfinder-builds": "2.1.0.3", "studio-42/elfinder": "2.1.*",
"jbroadway/urlify": "dev-master", "jbroadway/urlify": "dev-master",
"monolog/monolog": "~1.0", "monolog/monolog": "~1.0",
"ircmaxell/password-compat": "~1.0.4", "ircmaxell/password-compat": "~1.0.4",

@ -1,4 +1,4 @@
{% set finderFolder = _p.web ~ 'vendor/barryvdh/elfinder-builds/' %} {% set finderFolder = _p.web ~ 'vendor/studio-42/elfinder/' %}
<!-- elFinder CSS (REQUIRED) --> <!-- elFinder CSS (REQUIRED) -->
<link rel="stylesheet" type="text/css" media="screen" href="{{ finderFolder }}css/elfinder.full.css"> <link rel="stylesheet" type="text/css" media="screen" href="{{ finderFolder }}css/elfinder.full.css">
<link rel="stylesheet" type="text/css" media="screen" href="{{ finderFolder }}css/theme.css"> <link rel="stylesheet" type="text/css" media="screen" href="{{ finderFolder }}css/theme.css">

@ -219,7 +219,7 @@ class CourseDriver extends Driver implements DriverInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function upload($fp, $dst, $name, $tmpname) public function upload($fp, $dst, $name, $tmpname, $hashes = array())
{ {
$this->setConnectorFromPlugin(); $this->setConnectorFromPlugin();

@ -20,7 +20,6 @@ class PersonalDriver extends Driver implements DriverInterface
$userId = api_get_user_id(); $userId = api_get_user_id();
$dir = \UserManager::getUserPathById($userId, 'system'); $dir = \UserManager::getUserPathById($userId, 'system');
if (!empty($dir)) { if (!empty($dir)) {
if (!is_dir($dir)) { if (!is_dir($dir)) {
mkdir($dir); mkdir($dir);
} }
@ -37,11 +36,9 @@ class PersonalDriver extends Driver implements DriverInterface
public function getConfiguration() public function getConfiguration()
{ {
if ($this->allow()) { if ($this->allow()) {
$userId = api_get_user_id(); $userId = api_get_user_id();
if (!empty($userId)) { if (!empty($userId)) {
// Adding user personal files // Adding user personal files
$dir = \UserManager::getUserPathById($userId, 'system'); $dir = \UserManager::getUserPathById($userId, 'system');
$dirWeb = \UserManager::getUserPathById($userId, 'web'); $dirWeb = \UserManager::getUserPathById($userId, 'web');
@ -78,12 +75,10 @@ class PersonalDriver extends Driver implements DriverInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function upload($fp, $dst, $name, $tmpname) public function upload($fp, $dst, $name, $tmpname, $hashes = array())
{ {
$this->setConnectorFromPlugin(); $this->setConnectorFromPlugin();
if ($this->allow()) { if ($this->allow()) {
return parent::upload($fp, $dst, $name, $tmpname); return parent::upload($fp, $dst, $name, $tmpname);
} }
} }
@ -96,7 +91,6 @@ class PersonalDriver extends Driver implements DriverInterface
$this->setConnectorFromPlugin(); $this->setConnectorFromPlugin();
if ($this->allow()) { if ($this->allow()) {
return parent::rm($hash); return parent::rm($hash);
} }
} }
@ -107,7 +101,6 @@ class PersonalDriver extends Driver implements DriverInterface
public function allow() public function allow()
{ {
//if ($this->connector->security->isGranted('IS_AUTHENTICATED_FULLY')) { //if ($this->connector->security->isGranted('IS_AUTHENTICATED_FULLY')) {
return !api_is_anonymous(); return !api_is_anonymous();
} }
} }

@ -3,7 +3,15 @@
namespace Chamilo\CoreBundle\Component\Editor; namespace Chamilo\CoreBundle\Component\Editor;
use elFinder;
use elFinderSession;
use Exception;
/** /**
*
* Based in \elFinder this class only has a small change that allows use
* drivers with out adding elFinderVolume as class name.
*
* Class Finder * Class Finder
* *
* This class just modifies this line: * This class just modifies this line:
@ -14,100 +22,218 @@ namespace Chamilo\CoreBundle\Component\Editor;
*/ */
class Finder extends \elFinder class Finder extends \elFinder
{ {
/** /**
* Constructor * Constructor
* *
* @param array elFinder and roots configurations * @param array elFinder and roots configurations
* @return void * @author Dmitry (dio) Levashov
* @author Dmitry (dio) Levashov */
**/ public function __construct($opts) {
public function __construct($opts) // set error handler of WARNING, NOTICE
{ $errLevel = E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE | E_STRICT | E_RECOVERABLE_ERROR;
if (session_id() == '') { if (defined('E_DEPRECATED')) {
session_start(); $errLevel |= E_DEPRECATED | E_USER_DEPRECATED;
} }
set_error_handler('elFinder::phpErrorHandler', $errLevel);
$this->time = $this->utime();
$this->debug = (isset($opts['debug']) && $opts['debug'] ? true : false); // convert PATH_INFO to GET query
$this->timeout = (isset($opts['timeout']) ? $opts['timeout'] : 0); if (! empty($_SERVER['PATH_INFO'])) {
$this->netVolumesSessionKey = !empty($opts['netVolumesSessionKey'])? $opts['netVolumesSessionKey'] : 'elFinderNetVolumes'; $_ps = explode('/', trim($_SERVER['PATH_INFO'], '/'));
$this->callbackWindowURL = (isset($opts['callbackWindowURL']) ? $opts['callbackWindowURL'] : ''); if (! isset($_GET['cmd'])) {
$_cmd = $_ps[0];
// setlocale and global locale regists to elFinder::locale if (isset($this->commands[$_cmd])) {
self::$locale = !empty($opts['locale']) ? $opts['locale'] : 'en_US.UTF-8'; $_GET['cmd'] = $_cmd;
$_i = 1;
if (false === @setlocale(LC_ALL, self::$locale)) { foreach(array_keys($this->commands[$_cmd]) as $_k) {
self::$locale = setlocale(LC_ALL, ''); if (isset($_ps[$_i])) {
} if (! isset($_GET[$_k])) {
$_GET[$_k] = $_ps[$_i];
// bind events listeners }
if (!empty($opts['bind']) && is_array($opts['bind'])) { } else {
$_req = $_SERVER["REQUEST_METHOD"] == 'POST' ? $_POST : $_GET; break;
$_reqCmd = isset($_req['cmd']) ? $_req['cmd'] : ''; }
foreach ($opts['bind'] as $cmd => $handlers) { }
$doRegist = (strpos($cmd, '*') !== false); }
if (! $doRegist) { }
$_getcmd = create_function('$cmd', 'list($ret) = explode(\'.\', $cmd);return trim($ret);'); }
$doRegist = ($_reqCmd && in_array($_reqCmd, array_map($_getcmd, explode(' ', $cmd))));
} // set elFinder instance
if ($doRegist) { elFinder::$instance = $this;
if (! is_array($handlers) || is_object($handlers[0])) {
$handlers = array($handlers); // setup debug mode
} $this->debug = (isset($opts['debug']) && $opts['debug'] ? true : false);
foreach($handlers as $handler) { if ($this->debug) {
if ($handler) { error_reporting(defined('ELFINDER_DEBUG_ERRORLEVEL')? ELFINDER_DEBUG_ERRORLEVEL : -1);
if (is_string($handler) && strpos($handler, '.')) { ini_set('diaplay_errors', '1');
list($_domain, $_name, $_method) = array_pad(explode('.', $handler), 3, ''); }
if (strcasecmp($_domain, 'plugin') === 0) {
if ($plugin = $this->getPluginInstance($_name, isset($opts['plugin'][$_name])? $opts['plugin'][$_name] : array()) if (! interface_exists('elFinderSessionInterface')) {
and method_exists($plugin, $_method)) { include_once dirname(__FILE__).'/elFinderSessionInterface.php';
$this->bind($cmd, array($plugin, $_method)); }
}
} // session handler
} else { if (!empty($opts['session']) && $opts['session'] instanceof elFinderSessionInterface) {
$this->bind($cmd, $handler); $this->session = $opts['session'];
} } else {
} $sessionOpts = array(
} 'base64encode' => !empty($opts['base64encodeSessionData']),
} 'keys' => array(
} 'default' => !empty($opts['sessionCacheKey']) ? $opts['sessionCacheKey'] : 'elFinderCaches',
} 'netvolume' => !empty($opts['netVolumesSessionKey'])? $opts['netVolumesSessionKey'] : 'elFinderNetVolumes'
)
if (!isset($opts['roots']) || !is_array($opts['roots'])) { );
$opts['roots'] = array(); if (! class_exists('elFinderSession')) {
} include_once dirname(__FILE__) . '/elFinderSession.php';
}
// check for net volumes stored in session $this->session = new elFinderSession($sessionOpts);
foreach ($this->getNetVolumes() as $root) { }
$opts['roots'][] = $root; // try session start | restart
} $this->session->start();
// "mount" volumes $sessionUseCmds = array();
foreach ($opts['roots'] as $i => $o) { if (isset($opts['sessionUseCmds']) && is_array($opts['sessionUseCmds'])) {
//$class = 'elFinderVolume'.(isset($o['driver']) ? $o['driver'] : ''); $sessionUseCmds = $opts['sessionUseCmds'];
$class = isset($o['driver']) ? $o['driver'] : ''; }
if (class_exists($class)) { // set self::$volumesCnt by HTTP header "X-elFinder-VolumesCntStart"
$volume = new $class(); if (isset($_SERVER['HTTP_X_ELFINDER_VOLUMESCNTSTART']) && ($volumesCntStart = intval($_SERVER['HTTP_X_ELFINDER_VOLUMESCNTSTART']))) {
self::$volumesCnt = $volumesCntStart;
if ($volume->mount($o)) { }
// unique volume id (ends on "_") - used as prefix to files hash
$id = $volume->id(); $this->time = $this->utime();
$this->sessionCloseEarlier = isset($opts['sessionCloseEarlier'])? (bool)$opts['sessionCloseEarlier'] : true;
$this->volumes[$id] = $volume; $this->sessionUseCmds = array_flip($sessionUseCmds);
if (!$this->default && $volume->isReadable()) { $this->timeout = (isset($opts['timeout']) ? $opts['timeout'] : 0);
$this->default = $this->volumes[$id]; $this->uploadTempPath = (isset($opts['uploadTempPath']) ? $opts['uploadTempPath'] : '');
} $this->callbackWindowURL = (isset($opts['callbackWindowURL']) ? $opts['callbackWindowURL'] : '');
} else { $this->maxTargets = (isset($opts['maxTargets']) ? intval($opts['maxTargets']) : $this->maxTargets);
$this->mountErrors[] = 'Driver "'.$class.'" : '.implode(' ', $volume->error()); elFinder::$commonTempPath = (isset($opts['commonTempPath']) ? $opts['commonTempPath'] : './.tmp');
} if (!is_writable(elFinder::$commonTempPath)) {
} else { elFinder::$commonTempPath = sys_get_temp_dir();
$this->mountErrors[] = 'Driver "'.$class.'" does not exists'; if (!is_writable(elFinder::$commonTempPath)) {
} elFinder::$commonTempPath = '';
} }
}
// if at least one readable volume - ii desu >_< $this->maxArcFilesSize = isset($opts['maxArcFilesSize'])? intval($opts['maxArcFilesSize']) : 0;
$this->loaded = !empty($this->default); $this->optionsNetVolumes = (isset($opts['optionsNetVolumes']) && is_array($opts['optionsNetVolumes']))? $opts['optionsNetVolumes'] : array();
if (isset($opts['itemLockExpire'])) {
$this->itemLockExpire = intval($opts['itemLockExpire']);
}
// deprecated settings
$this->netVolumesSessionKey = !empty($opts['netVolumesSessionKey'])? $opts['netVolumesSessionKey'] : 'elFinderNetVolumes';
self::$sessionCacheKey = !empty($opts['sessionCacheKey']) ? $opts['sessionCacheKey'] : 'elFinderCaches';
// check session cache
$_optsMD5 = md5(json_encode($opts['roots']));
if ($this->session->get('_optsMD5') !== $_optsMD5) {
$this->session->set('_optsMD5', $_optsMD5);
}
// setlocale and global locale regists to elFinder::locale
self::$locale = !empty($opts['locale']) ? $opts['locale'] : 'en_US.UTF-8';
if (false === setlocale(LC_ALL, self::$locale)) {
self::$locale = setlocale(LC_ALL, '');
}
// set defaultMimefile
elFinder::$defaultMimefile = (isset($opts['defaultMimefile']) ? $opts['defaultMimefile'] : '');
// bind events listeners
if (!empty($opts['bind']) && is_array($opts['bind'])) {
$_req = $_SERVER["REQUEST_METHOD"] == 'POST' ? $_POST : $_GET;
$_reqCmd = isset($_req['cmd']) ? $_req['cmd'] : '';
foreach ($opts['bind'] as $cmd => $handlers) {
$doRegist = (strpos($cmd, '*') !== false);
if (! $doRegist) {
$_getcmd = create_function('$cmd', 'list($ret) = explode(\'.\', $cmd);return trim($ret);');
$doRegist = ($_reqCmd && in_array($_reqCmd, array_map($_getcmd, explode(' ', $cmd))));
}
if ($doRegist) {
// for backward compatibility
if (! is_array($handlers)) {
$handlers = array($handlers);
} else {
if (count($handlers) === 2 && is_object($handlers[0])) {
$handlers = array($handlers);
}
}
foreach($handlers as $handler) {
if ($handler) {
if (is_string($handler) && strpos($handler, '.')) {
list($_domain, $_name, $_method) = array_pad(explode('.', $handler), 3, '');
if (strcasecmp($_domain, 'plugin') === 0) {
if ($plugin = $this->getPluginInstance($_name, isset($opts['plugin'][$_name])? $opts['plugin'][$_name] : array())
and method_exists($plugin, $_method)) {
$this->bind($cmd, array($plugin, $_method));
}
}
} else {
$this->bind($cmd, $handler);
}
}
}
}
}
}
if (!isset($opts['roots']) || !is_array($opts['roots'])) {
$opts['roots'] = array();
}
// check for net volumes stored in session
$netVolumes = $this->getNetVolumes();
foreach ($netVolumes as $key => $root) {
if (! isset($root['id'])) {
// given fixed unique id
if (! $root['id'] = $this->getNetVolumeUniqueId($netVolumes)) {
$this->mountErrors[] = 'Netmount Driver "'.$root['driver'].'" : Could\'t given volume id.';
continue;
}
}
$opts['roots'][$key] = $root;
}
// "mount" volumes
foreach ($opts['roots'] as $i => $o) {
//$class = 'elFinderVolume'.(isset($o['driver']) ? $o['driver'] : '');
// Chamilo change
$class = (isset($o['driver']) ? $o['driver'] : '');
if (class_exists($class)) {
$volume = new $class();
try {
if ($this->maxArcFilesSize && (empty($o['maxArcFilesSize']) || $this->maxArcFilesSize < $o['maxArcFilesSize'])) {
$o['maxArcFilesSize'] = $this->maxArcFilesSize;
}
// pass session handler
$volume->setSession($this->session);
if ($volume->mount($o)) {
// unique volume id (ends on "_") - used as prefix to files hash
$id = $volume->id();
$this->volumes[$id] = $volume;
if ((!$this->default || $volume->root() !== $volume->defaultPath()) && $volume->isReadable()) {
$this->default = $this->volumes[$id];
}
} else {
$this->removeNetVolume($i, $volume);
$this->mountErrors[] = 'Driver "'.$class.'" : '.implode(' ', $volume->error());
}
} catch (Exception $e) {
$this->removeNetVolume($i, $volume);
$this->mountErrors[] = 'Driver "'.$class.'" : '.$e->getMessage();
}
} else {
$this->mountErrors[] = 'Driver "'.$class.'" does not exist';
}
}
// if at least one readable volume - ii desu >_<
$this->loaded = !empty($this->default);
// restore error handler for now
restore_error_handler();
} }
} }

Loading…
Cancel
Save