Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
"require": {
"php": ">=8.1",
"xpdo/xpdo": "^3.2",
"league/flysystem": "^2.0",
"league/flysystem-aws-s3-v3": "^2.0",
"league/flysystem-ftp": "^2.0",
"league/flysystem": "^3.0",
"league/flysystem-aws-s3-v3": "^3.0",
"league/flysystem-ftp": "^3.0",
"phpmailer/phpmailer": "^6.0",
"smarty/smarty": "^4.0",
"james-heinrich/phpthumb": "^1.7",
Expand Down
52 changes: 25 additions & 27 deletions core/src/Revolution/Sources/modMediaSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,17 @@ public function getContainerList($path)
$directories = $dirNames = $files = $fileNames = [];

if (!empty($path)) {
// Ensure the provided path can be read.
// Ensure the provided path is a directory.
try {
$mimeType = $this->filesystem->mimeType($path);
if (!$this->filesystem->directoryExists($path)) {
$this->addError('path', $this->xpdo->lexicon('file_folder_err_invalid'));
return [];
}
} catch (FilesystemException | UnableToRetrieveMetadata $e) {
$this->addError('path', $e->getMessage());
$this->xpdo->log(modX::LOG_LEVEL_ERROR, $e->getMessage());
return [];
}

if ($mimeType !== 'directory') {
$this->addError('path', $this->xpdo->lexicon('file_folder_err_invalid'));
return [];
}
}

try {
Expand Down Expand Up @@ -481,19 +479,17 @@ public function getObjectsInContainer($path)
$files = $fileNames = [];

if (!empty($path) && $path != DIRECTORY_SEPARATOR) {
// Ensure this is a directory.
try {
$mimeType = $this->filesystem->mimeType($path);
if (!$this->filesystem->directoryExists($path)) {
$this->addError('path', $this->xpdo->lexicon('file_folder_err_invalid'));
return [];
}
} catch (FilesystemException | UnableToRetrieveMetadata $e) {
$this->addError('path', $e->getMessage());
$this->xpdo->log(modX::LOG_LEVEL_ERROR, $e->getMessage());
return [];
}

// Ensure this is a directory.
if ($mimeType !== 'directory') {
$this->addError('path', $this->xpdo->lexicon('file_folder_err_invalid'));
return [];
}
}

try {
Expand Down Expand Up @@ -758,10 +754,14 @@ public function moveObject($from, $to, $point = 'append', $to_source = 0)
$to = $this->postfixSlash($to);
$newPath = rtrim($to, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename($from);

// Ensure object can be read.
// Ensure object exists and determine if it is a directory.
try {
$mimeType = $this->filesystem->mimeType($path);
if ($mimeType === 'directory') {
$isDirectory = $this->filesystem->directoryExists($path);
if (!$isDirectory && !$this->filesystem->fileExists($path)) {
$this->addError('path', $this->xpdo->lexicon('file_err_nf'));
return false;
}
if ($isDirectory) {
$newPath = $this->postfixSlash($newPath);
}
} catch (FilesystemException | UnableToReadFile $e) {
Expand All @@ -772,7 +772,7 @@ public function moveObject($from, $to, $point = 'append', $to_source = 0)

// Determine if moving to another media source.
if ($to_source) {
if ($mimeType === 'directory') {
if ($isDirectory) {
$this->addError('source', $this->xpdo->lexicon('no_move_folder'));

return false;
Expand Down Expand Up @@ -814,7 +814,7 @@ public function moveObject($from, $to, $point = 'append', $to_source = 0)
$this->filesystem->move($path, $newPath);
} catch (FilesystemException | UnableToMoveFile $e) {
// $this->addError('from', $this->xpdo->lexicon('file_err_rename'));
$prefix = $mimeType === 'directory' ? 'file_folder_' : 'file_' ;
$prefix = $isDirectory ? 'file_folder_' : 'file_' ;
$messageKey = $e instanceof UnableToMoveFile
? $prefix . 'err_move_write_exception'
: $prefix . 'err_move_write_general'
Expand Down Expand Up @@ -849,8 +849,7 @@ public function removeContainer($path)

// Ensure this is a directory.
try {
$mimeType = $this->filesystem->mimeType($path);
if ($mimeType !== 'directory') {
if (!$this->filesystem->directoryExists($path)) {
$this->addError('path', $this->xpdo->lexicon('file_folder_err_invalid'));
return false;
}
Expand Down Expand Up @@ -942,8 +941,7 @@ public function renameContainer($oldPath, $newName)

// Ensure current directory can be read.
try {
$mimeType = $this->filesystem->mimeType($oldPath);
if ($mimeType !== 'directory') {
if (!$this->filesystem->directoryExists($oldPath)) {
$this->addError('name', $this->xpdo->lexicon('file_folder_err_invalid'));
return false;
}
Expand Down Expand Up @@ -1221,8 +1219,8 @@ public function getVisibility($path)
$path = $this->sanitizePath($path);

try {
$mimeType = $this->filesystem->mimeType($path);
if (($mimeType === 'directory' && $this->visibility_dirs) || ($mimeType !== 'directory' && $this->visibility_files)) {
$isDirectory = $this->filesystem->directoryExists($path);
if (($isDirectory && $this->visibility_dirs) || (!$isDirectory && $this->visibility_files)) {
return $this->filesystem->visibility($path);
}
} catch (FilesystemException | UnableToRetrieveMetadata $e) {
Expand All @@ -1243,8 +1241,8 @@ public function setVisibility($path, $visibility)
{
$path = $this->sanitizePath($path);
try {
$mimeType = $this->filesystem->mimeType($path);
if (($mimeType === 'directory' && $this->visibility_dirs) || ($mimeType !== 'directory' && $this->visibility_files)) {
$isDirectory = $this->filesystem->directoryExists($path);
if (($isDirectory && $this->visibility_dirs) || (!$isDirectory && $this->visibility_files)) {
$this->filesystem->setVisibility($path, $visibility);
return true;
}
Expand Down
Loading