mode changes

This commit is contained in:
Dennis Eichhorn 2021-02-20 10:59:06 +01:00
parent 42c4b28a6b
commit 65fdcbee93
41 changed files with 87 additions and 140 deletions

View File

@ -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;
}
/**

View File

@ -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];
}
/**

View File

@ -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');
}

0
Docs/Dev/en/SUMMARY.md Normal file → Executable file
View File

0
Docs/Dev/en/collection.md Normal file → Executable file
View File

0
Docs/Dev/en/media.md Normal file → Executable file
View File

0
Docs/Dev/en/structure.md Normal file
View File

0
Docs/Help/en/SUMMARY.md Normal file → Executable file
View File

View File

@ -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}
*/

View File

@ -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;
}
/**

0
Theme/Api/render.tpl.php Normal file → Executable file
View File

0
Theme/Api/spreadsheetAsCsv.tpl.php Normal file → Executable file
View File

0
Theme/Api/spreadsheetAsHtml.tpl.php Normal file → Executable file
View File

0
Theme/Api/wordAsHtml.tpl.php Normal file → Executable file
View File

0
Theme/Backend/Components/Media/ElementView.php Normal file → Executable file
View File

View File

@ -0,0 +1,29 @@
<?php declare(strict_types=1);
?>
<section id="mediaFile" class="portlet">
<div class="portlet-body">
<div id="media" class="tabview tab-2 m-editor">
<ul class="tab-links">
<li><label tabindex="0" for="media-c-tab-1"><?= $this->getHtml('Preview', 'Media'); ?></label>
<li><label tabindex="0" for="media-c-tab-2"><?= $this->getHtml('Edit', 'Media'); ?></label>
</ul>
<div class="tab-content">
<input type="radio" id="media-c-tab-1" name="tabular-1" checked>
<div class="tab">
<?php
$archive = new ZipArchive();
$archive->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 );
}
?>
</div>
<input type="radio" id="media-c-tab-2" name="tabular-1">
<div class="tab">
</div>
</div>
</div>
</section>

0
Theme/Backend/Components/Media/audio.tpl.php Normal file → Executable file
View File

0
Theme/Backend/Components/Media/csv.tpl.php Normal file → Executable file
View File

0
Theme/Backend/Components/Media/default.tpl.php Normal file → Executable file
View File

0
Theme/Backend/Components/Media/image.tpl.php Normal file → Executable file
View File

0
Theme/Backend/Components/Media/json.tpl.php Normal file → Executable file
View File

0
Theme/Backend/Components/Media/markdown.tpl.php Normal file → Executable file
View File

0
Theme/Backend/Components/Media/pdf.tpl.php Normal file → Executable file
View File

0
Theme/Backend/Components/Media/powerpoint.tpl.php Normal file → Executable file
View File

0
Theme/Backend/Components/Media/spreadsheet.tpl.php Normal file → Executable file
View File

0
Theme/Backend/Components/Media/text.tpl.php Normal file → Executable file
View File

0
Theme/Backend/Components/Media/video.tpl.php Normal file → Executable file
View File

0
Theme/Backend/Components/Media/word.tpl.php Normal file → Executable file
View File

0
Theme/Backend/Lang/de.lang.php Normal file → Executable file
View File

0
Theme/Backend/Lang/en.lang.php Normal file → Executable file
View File

View File

@ -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=
<tr tabindex="0" data-href="<?= $url; ?>">
<td data-label="<?= $this->getHtml('Type'); ?>"><a href="<?= $url; ?>"><i class="fa fa-<?= $this->printHtml($icon); ?>"></i></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>">
<?= $this->printHtml(
$value->extension !== 'collection'
? $value->name . (
$value->extension !== '' ? '.' . $value->extension : ''
) : $value->name); ?>
<?= $this->printHtml($value->name); ?>
</a>
<td data-label="<?= $this->getHtml('Extension'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->extension); ?></a>
<td data-label="<?= $this->getHtml('Size'); ?>"><a href="<?= $url; ?>"><?php
$size = FileSizeType::autoFormat($value->size);
echo $this->printHtml($value->extension !== 'collection' ? \number_format($size[0], 1, '.', ','). $size[1] : ''); ?></a>
echo $this->printHtml($value->extension !== 'collection' ? \number_format($size[0], 1, '.', ',') . $size[1] : ''); ?></a>
<td data-label="<?= $this->getHtml('Creator'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->createdBy->name1); ?></a>
<td data-label="<?= $this->getHtml('Created'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->createdAt->format('Y-m-d H:i:s')); ?></a>
<?php endforeach; ?>

View File

@ -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();
<table class="list w-100">
<tbody>
<tr><td><?= $this->getHtml('Name'); ?><td class="wf-100"><?= $this->printHtml($media->name); ?>
<tr><td><?= $this->getHtml('Size'); ?><td class="wf-100"><?= $media->size; ?>
<tr><td><?= $this->getHtml('Size'); ?><td class="wf-100"><?php
$size = FileSizeType::autoFormat($media->size);
echo $this->printHtml(\number_format($size[0], 1, '.', ',') . $size[1]); ?>
<tr><td><?= $this->getHtml('Created'); ?><td><?= $this->printHtml($media->createdAt->format('Y-m-d')); ?>
<tr><td><?= $this->getHtml('Creator'); ?><td><a href="<?= UriFactory::build('{/prefix}profile/single?for=' . $media->createdBy->getId()); ?>"><?= $this->printHtml(
\ltrim($media->createdBy->name2 . ', ' . $media->createdBy->name1, ', ')
@ -80,111 +83,3 @@ echo $this->getData('nav')->render();
<?= $view->render($media); ?>
</div>
</div>
<!--
<div class="row">
<?php if ($this->isCollectionFunction($media, $this->request->getData('sub') ?? '')) : ?>
<div class="col-xs-12">
<section class="portlet">
<table class="default">
<caption><?= $this->getHtml('Media'); ?><i class="fa fa-download floatRight download btn"></i></caption>
<thead>
<tr>
<td>
<td class="wf-100"><?= $this->getHtml('Name'); ?>
<td><?= $this->getHtml('Type'); ?>
<td><?= $this->getHtml('Size'); ?>
<td><?= $this->getHtml('Creator'); ?>
<td><?= $this->getHtml('Created'); ?>
<tbody>
<?php
if (!\is_dir($media->isAbsolute ? $media->getPath() : __DIR__ . '/../../../../' . \ltrim($media->getPath(), '//'))
|| $media->getPath() === ''
) :
foreach ($media as $key => $value) :
$url = UriFactory::build('{/prefix}media/single?{?}&id=' . $value->getId());
$icon = $fileIconFunction(FileUtils::getExtensionType($value->extension));
?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><i class="fa fa-<?= $this->printHtml($icon); ?>"></i></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->name); ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->extension); ?></a>
<td><a href="<?= $url; ?>"><?= $value->size; ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->createdBy->name1); ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->createdAt->format('Y-m-d H:i:s')); ?></a>
<?php endforeach; else : $path = $this->dirPathFunction($media, $this->request->getData('sub') ?? ''); ?>
<?php $list = \phpOMS\System\File\Local\Directory::list($path);
foreach ($list as $key => $value) :
$url = UriFactory::build('{/prefix}media/single?{?}&id=' . $media->getId() . '&sub=' . \substr($value, \strlen($media->getPath())));
$icon = $fileIconFunction(FileUtils::getExtensionType(!\is_dir($value) ? File::extension($value) : 'collection'));
?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><i class="fa fa-<?= $this->printHtml($icon); ?>"></i></a>
<td><a href="<?= $url; ?>"><?= \substr($value, \strlen($media->getPath())); ?></a>
<td><a href="<?= $url; ?>"><?= !\is_dir($value) ? File::extension($value) : 'collection'; ?></a>
<td><a href="<?= $url; ?>"><?= !\is_dir($value) ? File::size($value) : ''; ?></a>
<td><a href="<?= $url; ?>"><?= File::owner($value); ?></a>
<td><a href="<?= $url; ?>"><?= File::created($value)->format('Y-m-d'); ?></a>
<?php endforeach; endif; ?>
</table>
</section>
</div>
<?php else: ?>
<div class="col-xs-12">
<section id="mediaFile" class="portlet">
<div class="portlet-body">
<?php
$path = $this->filePathFunction($media, $this->request->getData('sub') ?? '');
if ($this->isImageFile($media, $path)) : ?>
<div class="h-overflow centerText">
<img style="max-width: 100%" src="<?= $media->getPath(); ?>" alt="<?= $this->printHtml($media->name); ?>">
</div>
<?php elseif ($this->isTextFile($media, $path)) : ?>
<?php if (!\is_file(($media->isAbsolute ? '' : __DIR__ . '/../../../../') . $media->getPath())) : ?>
<div class="centerText"><i class="fa fa-question fa-5x"></i></div>
<?php else : ?>
<template id="iMediaUpdateTpl">
<textarea class="textContent" form="iMediaFileUpdate" data-tpl-text="/media/content" data-tpl-value="/media/content" data-marker="tpl" name="content"></textarea>
</template>
<?php if ($media->extension === 'csv') :
$f = \fopen(($media->isAbsolute ? '' : __DIR__ . '/../../../../') . $media->getPath(), 'r');
echo '<table class="default">';
$delim = CsvSettings::getFileDelimiter($f, 3);
while (($line = \fgetcsv($f, 0, $delim)) !== false) {
echo '<tr>';
foreach ($line as $cell) {
echo '<td>' . \htmlspecialchars($cell);
}
}
\fclose($f);
echo '</table>';
elseif ($media->extension === 'md') : ?>
<article><?= Markdown::parse(
$this->getFileContent(($media->isAbsolute ? '' : __DIR__ . '/../../../../') . $media->getPath())
); ?></article>
<?php else : ?>
<pre class="textContent" data-tpl-text="/media/content" data-tpl-value="/media/content"><?= $this->printHtml(
$this->getFileContent(($media->isAbsolute ? '' : __DIR__ . '/../../../../') . $media->getPath())
); ?></pre>
<?php endif; ?>
<?php endif; ?>
<?php elseif ($this->isVideoFile($media, $path)) : ?>
<video width="100%" controls>
<source src="<?= $media->getPath(); ?>" type="video/<?= $media->extension; ?>">
Your browser does not support HTML video.
</video>
<?php elseif ($this->isAudioFile($media, $path)) : ?>
<audio width="100%" controls>
<source src="<?= $media->getPath(); ?>" type="audio/<?= $media->extension; ?>">
Your browser does not support HTML audio.
</audio>
<?php endif; ?>
</div>
</section>
</div>
<?php endif; ?>
</div>
-->

View File

@ -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';

0
tests/Autoloader.php Normal file → Executable file
View File

0
tests/Bootstrap.php Normal file → Executable file
View File

0
tests/Models/CollectionMapperTest.php Normal file → Executable file
View File

0
tests/Models/NullCollectionTest.php Normal file → Executable file
View File

0
tests/Models/NullMediaTest.php Normal file → Executable file
View File

0
tests/Views/MediaViewTest.php Normal file → Executable file
View File

0
tests/Views/test.md Normal file → Executable file
View File

0
tests/phpunit_default.xml Normal file → Executable file
View File