From 2af621208d238c054a8160f4c6503c6cedcb8534 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 4 Sep 2019 18:32:41 +0300 Subject: [PATCH] feat(core): Entries Manager - Media section updates #225 #186 - update path for media from /image/ to /image/entries/ - update path for media from PATH['entries'] to PATH['assets'] --- flextype/dependencies.php | 2 +- flextype/routes/web.php | 2 +- .../app/Controllers/EntriesController.php | 44 ++++++++++--------- .../templates/content/entries/media.html | 4 +- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/flextype/dependencies.php b/flextype/dependencies.php index 2e5da2d2..b762e519 100644 --- a/flextype/dependencies.php +++ b/flextype/dependencies.php @@ -121,7 +121,7 @@ $flextype['images'] = static function ($container) { // Set source filesystem $source = new Filesystem( - new Local(PATH['entries']) + new Local(PATH['assets']) ); // Set cache filesystem diff --git a/flextype/routes/web.php b/flextype/routes/web.php index 9940dacf..2e24dabf 100644 --- a/flextype/routes/web.php +++ b/flextype/routes/web.php @@ -17,7 +17,7 @@ use Psr\Http\Message\ServerRequestInterface as Request; * Generates and returns the image response */ $app->get('/image/{path:.+}', function (Request $request, Response $response, array $args) use ($flextype) { - if (Filesystem::has(PATH['entries'] . '/' . $args['path'])) { + if (Filesystem::has(PATH['assets'] . '/' . $args['path'])) { return $flextype['images']->getImageResponse($args['path'], $_GET); } diff --git a/site/plugins/admin/app/Controllers/EntriesController.php b/site/plugins/admin/app/Controllers/EntriesController.php index c63aa404..0fc0fdd5 100644 --- a/site/plugins/admin/app/Controllers/EntriesController.php +++ b/site/plugins/admin/app/Controllers/EntriesController.php @@ -731,24 +731,6 @@ class EntriesController extends Controller } } - public function getMediaList(string $entry, bool $path = false) : array - { - $base_url = \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER))->getBaseUrl(); - $files = []; - foreach (array_diff(scandir(PATH['entries'] . '/' . $entry), ['..', '.']) as $file) { - if (strpos($this->registry->get('settings.entries.media.accept_file_types'), $file_ext = substr(strrchr($file, '.'), 1)) !== false) { - if (strpos($file, strtolower($file_ext), 1)) { - if ($path) { - $files[$base_url . '/' . $entry . '/' . $file] = $base_url . '/' . $entry . '/' . $file; - } else { - $files[$file] = $file; - } - } - } - } - return $files; - } - /** * Edit entry process * @@ -827,7 +809,7 @@ class EntriesController extends Controller $entry_id = $data['entry-id']; $media_id = $data['media-id']; - $files_directory = PATH['entries'] . '/' . $entry_id . '/' . $media_id; + $files_directory = PATH['assets'] . '/entries/' . $entry_id . '/' . $media_id; Filesystem::delete($files_directory); @@ -850,7 +832,10 @@ class EntriesController extends Controller $id = $data['entry-id']; - $files_directory = PATH['entries'] . '/' . $id . '/'; + $files_directory = PATH['assets'] . '/entries/' . $id . '/'; + + // Create files directory if its not exists + ! Filesystem::has($files_directory) and Filesystem::createDir($files_directory); $file = $this->_uploadFile($_FILES['file'], $files_directory, $this->registry->get('settings.entries.media.accept_file_types'), 27000000); @@ -1012,4 +997,23 @@ class EntriesController extends Controller return false; } + + public function getMediaList(string $entry, bool $path = false) : array + { + $base_url = \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER))->getBaseUrl(); + $files = []; + foreach (array_diff(scandir(PATH['assets'] . '/entries/' . $entry), ['..', '.']) as $file) { + if (strpos($this->registry->get('settings.entries.media.accept_file_types'), $file_ext = substr(strrchr($file, '.'), 1)) !== false) { + if (strpos($file, strtolower($file_ext), 1)) { + if ($path) { + $files[$base_url . '/' . $entry . '/' . $file] = $base_url . '/' . $entry . '/' . $file; + } else { + $files[$file] = $file; + } + } + } + } + return $files; + } + } diff --git a/site/plugins/admin/views/templates/content/entries/media.html b/site/plugins/admin/views/templates/content/entries/media.html index 76fca3bc..40beee05 100644 --- a/site/plugins/admin/views/templates/content/entries/media.html +++ b/site/plugins/admin/views/templates/content/entries/media.html @@ -25,14 +25,14 @@
+ data-image-url="{{ base_url() }}/image/entries/{{ id }}/{{ filesystem_basename(file) }}"> {% if (filesystem_ext(file) in ['jpeg', 'png', 'gif', 'jpg']) %} {% else %}