mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-17 01:38:41 +00:00
implement file creation
This commit is contained in:
parent
1734926ba6
commit
abffbdcd49
|
|
@ -34,6 +34,7 @@ use phpOMS\Message\ResponseAbstract;
|
||||||
use phpOMS\Model\Message\FormValidation;
|
use phpOMS\Model\Message\FormValidation;
|
||||||
use phpOMS\System\MimeType;
|
use phpOMS\System\MimeType;
|
||||||
use phpOMS\Utils\Parser\Markdown\Markdown;
|
use phpOMS\Utils\Parser\Markdown\Markdown;
|
||||||
|
use phpOMS\System\File\Local\Directory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Media class.
|
* Media class.
|
||||||
|
|
@ -327,7 +328,7 @@ final class ApiController extends Controller
|
||||||
/** @var Media $media */
|
/** @var Media $media */
|
||||||
$media = MediaMapper::get((int) $request->getData('id'));
|
$media = MediaMapper::get((int) $request->getData('id'));
|
||||||
$media->setName((string) ($request->getData('name') ?? $media->getName()));
|
$media->setName((string) ($request->getData('name') ?? $media->getName()));
|
||||||
$media->setVirtualPath((string) ($request->getData('virtualpath') ?? $media->getVirtualPath()));
|
$media->setVirtualPath(\urldecode((string) ($request->getData('virtualpath') ?? $media->getVirtualPath())));
|
||||||
|
|
||||||
if ($request->getData('content') !== null) {
|
if ($request->getData('content') !== null) {
|
||||||
\file_put_contents(
|
\file_put_contents(
|
||||||
|
|
@ -473,8 +474,9 @@ final class ApiController extends Controller
|
||||||
*/
|
*/
|
||||||
public function apiMediaCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
public function apiMediaCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||||
{
|
{
|
||||||
$virtualPath = (string) ($request->getData('path') ?? '');
|
$virtualPath = \urldecode((string) ($request->getData('path') ?? ''));
|
||||||
$fileName = (string) ($request->getData('fileName') ?? '');
|
$fileName = (string) ($request->getData('fileName') ?? ($request->getData('name') ?? ''));
|
||||||
|
$fileName .= \strripos($fileName, '.') === false ? '.txt' : '';
|
||||||
$pathSettings = (int) ($request->getData('pathsettings') ?? PathSettings::RANDOM_PATH);
|
$pathSettings = (int) ($request->getData('pathsettings') ?? PathSettings::RANDOM_PATH);
|
||||||
|
|
||||||
$outputDir = '';
|
$outputDir = '';
|
||||||
|
|
@ -484,16 +486,20 @@ final class ApiController extends Controller
|
||||||
$outputDir = __DIR__ . '/../../../Modules/Media/Files/' . \ltrim($virtualPath, '\\/');
|
$outputDir = __DIR__ . '/../../../Modules/Media/Files/' . \ltrim($virtualPath, '\\/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!\is_dir($outputDir)) {
|
||||||
|
Directory::create($outputDir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
\file_put_contents($outputDir . '/' . $fileName, (string) ($request->getData('content') ?? ''));
|
\file_put_contents($outputDir . '/' . $fileName, (string) ($request->getData('content') ?? ''));
|
||||||
|
|
||||||
$status = [
|
$status = [
|
||||||
[
|
[
|
||||||
'status' => UploadStatus::OK,
|
'status' => UploadStatus::OK,
|
||||||
'path' => $outputDir . '/' . $fileName,
|
'path' => $outputDir,
|
||||||
'filename' => $fileName,
|
'filename' => $fileName,
|
||||||
'name' => $request->getData('name') ?? '',
|
'name' => $request->getData('name') ?? '',
|
||||||
'size' => \strlen((string) ($request->getData('content') ?? '')),
|
'size' => \strlen((string) ($request->getData('content') ?? '')),
|
||||||
'extension' => \substr($fileName, \strripos($fileName, '.')),
|
'extension' => \substr($fileName, \strripos($fileName, '.') + 1),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ use phpOMS\Uri\UriFactory;
|
||||||
<div class="portlet-body">
|
<div class="portlet-body">
|
||||||
<form id="fEditor" method="PUT" action="<?= UriFactory::build('{/api}media/file?{?}&csrf={$CSRF}'); ?>">
|
<form id="fEditor" method="PUT" action="<?= UriFactory::build('{/api}media/file?{?}&csrf={$CSRF}'); ?>">
|
||||||
<div class="ipt-wrap">
|
<div class="ipt-wrap">
|
||||||
<div class="ipt-first"><input name="title" type="text" class="wf-100"></div>
|
<div class="ipt-first"><input autocomplete="off" name="name" type="text" class="wf-100"></div>
|
||||||
<div class="ipt-second"><input type="submit" value="<?= $this->getHtml('Save', '0', '0') ?>"></div>
|
<div class="ipt-second"><input type="submit" value="<?= $this->getHtml('Save', '0', '0') ?>"></div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
@ -46,7 +46,7 @@ use phpOMS\Uri\UriFactory;
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<?= $this->getData('editor')->getData('text')->render('editor', 'plain', 'fEditor'); ?>
|
<?= $this->getData('editor')->getData('text')->render('editor', 'content', 'fEditor'); ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -84,14 +84,19 @@ $media = $this->getData('media');
|
||||||
|
|
||||||
$url = $value->getExtension() === 'collection'
|
$url = $value->getExtension() === 'collection'
|
||||||
? UriFactory::build('{/prefix}media/list?path=' . \rtrim($value->getVirtualPath(), '/') . '/' . $value->getName())
|
? UriFactory::build('{/prefix}media/list?path=' . \rtrim($value->getVirtualPath(), '/') . '/' . $value->getName())
|
||||||
: UriFactory::build('{/prefix}media/single?id=' . $value->getId());
|
: UriFactory::build('{/prefix}media/single?id=' . $value->getId() . '&path={?path}');
|
||||||
|
|
||||||
$icon = $fileIconFunction(\phpOMS\System\File\FileUtils::getExtensionType($value->getExtension()));
|
$icon = $fileIconFunction(\phpOMS\System\File\FileUtils::getExtensionType($value->getExtension()));
|
||||||
?>
|
?>
|
||||||
<tr tabindex="0" data-href="<?= $url; ?>">
|
<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('Type') ?>"><a href="<?= $url; ?>"><i class="fa fa-<?= $this->printHtml($icon); ?>"></i></a>
|
||||||
<td data-label="<?= $this->getHtml('Name') ?>"><a href="<?= $url; ?>"><?= $this->printHtml(
|
<td data-label="<?= $this->getHtml('Name') ?>"><a href="<?= $url; ?>">
|
||||||
$value->getExtension() !== 'collection' ? $value->getName() . '.' . $value->getExtension() : $value->getName()); ?></a>
|
<?= $this->printHtml(
|
||||||
|
$value->getExtension() !== 'collection'
|
||||||
|
? $value->getName() . (
|
||||||
|
$value->getExtension() !== '' ? '.' . $value->getExtension() : ''
|
||||||
|
) : $value->getName()); ?>
|
||||||
|
</a>
|
||||||
<td data-label="<?= $this->getHtml('Extension') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getExtension()); ?></a>
|
<td data-label="<?= $this->getHtml('Extension') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getExtension()); ?></a>
|
||||||
<td data-label="<?= $this->getHtml('Size') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getSize()); ?></a>
|
<td data-label="<?= $this->getHtml('Size') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getSize()); ?></a>
|
||||||
<td data-label="<?= $this->getHtml('Creator') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getCreatedBy()->getName1()); ?></a>
|
<td data-label="<?= $this->getHtml('Creator') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getCreatedBy()->getName1()); ?></a>
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,21 @@ include __DIR__ . '/template-functions.php';
|
||||||
$media = $this->getData('media');
|
$media = $this->getData('media');
|
||||||
echo $this->getData('nav')->render();
|
echo $this->getData('nav')->render();
|
||||||
?>
|
?>
|
||||||
|
<?php if ($this->request->getData('path') !== null) : ?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<div class="box">
|
||||||
|
<a tabindex="0" class="button" href="<?= UriFactory::build('{/prefix}media/list?path={?path}'); ?>">Back</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<section class="box wf-100">
|
<section class="portlet">
|
||||||
<header><h1><?= $this->printHtml($media->getName()); ?></h1></header>
|
<div class="portlet-head"><?= $this->printHtml($media->getName()); ?></div>
|
||||||
<div class="inner">
|
<div class="portlet-body">
|
||||||
<table class="list w-100">
|
<table class="list w-100">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr><td><?= $this->getHtml('Name') ?><td class="wf-100"><?= $this->printHtml($media->getName()); ?>
|
<tr><td><?= $this->getHtml('Name') ?><td class="wf-100"><?= $this->printHtml($media->getName()); ?>
|
||||||
|
|
@ -49,7 +58,7 @@ echo $this->getData('nav')->render();
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<?php if ($this->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">
|
<section class="portlet">
|
||||||
<table class="default">
|
<table class="default">
|
||||||
<caption><?= $this->getHtml('Media') ?><i class="fa fa-download floatRight download btn"></i></caption>
|
<caption><?= $this->getHtml('Media') ?><i class="fa fa-download floatRight download btn"></i></caption>
|
||||||
<thead>
|
<thead>
|
||||||
|
|
@ -91,17 +100,17 @@ echo $this->getData('nav')->render();
|
||||||
<td><a href="<?= $url; ?>"><?= File::created($value)->format('Y-m-d'); ?></a>
|
<td><a href="<?= $url; ?>"><?= File::created($value)->format('Y-m-d'); ?></a>
|
||||||
<?php endforeach; endif; ?>
|
<?php endforeach; endif; ?>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<section id="mediaFile" class="box wf-100"
|
<section id="mediaFile" class="portlet"
|
||||||
data-update-content=".inner"
|
data-update-content=".inner"
|
||||||
data-update-element="#mediaFile .textContent"
|
data-update-element="#mediaFile .textContent"
|
||||||
data-tag="form"
|
data-tag="form"
|
||||||
data-method="POST"
|
data-method="POST"
|
||||||
data-uri="<?= \phpOMS\Uri\UriFactory::build('{/api}media?{?}&csrf={$CSRF}'); ?>">
|
data-uri="<?= \phpOMS\Uri\UriFactory::build('{/api}media?{?}&csrf={$CSRF}'); ?>">
|
||||||
<div class="inner">
|
<div class="portlet-body inner">
|
||||||
<?php
|
<?php
|
||||||
$path = $this->filePathFunction($media, $this->request->getData('sub') ?? '');
|
$path = $this->filePathFunction($media, $this->request->getData('sub') ?? '');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user