mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-17 09:48:41 +00:00
Fix #142
This commit is contained in:
parent
86e7120d02
commit
360c21f0f6
|
|
@ -18,6 +18,7 @@ use Modules\Media\Models\Media;
|
||||||
use Modules\Media\Models\MediaMapper;
|
use Modules\Media\Models\MediaMapper;
|
||||||
use Modules\Media\Models\CollectionMapper;
|
use Modules\Media\Models\CollectionMapper;
|
||||||
use Modules\Media\Models\Collection;
|
use Modules\Media\Models\Collection;
|
||||||
|
use Modules\Media\Views\MediaView;
|
||||||
|
|
||||||
use Modules\Media\Models\UploadFile;
|
use Modules\Media\Models\UploadFile;
|
||||||
use Modules\Media\Models\UploadStatus;
|
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
|
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->setTemplate('/Modules/Media/Theme/Backend/media-single');
|
||||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000401001, $request, $response));
|
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000401001, $request, $response));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ echo $this->getData('nav')->render();
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<?php if ($isCollectionFunction($media, $this->request->getData('sub') ?? '')) : ?>
|
<?php if ($this->isCollectionFunction($media, $this->request->getData('sub') ?? '')) : ?>
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<div class="box wf-100">
|
<div class="box wf-100">
|
||||||
<table class="table red">
|
<table class="table red">
|
||||||
|
|
@ -63,7 +63,7 @@ echo $this->getData('nav')->render();
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php if (!is_dir($media->getPath())) : foreach ($media as $key => $value) :
|
<?php if (!is_dir($media->getPath())) : foreach ($media as $key => $value) :
|
||||||
$url = UriFactory::build('/{/lang}/backend/media/single?{?}&id=' . $value->getId());
|
$url = UriFactory::build('/{/lang}/backend/media/single?{?}&id=' . $value->getId());
|
||||||
$icon = $fileIconFunction(FileUtils::getExtensionType($value->getExtension()));
|
$icon = $this->fileIconFunction(FileUtils::getExtensionType($value->getExtension()));
|
||||||
?>
|
?>
|
||||||
<tr data-href="<?= $url; ?>">
|
<tr data-href="<?= $url; ?>">
|
||||||
<td><a href="<?= $url; ?>"><i class="fa fa-<?= $this->printHtml($icon); ?>"></i></a>
|
<td><a href="<?= $url; ?>"><i class="fa fa-<?= $this->printHtml($icon); ?>"></i></a>
|
||||||
|
|
@ -72,11 +72,11 @@ echo $this->getData('nav')->render();
|
||||||
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->getSize()); ?></a>
|
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->getSize()); ?></a>
|
||||||
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->getCreatedBy()->getName1()); ?></a>
|
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->getCreatedBy()->getName1()); ?></a>
|
||||||
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->getCreatedAt()->format('Y-m-d H:i:s')); ?></a>
|
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->getCreatedAt()->format('Y-m-d H:i:s')); ?></a>
|
||||||
<?php endforeach; else : $path = $dirPathFunction($media, $this->request->getData('sub') ?? ''); ?>
|
<?php endforeach; else : $path = $this->dirPathFunction($media, $this->request->getData('sub') ?? ''); ?>
|
||||||
<?php $list = \phpOMS\System\File\Local\Directory::list($path);
|
<?php $list = \phpOMS\System\File\Local\Directory::list($path);
|
||||||
foreach ($list as $key => $value) :
|
foreach ($list as $key => $value) :
|
||||||
$url = UriFactory::build('/{/lang}/backend/media/single?{?}&id=' . $media->getId() . '&sub=' . substr($value, strlen($media->getPath())));
|
$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'));
|
||||||
?>
|
?>
|
||||||
<tr data-href="<?= $url; ?>">
|
<tr data-href="<?= $url; ?>">
|
||||||
<td><a href="<?= $url; ?>"><i class="fa fa-<?= $this->printHtml($icon); ?>"></i></a>
|
<td><a href="<?= $url; ?>"><i class="fa fa-<?= $this->printHtml($icon); ?>"></i></a>
|
||||||
|
|
@ -94,9 +94,9 @@ echo $this->getData('nav')->render();
|
||||||
<section class="box wf-100">
|
<section class="box wf-100">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<?php
|
<?php
|
||||||
$path = $filePathFunction($media, $this->request->getData('sub') ?? '');
|
$path = $this->filePathFunction($media, $this->request->getData('sub') ?? '');
|
||||||
|
|
||||||
if ($isImageFunction($media, $path)) : ?>
|
if ($this->isImageFunction($media, $path)) : ?>
|
||||||
<div class="h-overflow">
|
<div class="h-overflow">
|
||||||
<img src="<?= $media->isAbsolute() ? $this->printHtml($path) : $this->printHtml($this->request->getUri()->getBase() . $path); ?>">
|
<img src="<?= $media->isAbsolute() ? $this->printHtml($path) : $this->printHtml($this->request->getUri()->getBase() . $path); ?>">
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -108,7 +108,7 @@ echo $this->getData('nav')->render();
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
<pre>
|
<pre>
|
||||||
<?php
|
<?php
|
||||||
$output = $lineContentFunction($media->isAbsolute() ? $path : __DIR__ . '/../../../../' . $path);
|
$output = $this->lineContentFunction($media->isAbsolute() ? $path : __DIR__ . '/../../../../' . $path);
|
||||||
foreach ($output as $line) : ?><span><?= $this->printHtml($line); ?></span><?php endforeach; ?>
|
foreach ($output as $line) : ?><span><?= $this->printHtml($line); ?></span><?php endforeach; ?>
|
||||||
</pre>
|
</pre>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
|
||||||
|
|
@ -28,58 +28,3 @@ $fileIconFunction = function (int $extensionType) : string
|
||||||
|
|
||||||
return 'file-o';
|
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;
|
|
||||||
};
|
|
||||||
|
|
|
||||||
85
Views/MediaView.php
Normal file
85
Views/MediaView.php
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.2
|
||||||
|
*
|
||||||
|
* @package Modules\Media\Views
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://website.orange-management.de
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\Media\Views;
|
||||||
|
|
||||||
|
use phpOMS\Views\View;
|
||||||
|
use phpOMS\System\File\FileUtils;
|
||||||
|
use phpOMS\System\File\Local\File;
|
||||||
|
use phpOMS\Utils\StringUtils;
|
||||||
|
use phpOMS\System\File\ExtensionType;
|
||||||
|
|
||||||
|
use Modules\Media\Models\Media;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Media view.
|
||||||
|
*
|
||||||
|
* @package Modules\Media\Views
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://website.orange-management.de
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
class MediaView extends View
|
||||||
|
{
|
||||||
|
protected function filePathFunction(Media $media, string $sub) : string
|
||||||
|
{
|
||||||
|
if (is_file($media->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user