-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'artgris:master' into master
- Loading branch information
Showing
11 changed files
with
164 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,60 +13,66 @@ | |
/** | ||
* @author Arthur Gribet <[email protected]> | ||
*/ | ||
class FileManager { | ||
class FileManager | ||
{ | ||
const VIEW_THUMBNAIL = 'thumbnail'; | ||
const VIEW_LIST = 'list'; | ||
|
||
/** | ||
* FileManager constructor. | ||
*/ | ||
public function __construct(private array $queryParameters, private array $configuration, private RouterInterface $router, private EventDispatcherInterface $dispatcher, private string $webDir) { | ||
public function __construct(private array $queryParameters, private array $configuration, private RouterInterface $router, private EventDispatcherInterface $dispatcher, private string $webDir) | ||
{ | ||
// Check Security | ||
$this->checkSecurity(); | ||
} | ||
|
||
public function getDirName(): string { | ||
public function getDirName(): string | ||
{ | ||
return \dirname($this->getBasePath()); | ||
} | ||
|
||
public function getBaseName(): string { | ||
public function getBaseName(): string | ||
{ | ||
return basename($this->getBasePath()); | ||
} | ||
|
||
public function getRegex(): string { | ||
public function getRegex(): string | ||
{ | ||
if (isset($this->configuration['regex'])) { | ||
return '/'.$this->configuration['regex'].'/i'; | ||
return '/' . $this->configuration['regex'] . '/i'; | ||
} | ||
|
||
return match ($this->getType()) { | ||
'media' => '/\.(mp4|ogg|webm)$/i', | ||
'image' => '/\.(gif|png|jpe?g|svg)$/i', | ||
'image' => '/\.(gif|png|jpe?g|svg|webp)$/i', | ||
default => '/.+$/i', | ||
}; | ||
} | ||
|
||
public function getCurrentRoute(): ?string { | ||
if ($this->getRoute()) { | ||
return urldecode($this->getRoute()); | ||
} | ||
|
||
return null; | ||
} | ||
// public function getCurrentRoute(): ?string { | ||
// if ($this->getRoute()) { | ||
// return urldecode($this->getRoute()); | ||
// } | ||
// | ||
// return null; | ||
// } | ||
|
||
public function getCurrentPath(): bool|string { | ||
return realpath($this->getBasePath().$this->getCurrentRoute()); | ||
public function getCurrentPath(): bool|string | ||
{ | ||
return realpath($this->getBasePath() . $this->getRoute()); | ||
} | ||
|
||
// parent url | ||
public function getParent(): ?string { | ||
public function getParent(): ?string | ||
{ | ||
$queryParentParameters = $this->queryParameters; | ||
|
||
if ($this->getCurrentRoute()) { | ||
|
||
$parentRoute = \dirname($this->getCurrentRoute()); | ||
if ($this->getRoute()) { | ||
|
||
$parentRoute = \dirname($this->getRoute()); | ||
if (\DIRECTORY_SEPARATOR !== $parentRoute) { | ||
$queryParentParameters['route'] = \dirname($this->getCurrentRoute()); | ||
$queryParentParameters['route'] = \dirname($this->getRoute()); | ||
} else { | ||
unset($queryParentParameters['route']); | ||
} | ||
|
@@ -79,28 +85,33 @@ public function getParent(): ?string { | |
return null; | ||
} | ||
|
||
public function getImagePath(): bool|string { | ||
public function getImagePath(): bool|string | ||
{ | ||
$baseUrl = $this->getBaseUrl(); | ||
|
||
if ($baseUrl) { | ||
return $baseUrl.$this->getCurrentRoute().'/'; | ||
$routePath = $this->getRoutePath(); | ||
return $baseUrl . $routePath . '/'; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private function getBaseUrl(): bool|string { | ||
private function getBaseUrl(): bool|string | ||
{ | ||
$webPath = $this->webDir; | ||
$dirl = new \SplFileInfo($this->getConfiguration()['dir']); | ||
$base = $dirl->getPathname(); | ||
|
||
if (0 === mb_strpos($base, $webPath)) { | ||
if (str_starts_with($base, $webPath)) { | ||
return mb_substr($base, mb_strlen($webPath)); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private function checkSecurity(): void { | ||
private function checkSecurity(): void | ||
{ | ||
if (!isset($this->configuration['dir'])) { | ||
throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, 'Please define a "dir" parameter in your config.yml'); | ||
} | ||
|
@@ -115,67 +126,86 @@ private function checkSecurity(): void { | |
$currentPath = $this->getCurrentPath(); | ||
|
||
// check Path security | ||
if (false === $currentPath || 0 !== mb_strpos($currentPath, $this->getBasePath())) { | ||
if (false === $currentPath || !str_starts_with($currentPath, $this->getBasePath())) { | ||
throw new HttpException(Response::HTTP_UNAUTHORIZED, 'You are not allowed to access this folder.'); | ||
} | ||
$event = new GenericEvent($this, ['path' => $currentPath]); | ||
$this->dispatcher->dispatch($event, FileManagerEvents::POST_CHECK_SECURITY); | ||
|
||
} | ||
|
||
public function getModule(): ?string { | ||
public function getModule(): ?string | ||
{ | ||
return $this->getQueryParameters()['module'] ?? null; | ||
} | ||
|
||
public function getType(): ?string { | ||
public function getType(): ?string | ||
{ | ||
return $this->mergeConfAndQuery('type'); | ||
} | ||
|
||
public function getRoute(): ?string { | ||
public function getRoute(): ?string | ||
{ | ||
return isset($this->getQueryParameters()['route']) && '/' !== $this->getQueryParameters()['route'] ? $this->getQueryParameters()['route'] : null; | ||
} | ||
|
||
public function getBasePath(): bool|string { | ||
public function getRoutePath(): ?string | ||
{ | ||
return implode('/', array_map('rawurlencode', explode('/', $this->getRoute()))); | ||
} | ||
|
||
public function getBasePath(): bool|string | ||
{ | ||
return realpath($this->getConfiguration()['dir']); | ||
} | ||
|
||
public function getQueryParameters(): array { | ||
public function getQueryParameters(): array | ||
{ | ||
return $this->queryParameters; | ||
} | ||
|
||
public function getRouter(): RouterInterface { | ||
public function getRouter(): RouterInterface | ||
{ | ||
return $this->router; | ||
} | ||
|
||
public function setRouter(RouterInterface $router): void { | ||
public function setRouter(RouterInterface $router): void | ||
{ | ||
$this->router = $router; | ||
} | ||
|
||
public function getConfiguration(): array { | ||
public function getConfiguration(): array | ||
{ | ||
return $this->configuration; | ||
} | ||
|
||
public function setConfiguration(array $configuration): void { | ||
public function setConfiguration(array $configuration): void | ||
{ | ||
$this->configuration = $configuration; | ||
} | ||
|
||
public function getTree(): bool { | ||
public function getTree(): bool | ||
{ | ||
return $this->mergeQueryAndConf('tree', true); | ||
} | ||
|
||
public function getView(): string { | ||
public function getView(): string | ||
{ | ||
return $this->mergeQueryAndConf('view', 'list'); | ||
} | ||
|
||
public function getQueryParameter(string $parameter) { | ||
public function getQueryParameter(string $parameter) | ||
{ | ||
return $this->getQueryParameters()[$parameter] ?? null; | ||
} | ||
|
||
public function getConfigurationParameter(string $parameter) { | ||
public function getConfigurationParameter(string $parameter) | ||
{ | ||
return $this->getConfiguration()[$parameter] ?? null; | ||
} | ||
|
||
private function mergeQueryAndConf(string $parameter, $default = null) { | ||
private function mergeQueryAndConf(string $parameter, $default = null) | ||
{ | ||
if (null !== $this->getQueryParameter($parameter)) { | ||
return $this->getQueryParameter($parameter); | ||
} | ||
|
@@ -186,7 +216,8 @@ private function mergeQueryAndConf(string $parameter, $default = null) { | |
return $default; | ||
} | ||
|
||
private function mergeConfAndQuery(string $parameter, $default = null) { | ||
private function mergeConfAndQuery(string $parameter, $default = null) | ||
{ | ||
if (null !== $this->getConfigurationParameter($parameter)) { | ||
return $this->getConfigurationParameter($parameter); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
file: | ||
add: | ||
success: è stato caricato correttamente | ||
renamed: | ||
success: Il file è stato rinominato correttamente | ||
danger: Il file esiste già o non sei autorizzato a rinominarlo | ||
unauthorized: I file non esistono più o non sei autorizzato ad accedere a questa pagina | ||
nochanged: Nessuna modifica rilevata | ||
deleted: | ||
success: I file sono stati eliminati correttamente | ||
danger: I file non esistono più o non sei autorizzato ad accedere a questa pagina | ||
unauthorized: I file non esistono più o non sei autorizzato ad accedere a questa pagina | ||
folder: | ||
add: | ||
danger: "Si è verificato un errore durante la creazione della cartella: %message%" | ||
success: La cartella è stata creata correttamente | ||
deleted: | ||
success: La cartella è stata eliminata correttamente | ||
unauthorized: La cartella non esiste più o non sei autorizzato ad accedere a questa pagina | ||
button: | ||
cancel: ANNULLA | ||
refresh: Aggiorna | ||
parent: Genitore | ||
save: SALVA | ||
add: | ||
files: Aggiungi file... | ||
folder: Nuova cartella... | ||
delete: | ||
current: Elimina cartella corrente | ||
selected: Elimina file selezionati | ||
action: ELIMINA | ||
rename: | ||
action: RINOMINA | ||
tree: Albero | ||
title: | ||
add: | ||
folder: Nuova cartella | ||
rename: | ||
file: Rinomina | ||
delete: Elimina | ||
download: Scarica | ||
preview: | ||
file: Apri | ||
input: | ||
default: Cartella senza titolo | ||
table: | ||
name: Nome | ||
date: Data | ||
size: Peso | ||
dimension: Dimensione | ||
actions: Azioni | ||
confirm: | ||
delete: Sei sicuro di voler eliminare? | ||
size: | ||
mb: MB | ||
kb: kB | ||
select-all: Seleziona tutto | ||
upload: | ||
exception_move_uploaded_file: Permesso negato | ||
search: | ||
placeholder: Cerca |
Oops, something went wrong.