From 65fdcbee9316c9d1a45a986e62aaf6168ee78413 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 20 Feb 2021 10:59:06 +0100 Subject: [PATCH] mode changes --- Admin/Installer.php | 21 +++- Controller/ApiController.php | 2 +- Controller/BackendController.php | 27 +++-- Docs/Dev/en/SUMMARY.md | 0 Docs/Dev/en/collection.md | 0 Docs/Dev/en/media.md | 0 Docs/Dev/en/structure.md | 0 Docs/Help/en/SUMMARY.md | 0 Models/Collection.php | 11 ++ Models/UploadFile.php | 8 +- Theme/Api/render.tpl.php | 0 Theme/Api/spreadsheetAsCsv.tpl.php | 0 Theme/Api/spreadsheetAsHtml.tpl.php | 0 Theme/Api/wordAsHtml.tpl.php | 0 .../Backend/Components/Media/ElementView.php | 0 .../Backend/Components/Media/archive.tpl.php | 29 +++++ Theme/Backend/Components/Media/audio.tpl.php | 0 Theme/Backend/Components/Media/csv.tpl.php | 0 .../Backend/Components/Media/default.tpl.php | 0 Theme/Backend/Components/Media/image.tpl.php | 0 Theme/Backend/Components/Media/json.tpl.php | 0 .../Backend/Components/Media/markdown.tpl.php | 0 Theme/Backend/Components/Media/pdf.tpl.php | 0 .../Components/Media/powerpoint.tpl.php | 0 .../Components/Media/spreadsheet.tpl.php | 0 Theme/Backend/Components/Media/text.tpl.php | 0 Theme/Backend/Components/Media/video.tpl.php | 0 Theme/Backend/Components/Media/word.tpl.php | 0 Theme/Backend/Lang/de.lang.php | 0 Theme/Backend/Lang/en.lang.php | 0 Theme/Backend/media-list.tpl.php | 10 +- Theme/Backend/media-single.tpl.php | 113 +----------------- Theme/Backend/template-functions.php | 6 +- tests/Autoloader.php | 0 tests/Bootstrap.php | 0 tests/Models/CollectionMapperTest.php | 0 tests/Models/NullCollectionTest.php | 0 tests/Models/NullMediaTest.php | 0 tests/Views/MediaViewTest.php | 0 tests/Views/test.md | 0 tests/phpunit_default.xml | 0 41 files changed, 87 insertions(+), 140 deletions(-) mode change 100644 => 100755 Docs/Dev/en/SUMMARY.md mode change 100644 => 100755 Docs/Dev/en/collection.md mode change 100644 => 100755 Docs/Dev/en/media.md create mode 100644 Docs/Dev/en/structure.md mode change 100644 => 100755 Docs/Help/en/SUMMARY.md mode change 100644 => 100755 Theme/Api/render.tpl.php mode change 100644 => 100755 Theme/Api/spreadsheetAsCsv.tpl.php mode change 100644 => 100755 Theme/Api/spreadsheetAsHtml.tpl.php mode change 100644 => 100755 Theme/Api/wordAsHtml.tpl.php mode change 100644 => 100755 Theme/Backend/Components/Media/ElementView.php create mode 100644 Theme/Backend/Components/Media/archive.tpl.php mode change 100644 => 100755 Theme/Backend/Components/Media/audio.tpl.php mode change 100644 => 100755 Theme/Backend/Components/Media/csv.tpl.php mode change 100644 => 100755 Theme/Backend/Components/Media/default.tpl.php mode change 100644 => 100755 Theme/Backend/Components/Media/image.tpl.php mode change 100644 => 100755 Theme/Backend/Components/Media/json.tpl.php mode change 100644 => 100755 Theme/Backend/Components/Media/markdown.tpl.php mode change 100644 => 100755 Theme/Backend/Components/Media/pdf.tpl.php mode change 100644 => 100755 Theme/Backend/Components/Media/powerpoint.tpl.php mode change 100644 => 100755 Theme/Backend/Components/Media/spreadsheet.tpl.php mode change 100644 => 100755 Theme/Backend/Components/Media/text.tpl.php mode change 100644 => 100755 Theme/Backend/Components/Media/video.tpl.php mode change 100644 => 100755 Theme/Backend/Components/Media/word.tpl.php mode change 100644 => 100755 Theme/Backend/Lang/de.lang.php mode change 100644 => 100755 Theme/Backend/Lang/en.lang.php mode change 100644 => 100755 tests/Autoloader.php mode change 100644 => 100755 tests/Bootstrap.php mode change 100644 => 100755 tests/Models/CollectionMapperTest.php mode change 100644 => 100755 tests/Models/NullCollectionTest.php mode change 100644 => 100755 tests/Models/NullMediaTest.php mode change 100644 => 100755 tests/Views/MediaViewTest.php mode change 100644 => 100755 tests/Views/test.md mode change 100644 => 100755 tests/phpunit_default.xml diff --git a/Admin/Installer.php b/Admin/Installer.php index 1c07552..1daf0c9 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -110,13 +110,28 @@ final class Installer extends InstallerAbstract */ private static function createCollection($dbPool, $data) : Collection { + if (!isset($data['path'])) { + $dirPath = __DIR__ . '/../../../Modules/Media/Files' . ($data['virtualPath'] ?? '/') . '/' . ($data['name'] ?? ''); + $path = '/Modules/Media/Files' . ($data['virtualPath'] ?? '') . '/' . ($data['name'] ?? ''); + } else { + $dirPath = $data['path'] . '/' . ($data['name'] ?? ''); + $path = $data['path'] ?? '/Modules/Media/Files' . '/' . ($data['name'] ?? ''); + } + $collection = new Collection(); - $collection->name = (string) $data['name'] ?? ''; - $collection->setVirtualPath((string) $data['virtualPath'] ?? '/'); - $collection->setPath((string) ($data['path'] ?? '/Modules/Media/Files/' . ((string) $data['name'] ?? ''))); + $collection->name = $data['name'] ?? ''; + $collection->setVirtualPath($data['virtualPath'] ?? '/'); + $collection->setPath($path); $collection->createdBy = new NullAccount((int) $data['user'] ?? 1); CollectionMapper::create($collection); + + if ($data['create_directory']) { + // @todo fix permission mode + \mkdir($dirPath, 0755, true); + } + + return $collection; } /** diff --git a/Controller/ApiController.php b/Controller/ApiController.php index bbdc4eb..1eee18d 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -165,7 +165,7 @@ final class ApiController extends Controller public static function createMediaPath(string $basePath = '/Modules/Media/Files') : string { $rndPath = \str_pad(\dechex(\mt_rand(0, 65535)), 4, '0', \STR_PAD_LEFT); - return $basePath . '/' . $rndPath[0] . $rndPath[1] . '/' . $rndPath[2] . $rndPath[3]; + return $basePath . '/_' . $rndPath[0] . $rndPath[1] . '/' . $rndPath[2] . $rndPath[3]; } /** diff --git a/Controller/BackendController.php b/Controller/BackendController.php index fed9ff0..6526153 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -115,7 +115,7 @@ final class BackendController extends Controller $collection = new Collection(); $collection->name = \basename($path); $collection->setVirtualPath(\dirname($path)); - $collection->setPath(\dirname($path)); + $collection->setPath($path); $collection->isAbsolute = false; } @@ -125,16 +125,18 @@ final class BackendController extends Controller /** @var string[] $glob */ $glob = $collection->isAbsolute ? $collection->getPath() . '/' . $collection->name . '/*' - : \glob(__DIR__ . '/../Files/' . \rtrim($collection->getPath(), '/') . '/' . $collection->name . '/*'); + : \glob(__DIR__ . '/../Files/' . \trim($collection->getVirtualPath(), '/') . '/' . $collection->name . '/*'); $glob = $glob === false ? [] : $glob; foreach ($glob as $file) { + $basename = \basename($file); + if ($basename[0] === '_' && \strlen($basename) === 3) { + continue; + } + foreach ($media as $obj) { - if (($obj->extension !== 'collection' - && !empty($obj->extension) - && $obj->name . '.' . $obj->extension === \basename($file)) - || ($obj->extension === 'collection' - && $obj->name === \basename($file)) + if ($obj->name === $basename + || $obj->name . '.' . $obj->extension === $basename ) { continue 2; } @@ -205,11 +207,9 @@ final class BackendController extends Controller $view->setTemplate('/Modules/Media/Theme/Backend/media-list'); } else { $sub = $request->getData('sub') ?? ''; - if (($media->extension === 'collection' - && !\is_file($media->getPath() . $sub)) - || (\is_dir($media->getPath()) - && (\is_dir($media->getPath() . $sub)) - )) { + if (\is_dir($media->getPath()) + && (\is_dir($media->getPath() . $sub)) + ) { $listView = new ListView($this->app->l11nManager, $request, $response); $listView->setTemplate('/modules/Media/Theme/Backend/Components/Media/list'); $view->addData('view', $listView); @@ -290,6 +290,9 @@ final class BackendController extends Controller case 'mpeg': $view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/video'); break; + case 'zip': + $view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/archive'); + break; default: $view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/default'); } diff --git a/Docs/Dev/en/SUMMARY.md b/Docs/Dev/en/SUMMARY.md old mode 100644 new mode 100755 diff --git a/Docs/Dev/en/collection.md b/Docs/Dev/en/collection.md old mode 100644 new mode 100755 diff --git a/Docs/Dev/en/media.md b/Docs/Dev/en/media.md old mode 100644 new mode 100755 diff --git a/Docs/Dev/en/structure.md b/Docs/Dev/en/structure.md new file mode 100644 index 0000000..e69de29 diff --git a/Docs/Help/en/SUMMARY.md b/Docs/Help/en/SUMMARY.md old mode 100644 new mode 100755 diff --git a/Models/Collection.php b/Models/Collection.php index edc7a23..9aa4e1b 100755 --- a/Models/Collection.php +++ b/Models/Collection.php @@ -88,6 +88,17 @@ class Collection extends Media implements \Iterator return $this->sources; } + public function getSourceByName(string $name) : Media + { + foreach ($this->sources as $source) { + if ($source->name === $name) { + return $source; + } + } + + return new NullMedia(); + } + /** * {@inheritdoc} */ diff --git a/Models/UploadFile.php b/Models/UploadFile.php index b15b72b..af55cdd 100755 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -156,9 +156,7 @@ class UploadFile $split = \explode('.', $f['name']); $result[$key]['name'] = \count($files) === 1 && !empty($name) ? $name - : (\count($split) > 1 - ? \substr($f['name'], 0, \strripos($f['name'], '.')) - : $f['name']); + : $f['name']; $extension = \count($split) > 1 ? $split[\count($split) - 1] : ''; $result[$key]['extension'] = $extension; @@ -324,9 +322,9 @@ class UploadFile { do { $rndPath = \str_pad(\dechex(\mt_rand(0, 65535)), 4, '0', \STR_PAD_LEFT); - } while (\is_dir($this->outputDir . '/' . $rndPath)); + } while (\is_dir($this->outputDir . '/_' . $rndPath)); - return $this->outputDir . '/' . $rndPath; + return $this->outputDir . '/_' . $rndPath; } /** diff --git a/Theme/Api/render.tpl.php b/Theme/Api/render.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Api/spreadsheetAsCsv.tpl.php b/Theme/Api/spreadsheetAsCsv.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Api/spreadsheetAsHtml.tpl.php b/Theme/Api/spreadsheetAsHtml.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Api/wordAsHtml.tpl.php b/Theme/Api/wordAsHtml.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Components/Media/ElementView.php b/Theme/Backend/Components/Media/ElementView.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Components/Media/archive.tpl.php b/Theme/Backend/Components/Media/archive.tpl.php new file mode 100644 index 0000000..7a0bc30 --- /dev/null +++ b/Theme/Backend/Components/Media/archive.tpl.php @@ -0,0 +1,29 @@ + +
+
+
+ +
+ +
+ open(($this->media->isAbsolute ? '' : __DIR__ . '/../../../../../../') . $this->media->getPath()); + + for( $i = 0; $i < $archive->numFiles; $i++ ){ + $stat = $archive->statIndex( $i ); + print_r( basename( $stat['name'] ) . PHP_EOL ); + } + ?> +
+ +
+
+
+
+
diff --git a/Theme/Backend/Components/Media/audio.tpl.php b/Theme/Backend/Components/Media/audio.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Components/Media/csv.tpl.php b/Theme/Backend/Components/Media/csv.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Components/Media/default.tpl.php b/Theme/Backend/Components/Media/default.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Components/Media/image.tpl.php b/Theme/Backend/Components/Media/image.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Components/Media/json.tpl.php b/Theme/Backend/Components/Media/json.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Components/Media/markdown.tpl.php b/Theme/Backend/Components/Media/markdown.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Components/Media/pdf.tpl.php b/Theme/Backend/Components/Media/pdf.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Components/Media/powerpoint.tpl.php b/Theme/Backend/Components/Media/powerpoint.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Components/Media/spreadsheet.tpl.php b/Theme/Backend/Components/Media/spreadsheet.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Components/Media/text.tpl.php b/Theme/Backend/Components/Media/text.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Components/Media/video.tpl.php b/Theme/Backend/Components/Media/video.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Components/Media/word.tpl.php b/Theme/Backend/Components/Media/word.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/de.lang.php b/Theme/Backend/Lang/de.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/media-list.tpl.php b/Theme/Backend/media-list.tpl.php index 34bc8a0..262d58e 100755 --- a/Theme/Backend/media-list.tpl.php +++ b/Theme/Backend/media-list.tpl.php @@ -92,7 +92,7 @@ $next = empty($media) ? '{/prefix}media/list' : '{/prefix}media/list?{?}&id= : UriFactory::build('{/prefix}media/single?id=' . $value->getId() . '&path={?path}' . ( $value->getId() === 0 - ? '/' . $value->name . (!empty($value->extension) ? '.' . $value->extension : '') + ? '/' . $value->name : '' ) ); @@ -102,16 +102,12 @@ $next = empty($media) ? '{/prefix}media/list' : '{/prefix}media/list?{?}&id= - printHtml( - $value->extension !== 'collection' - ? $value->name . ( - $value->extension !== '' ? '.' . $value->extension : '' - ) : $value->name); ?> + printHtml($value->name); ?> printHtml($value->extension); ?> size); - echo $this->printHtml($value->extension !== 'collection' ? \number_format($size[0], 1, '.', ','). $size[1] : ''); ?> + echo $this->printHtml($value->extension !== 'collection' ? \number_format($size[0], 1, '.', ',') . $size[1] : ''); ?> printHtml($value->createdBy->name1); ?> printHtml($value->createdAt->format('Y-m-d H:i:s')); ?> diff --git a/Theme/Backend/media-single.tpl.php b/Theme/Backend/media-single.tpl.php index 232f548..974901a 100755 --- a/Theme/Backend/media-single.tpl.php +++ b/Theme/Backend/media-single.tpl.php @@ -17,6 +17,7 @@ use \phpOMS\System\File\Local\File; use \phpOMS\Uri\UriFactory; use phpOMS\Utils\IO\Csv\CsvSettings; use phpOMS\Utils\Parser\Markdown\Markdown; +use phpOMS\Utils\Converter\FileSizeType; include __DIR__ . '/template-functions.php'; @@ -47,7 +48,9 @@ echo $this->getData('nav')->render();
getHtml('Name'); ?>printHtml($media->name); ?> -
getHtml('Size'); ?>size; ?> +
getHtml('Size'); ?>size); + echo $this->printHtml(\number_format($size[0], 1, '.', ',') . $size[1]); ?>
getHtml('Created'); ?>printHtml($media->createdAt->format('Y-m-d')); ?>
getHtml('Creator'); ?>printHtml( \ltrim($media->createdBy->name2 . ', ' . $media->createdBy->name1, ', ') @@ -80,111 +83,3 @@ echo $this->getData('nav')->render(); render($media); ?> - - \ No newline at end of file diff --git a/Theme/Backend/template-functions.php b/Theme/Backend/template-functions.php index 1583657..ba4d2f7 100755 --- a/Theme/Backend/template-functions.php +++ b/Theme/Backend/template-functions.php @@ -17,9 +17,9 @@ use \phpOMS\System\File\ExtensionType; $fileIconFunction = function (int $extensionType) : string { if ($extensionType === ExtensionType::CODE) { - return 'file-code'; + return 'file-code-o'; } elseif ($extensionType === ExtensionType::TEXT || $extensionType === ExtensionType::WORD) { - return 'file-text'; + return 'file-text-o'; } elseif ($extensionType === ExtensionType::PRESENTATION) { return 'file-powerpoint-o'; } elseif ($extensionType === ExtensionType::PDF) { @@ -35,7 +35,7 @@ $fileIconFunction = function (int $extensionType) : string } elseif ($extensionType === ExtensionType::SPREADSHEET) { return 'file-excel-o'; } elseif ($extensionType === ExtensionType::DIRECTORY) { - return 'folder-open'; + return 'folder-open-o'; } return 'file'; diff --git a/tests/Autoloader.php b/tests/Autoloader.php old mode 100644 new mode 100755 diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php old mode 100644 new mode 100755 diff --git a/tests/Models/CollectionMapperTest.php b/tests/Models/CollectionMapperTest.php old mode 100644 new mode 100755 diff --git a/tests/Models/NullCollectionTest.php b/tests/Models/NullCollectionTest.php old mode 100644 new mode 100755 diff --git a/tests/Models/NullMediaTest.php b/tests/Models/NullMediaTest.php old mode 100644 new mode 100755 diff --git a/tests/Views/MediaViewTest.php b/tests/Views/MediaViewTest.php old mode 100644 new mode 100755 diff --git a/tests/Views/test.md b/tests/Views/test.md old mode 100644 new mode 100755 diff --git a/tests/phpunit_default.xml b/tests/phpunit_default.xml old mode 100644 new mode 100755