Skip to content

Commit

Permalink
Respect skipFiles and allowFileTypes from media source
Browse files Browse the repository at this point in the history
Resolves #145
  • Loading branch information
theboxer committed Feb 22, 2019
1 parent 72100b7 commit 6e92505
Showing 1 changed file with 64 additions and 16 deletions.
80 changes: 64 additions & 16 deletions core/components/fred/model/fred/src/Endpoint/ElFinder.php
Expand Up @@ -11,6 +11,7 @@
namespace Fred\Endpoint;

use Firebase\JWT\JWT;
use Fred\Utils;

class ElFinder extends Endpoint
{
Expand Down Expand Up @@ -82,7 +83,7 @@ public function run()

$readOnly = false;
if (isset($properties['fredReadOnly']) && ($properties['fredReadOnly']['value'] === true)) $readOnly = true;

$roots[] = [
'id' => 'ms' . $mediaSource->id,
'driver' => 'LocalFileSystem',
Expand All @@ -93,21 +94,7 @@ public function run()
'startPath' => $path,
'disabled' => $readOnly ? array('rename', 'rm', 'cut', 'copy') : [],
'uploadDeny' => ['text/x-php'],
'attributes' => [
[
'pattern' => '/.php/',
'read' => false,
'write' => false,
'locked' => true,
'hidden' => true,
],
[
'pattern' => '/.*/',
'read' => true,
'write' => !$readOnly,
'locked' => false
]
]
'attributes' => $this->getRootAttributes($properties)
];

}
Expand All @@ -117,4 +104,65 @@ public function run()
$connector = new \elFinderConnector(new \elFinder($options));
$connector->run();
}

private function getRootAttributes($properties)
{
$readOnly = false;
if (isset($properties['fredReadOnly']) && ($properties['fredReadOnly']['value'] === true)) $readOnly = true;

$skipFiles = isset($properties['skipFiles']) ? $properties['skipFiles']['value'] : '';
$skipFiles = Utils::explodeAndClean($skipFiles);

$allowedFileTypes = isset($properties['allowedFileTypes']) ? $properties['allowedFileTypes']['value'] : '';
$allowedFileTypes = Utils::explodeAndClean($allowedFileTypes);

$attributes = [];

if (!empty($allowedFileTypes)) {
foreach ($allowedFileTypes as $fileType) {
$attributes[] = [
'pattern' => '/.' . $fileType . '/',
'read' => true,
'write' => !$readOnly,
'locked' => false,
'hidden' => false,
];
}

$attributes[] = [
'pattern' => '/\..*/',
'read' => false,
'write' => false,
'locked' => true,
'hidden' => true,
];
} else {
$attributes[] = [
'pattern' => '/.php/',
'read' => false,
'write' => false,
'locked' => true,
'hidden' => true,
];

foreach ($skipFiles as $file) {
$attributes[] = [
'pattern' => '/' . $file . '/',
'read' => false,
'write' => false,
'locked' => true,
'hidden' => true,
];
}

$attributes[] = [
'pattern' => '/.*/',
'read' => true,
'write' => !$readOnly,
'locked' => false
];
}

return $attributes;
}
}

0 comments on commit 6e92505

Please sign in to comment.