diff --git a/Controller.php b/Controller.php index a409bbc..a7cb42a 100644 --- a/Controller.php +++ b/Controller.php @@ -18,6 +18,7 @@ use Modules\Media\Models\Media; use Modules\Media\Models\MediaMapper; use Modules\Media\Models\CollectionMapper; use Modules\Media\Models\Collection; +use Modules\Media\Views\MediaView; use Modules\Media\Models\UploadFile; use Modules\Media\Models\UploadStatus; @@ -143,7 +144,7 @@ class Controller extends ModuleAbstract implements WebInterface */ public function viewMediaSingle(RequestAbstract $request, ResponseAbstract $response, $data = null) : \Serializable { - $view = new View($this->app, $request, $response); + $view = new MediaView($this->app, $request, $response); $view->setTemplate('/Modules/Media/Theme/Backend/media-single'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000401001, $request, $response)); diff --git a/Theme/Backend/media-single.tpl.php b/Theme/Backend/media-single.tpl.php index b20832b..5c3658d 100644 --- a/Theme/Backend/media-single.tpl.php +++ b/Theme/Backend/media-single.tpl.php @@ -47,7 +47,7 @@ echo $this->getData('nav')->render();
| @@ -72,11 +72,11 @@ echo $this->getData('nav')->render(); | = $this->printHtml($value->getSize()); ?> | = $this->printHtml($value->getCreatedBy()->getName1()); ?> | = $this->printHtml($value->getCreatedAt()->format('Y-m-d H:i:s')); ?> - request->getData('sub') ?? ''); ?> + dirPathFunction($media, $this->request->getData('sub') ?? ''); ?> $value) : $url = UriFactory::build('/{/lang}/backend/media/single?{?}&id=' . $media->getId() . '&sub=' . substr($value, strlen($media->getPath()))); - $icon = $fileIconFunction(FileUtils::getExtensionType(!is_dir($value) ? File::extension($value) : 'collection')); + $icon = $this->fileIconFunction(FileUtils::getExtensionType(!is_dir($value) ? File::extension($value) : 'collection')); ?> |
|
@@ -94,9 +94,9 @@ echo $this->getData('nav')->render();
request->getData('sub') ?? '');
+ $path = $this->filePathFunction($media, $this->request->getData('sub') ?? '');
- if ($isImageFunction($media, $path)) : ?>
+ if ($this->isImageFunction($media, $path)) : ?>
isAbsolute() ? $path : __DIR__ . '/../../../../' . $path);
+ $output = $this->lineContentFunction($media->isAbsolute() ? $path : __DIR__ . '/../../../../' . $path);
foreach ($output as $line) : ?>= $this->printHtml($line); ?>
diff --git a/Theme/Backend/template-functions.php b/Theme/Backend/template-functions.php
index 27fa5bf..e040c17 100644
--- a/Theme/Backend/template-functions.php
+++ b/Theme/Backend/template-functions.php
@@ -28,58 +28,3 @@ $fileIconFunction = function (int $extensionType) : string
return 'file-o';
};
-
-// todo: move all functions below here to view since they are view related and not template specific
-use \phpOMS\System\File\FileUtils;
-use \phpOMS\System\File\Local\File;
-
-$filePathFunction = function ($media, string $sub) : string
-{
- if (is_file($media->getPath() . $sub)
- && phpOMS\Utils\StringUtils::startsWith(
- str_replace('\\', '/', realpath($media->getPath() . $sub)),
- $media->getPath()
- )
- ) {
- return $media->getPath() . $sub;
- }
-
- return $media->getPath();
-};
-
-$dirPathFunction = function ($media, string $sub) : string
-{
- if (is_dir($media->getPath() . $sub)
- && phpOMS\Utils\StringUtils::startsWith(
- str_replace('\\', '/', realpath($media->getPath() . $sub)),
- $media->getPath()
- )
- ) {
- return $media->getPath() . $sub;
- }
-
- return $media->getPath();
-};
-
-$isCollectionFunction = function ($media, string $sub) : bool
-{
- return ($media->getExtension() === 'collection'
- && !is_file($media->getPath() . $sub))
- || (is_dir($media->getPath())
- && ($sub === null || is_dir($media->getPath() . $sub))
- );
-};
-
-$lineContentFunction = function (string $path) : array
-{
- $output = file_get_contents($path);
- $output = str_replace(["\r\n", "\r"], "\n", $output);
-
- return explode("\n", $output);
-};
-
-$isImageFunction = function ($media, string $path) : bool
-{
- return FileUtils::getExtensionType($media->getExtension()) === ExtensionType::IMAGE
- || FileUtils::getExtensionType(File::extension($path)) === ExtensionType::IMAGE;
-};
diff --git a/Views/MediaView.php b/Views/MediaView.php
new file mode 100644
index 0000000..fa74759
--- /dev/null
+++ b/Views/MediaView.php
@@ -0,0 +1,85 @@
+getPath() . $sub)
+ && StringUtils::startsWith(
+ str_replace('\\', '/', realpath($media->getPath() . $sub)),
+ $media->getPath()
+ )
+ ) {
+ return $media->getPath() . $sub;
+ }
+
+ return $media->getPath();
+ }
+
+ protected function dirPathFunction(Media $media, string $sub) : string
+ {
+ if (is_dir($media->getPath() . $sub)
+ && StringUtils::startsWith(
+ str_replace('\\', '/', realpath($media->getPath() . $sub)),
+ $media->getPath()
+ )
+ ) {
+ return $media->getPath() . $sub;
+ }
+
+ return $media->getPath();
+ }
+
+ protected function isCollectionFunction(Media $media, string $sub) : bool
+ {
+ return ($media->getExtension() === 'collection'
+ && !is_file($media->getPath() . $sub))
+ || (is_dir($media->getPath())
+ && ($sub === null || is_dir($media->getPath() . $sub))
+ );
+ }
+
+ protected function lineContentFunction(string $path) : array
+ {
+ $output = file_get_contents($path);
+ $output = str_replace(["\r\n", "\r"], "\n", $output);
+
+ return explode("\n", $output);
+ }
+
+ protected function isImageFunction(Media $media, string $path) : bool
+ {
+ return FileUtils::getExtensionType($media->getExtension()) === ExtensionType::IMAGE
+ || FileUtils::getExtensionType(File::extension($path)) === ExtensionType::IMAGE;
+ }
+}
|