Skip to content

Commit

Permalink
[php:core] fix Studio-42#1315 implement function for copyJoin of vo…
Browse files Browse the repository at this point in the history
…lume root option
  • Loading branch information
nao-pon committed Apr 17, 2016
1 parent 833f590 commit 6f17fbb
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 34 deletions.
24 changes: 18 additions & 6 deletions php/elFinder.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,15 @@ public function exec($cmd, $args) {
);
}

if (isset($result['removed'])) {
foreach ($this->volumes as $volume) {
foreach ($this->volumes as $volume) {
if (isset($result['removed'])) {
$result['removed'] = array_merge($result['removed'], $volume->removed());
$volume->resetRemoved();
}
if (isset($result['added'])) {
$result['added'] = array_merge($result['added'], $volume->added());
debug($result);
}
$volume->resetResultStat();
}

// call handlers for this command
Expand Down Expand Up @@ -2281,8 +2285,14 @@ protected function paste($args) {
$result['warning'] = $this->error($dstVolume->error());
break;
}

$result['added'][] = $file;

$dirChange = ! empty($file['dirChange']);
unset($file['dirChange']);
if ($dirChange) {
$result['changed'][] = $file;
} else {
$result['added'][] = $file;
}
if ($rnres) {
$result = array_merge_recursive($result, $rnres);
}
Expand Down Expand Up @@ -2687,10 +2697,12 @@ protected function hashes($files) {
* @author Dmitry (dio) Levashov
**/
protected function filter($files) {
$exists = array();
foreach ($files as $i => $file) {
if (!empty($file['hidden']) || !$this->default->mimeAccepted($file['mime'])) {
if (isset($exists[$file['hash']]) || !empty($file['hidden']) || !$this->default->mimeAccepted($file['mime'])) {
unset($files[$i]);
}
$exists[$file['hash']] = true;
}
return array_merge($files, array());
}
Expand Down
120 changes: 92 additions & 28 deletions php/elFinderVolumeDriver.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,13 @@ abstract class elFinderVolumeDriver {
**/
protected $removed = array();

/**
* Store files added files info
*
* @var array
**/
protected $added = array();

/**
* Cache storage
*
Expand Down Expand Up @@ -1350,14 +1357,35 @@ public function removed() {
return $this->removed;
}

/**
* Return list of added files
*
* @deprecated
* @return array
* @author Naoki Sawada
**/
public function added() {
return $this->added;
}

/**
* Clean removed files list
*
* @return void
* @author Dmitry (dio) Levashov
**/
public function resetRemoved() {
$this->resetResultStat();
}

/**
* Clean added/removed files list
*
* @return void
**/
public function resetResultStat() {
$this->removed = array();
$this->added = array();
}

/**
Expand Down Expand Up @@ -1879,6 +1907,7 @@ public function paste($volume, $src, $dst, $rmSrc = false, $hashes = array()) {
}
$stat = $this->stat($test);
$this->clearcache();
$dstDirExists = false;
if ($stat && $stat['name'] === $name) { // file exists and check filename for item ID based filesystem
if ($this->options['copyOverwrite']) {
// do not replace file with dir or dir with file
Expand All @@ -1899,8 +1928,12 @@ public function paste($volume, $src, $dst, $rmSrc = false, $hashes = array()) {
return $this->setError(elFinder::ERROR_REPLACE, $errpath);
}
// remove existed file
if (!$this->remove($test)) {
return $this->setError(elFinder::ERROR_REPLACE, $this->path($stat['hash']));
if (! $this->options['copyJoin'] || $stat['mime'] !== 'directory') {
if (! $this->remove($test)) {
return $this->setError(elFinder::ERROR_REPLACE, $this->path($stat['hash']));
}
} else if ($stat['mime'] === 'directory') {
$dstDirExists = true;
}
} else {
$name = $this->uniqueName($destination, $name, ' ', false);
Expand All @@ -1914,26 +1947,43 @@ public function paste($volume, $src, $dst, $rmSrc = false, $hashes = array()) {
if ($this->inpathCE($destination, $source)) {
return $this->setError(elFinder::ERROR_COPY_INTO_ITSELF, $errpath);
}
$method = $rmSrc ? 'move' : 'copy';
$rmDir = false;
if ($rmSrc) {
if ($dstDirExists) {
$rmDir = true;
$method = 'copy';
} else {
$method = 'move';
}
} else {
$method = 'copy';
}
$this->clearcache();
return ($path = $this->$method($source, $destination, $name)) ? $this->stat($path) : false;
}

// copy/move from another volume
if (!$this->options['copyTo'] || !$volume->copyFromAllowed()) {
return $this->setError(elFinder::ERROR_COPY, $errpath, elFinder::ERROR_PERM_DENIED);
}

if (($path = $this->copyFrom($volume, $src, $destination, $name)) == false) {
return false;
}

if ($rmSrc) {
if (!$volume->rm($src)) {
return $this->setError(elFinder::ERROR_MOVE, $errpath, elFinder::ERROR_RM_SRC);
if ($res = ($path = $this->$method($source, $destination, $name)) ? $this->stat($path) : false) {
if ($rmDir) {
$this->remove($source);
}
} else {
return false;
}
} else {
// copy/move from another volume
if (!$this->options['copyTo'] || !$volume->copyFromAllowed()) {
return $this->setError(elFinder::ERROR_COPY, $errpath, elFinder::ERROR_PERM_DENIED);
}

if (($path = $this->copyFrom($volume, $src, $destination, $name)) == false) {
return false;
}

if ($rmSrc) {
if (!$volume->rm($src)) {
return $this->setError(elFinder::ERROR_MOVE, $errpath, elFinder::ERROR_RM_SRC);
}
}
$res = $this->stat($path);
}
return $this->stat($path);
return $res;
}

/**
Expand Down Expand Up @@ -3797,15 +3847,15 @@ protected function copy($src, $dst, $name) {
: $this->setError(elFinder::ERROR_COPY, $this->path($srcStat['hash']));
}

if ($srcStat['mime'] == 'directory') {
$test = $this->stat($this->joinPathCE($dst, $name));
if ($srcStat['mime'] === 'directory') {
$testStat = $this->stat($this->joinPathCE($dst, $name));
$this->clearcache();

if (($test && $test['mime'] != 'directory') || (! $test = $this->mkdir($this->encode($dst), $name))) {
if (($testStat && $testStat['mime'] != 'directory') || (! $testStat && ! $testStat = $this->mkdir($this->encode($dst), $name))) {
return $this->setError(elFinder::ERROR_COPY, $this->path($srcStat['hash']));
}

$dst = $this->decode($test['hash']);
$dst = $this->decode($testStat['hash']);

foreach ($this->getScandir($src) as $stat) {
if (empty($stat['hidden'])) {
Expand All @@ -3817,12 +3867,25 @@ protected function copy($src, $dst, $name) {
}
}
}
$this->clearcache();

$this->added[] = $testStat;

return $dst;
}

if ($this->options['copyJoin']) {
$test = $this->joinPathCE($dst, $name);
if ($testStat = $this->stat($test)) {
$this->remove($test);
}
} else {
$testStat = false;
}
if ($res = $this->convEncOut($this->_copy($this->convEncIn($src), $this->convEncIn($dst), $this->convEncIn($name)))) {
return is_string($res)? $res : $this->joinPathCE($dst, $name);
$path = is_string($res)? $res : $this->joinPathCE($dst, $name);
$this->clearcache();
$this->added[] = $this->stat($path);
return $path;
}

return $this->setError(elFinder::ERROR_COPY, $this->path($srcStat['hash']));
Expand Down Expand Up @@ -3883,8 +3946,7 @@ protected function copyFrom($volume, $src, $destination, $name) {
$test = $this->stat($this->joinPathCE($destination, $name));
$this->clearcache();

if (($test && $test['mime'] != 'directory') || (! $test = $this->mkdir($this->encode($destination), $name))) {
//if ((!$stat || $stat['mime'] != 'directory') && $this->convEncOut(!$this->_mkdir($this->convEncIn($destination), $this->convEncIn($name)))) {
if (($test && $test['mime'] != 'directory') || (! $test && ! $test = $this->mkdir($this->encode($destination), $name))) {
return $this->setError(elFinder::ERROR_COPY, $errpath);
}

Expand All @@ -3898,6 +3960,7 @@ protected function copyFrom($volume, $src, $destination, $name) {
}
}

$this->added[] = $test;
} else {
// $mime = $source['mime'];
// $w = $h = 0;
Expand All @@ -3924,6 +3987,8 @@ protected function copyFrom($volume, $src, $destination, $name) {
$this->remove($path, true);
return $this->setError(elFinder::ERROR_UPLOAD_FILE_MIME, $errpath);
}

$this->added[] = $stat;
}

return $path;
Expand Down Expand Up @@ -4457,7 +4522,6 @@ protected function imgSquareFit($path, $width, $height, $align = 'center', $vali
* @author Troex Nevelin
**/
protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null, $jpgQuality = null) {
debug($path, $degree);
if (($s = @getimagesize($path)) == false || $degree % 360 === 0) {
return false;
}
Expand Down

0 comments on commit 6f17fbb

Please sign in to comment.