diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 6d03fc9..37316d3 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -16,6 +16,8 @@ namespace Modules\Media\Controller; use Modules\Media\Models\Media; use Modules\Media\Models\MediaMapper; +use Modules\Media\Models\Collection; +use Modules\Media\Models\CollectionMapper; use Modules\Media\Models\UploadFile; use Modules\Media\Models\UploadStatus; @@ -73,8 +75,9 @@ final class ApiController extends Controller */ public function apiMediaUpload(RequestAbstract $request, ResponseAbstract $response, $data = null) : void { - // todo: handle logging + // todo: this is really messy because i don't use formdata object. media first get's uploaded but nothing is done with the form data $uploads = $this->uploadFiles( + $request->getData('name') ?? '', $request->getFiles(), $request->getHeader()->getAccount(), (string) ($request->getData('path') ?? __DIR__ . '/../../../Modules/Media/Files') @@ -107,6 +110,7 @@ final class ApiController extends Controller } /** + * @param string $name Name * @param array $files Files * @param int $account Uploader * @param string $basePath Base path @@ -115,7 +119,7 @@ final class ApiController extends Controller * * @since 1.0.0 */ - public function uploadFiles(array $files, int $account, string $basePath = 'Modules/Media/Files') : array + public function uploadFiles(string $name, array $files, int $account, string $basePath = 'Modules/Media/Files') : array { $mediaCreated = []; @@ -123,8 +127,8 @@ final class ApiController extends Controller $upload = new UploadFile(); $upload->setOutputDir(self::createMediaPath($basePath)); - $status = $upload->upload($files); - $mediaCreated = self::createDbEntries($status, $account); + $status = $upload->upload($files, $name); + $mediaCreated = self::createDbEntries($name, $status, $account); } return $mediaCreated; @@ -144,7 +148,7 @@ final class ApiController extends Controller * * @since 1.0.0 */ - public static function createDbEntries(array $status, int $account) : array + public static function createDbEntries(string $name, array $status, int $account) : array { $mediaCreated = []; @@ -178,7 +182,7 @@ final class ApiController extends Controller private static function normalizeDbPath(string $path) : string { - $realpath = \realpath(__DIR__ . '/../../'); + $realpath = \realpath(__DIR__ . '/../../../'); if ($realpath === false) { throw new \Exception(); diff --git a/Models/UploadFile.php b/Models/UploadFile.php index 2f325c5..4341208 100644 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -88,6 +88,7 @@ class UploadFile * Upload file to server. * * @param array $files File data ($_FILE) + * @param string $name File name * @param string $encoding Encoding used for uploaded file. Empty string will not convert file content. * * @return array @@ -96,7 +97,7 @@ class UploadFile * * @since 1.0.0 */ - public function upload(array $files, string $encoding = 'UTF-8') : array + public function upload(array $files, string $name = '', string $encoding = 'UTF-8') : array { $result = []; @@ -141,7 +142,7 @@ class UploadFile } $split = \explode('.', $f['name']); - $result[$key]['name'] = $split[0]; + $result[$key]['name'] = \count($files) === 1 && !empty($name) ? $name : $split[0]; $extension = \count($split) > 1 ? $split[\count($split) - 1] : ''; $result[$key]['extension'] = $extension; diff --git a/Theme/Backend/Components/Media/list.tpl.php b/Theme/Backend/Components/Media/list.tpl.php index e785f43..3559759 100644 --- a/Theme/Backend/Components/Media/list.tpl.php +++ b/Theme/Backend/Components/Media/list.tpl.php @@ -10,7 +10,7 @@ getHtml('Created', 'Media') ?> - media as $key => $value) : $count++; + media as $key => $value) : ++$count; $url = \phpOMS\Uri\UriFactory::build('{/lang}/backend/media/single?{?}&id=' . $value->getId()); $icon = ''; diff --git a/Theme/Backend/Components/Upload/upload.tpl.php b/Theme/Backend/Components/Upload/upload.tpl.php index 2104abc..7daf11f 100644 --- a/Theme/Backend/Components/Upload/upload.tpl.php +++ b/Theme/Backend/Components/Upload/upload.tpl.php @@ -13,7 +13,7 @@ + data-src="{/lang}/api/media/find?search={#mediaInput}"> @@ -59,7 +60,7 @@ echo $this->getData('nav')->render(); getHtml('Created') ?> isAbsolute() ? $path : __DIR__ . '/../../../' . \ltrim($media->getPath(), '//')) + if (!\is_dir($media->isAbsolute() ? $path : __DIR__ . '/../../../../' . \ltrim($media->getPath(), '//')) || $media->getPath() === '' ) : foreach ($media as $key => $value) : @@ -104,12 +105,12 @@ echo $this->getData('nav')->render(); - isAbsolute() ? $path : __DIR__ . '/../../../' . \ltrim($path, '/'))) : ?> + isAbsolute() ? $path : __DIR__ . '/../../../../' . \ltrim($path, '/'))) : ?>
                     lineContentFunction($media->isAbsolute() ? $path : __DIR__ . '/../../../' . \ltrim($path, '/'));
+                    $output = $this->lineContentFunction($media->isAbsolute() ? $path : __DIR__ . '/../../../../' . \ltrim($path, '/'));
                     foreach ($output as $line) : ?>printHtml($line); ?>