mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-07 04:58:42 +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\System\MimeType;
|
||||
use phpOMS\Utils\Parser\Markdown\Markdown;
|
||||
use phpOMS\System\File\Local\Directory;
|
||||
|
||||
/**
|
||||
* Media class.
|
||||
|
|
@ -327,7 +328,7 @@ final class ApiController extends Controller
|
|||
/** @var Media $media */
|
||||
$media = MediaMapper::get((int) $request->getData('id'));
|
||||
$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) {
|
||||
\file_put_contents(
|
||||
|
|
@ -473,8 +474,9 @@ final class ApiController extends Controller
|
|||
*/
|
||||
public function apiMediaCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
$virtualPath = (string) ($request->getData('path') ?? '');
|
||||
$fileName = (string) ($request->getData('fileName') ?? '');
|
||||
$virtualPath = \urldecode((string) ($request->getData('path') ?? ''));
|
||||
$fileName = (string) ($request->getData('fileName') ?? ($request->getData('name') ?? ''));
|
||||
$fileName .= \strripos($fileName, '.') === false ? '.txt' : '';
|
||||
$pathSettings = (int) ($request->getData('pathsettings') ?? PathSettings::RANDOM_PATH);
|
||||
|
||||
$outputDir = '';
|
||||
|
|
@ -484,16 +486,20 @@ final class ApiController extends Controller
|
|||
$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') ?? ''));
|
||||
|
||||
$status = [
|
||||
[
|
||||
'status' => UploadStatus::OK,
|
||||
'path' => $outputDir . '/' . $fileName,
|
||||
'path' => $outputDir,
|
||||
'filename' => $fileName,
|
||||
'name' => $request->getData('name') ?? '',
|
||||
'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">
|
||||
<form id="fEditor" method="PUT" action="<?= UriFactory::build('{/api}media/file?{?}&csrf={$CSRF}'); ?>">
|
||||
<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>
|
||||
</form>
|
||||
|
|
@ -46,7 +46,7 @@ use phpOMS\Uri\UriFactory;
|
|||
</div>
|
||||
|
||||
<div class="box">
|
||||
<?= $this->getData('editor')->getData('text')->render('editor', 'plain', 'fEditor'); ?>
|
||||
<?= $this->getData('editor')->getData('text')->render('editor', 'content', 'fEditor'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -84,14 +84,19 @@ $media = $this->getData('media');
|
|||
|
||||
$url = $value->getExtension() === 'collection'
|
||||
? 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()));
|
||||
?>
|
||||
<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->getExtension() !== 'collection' ? $value->getName() . '.' . $value->getExtension() : $value->getName()); ?></a>
|
||||
<td data-label="<?= $this->getHtml('Name') ?>"><a href="<?= $url; ?>">
|
||||
<?= $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('Size') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getSize()); ?></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');
|
||||
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="col-xs-12">
|
||||
<section class="box wf-100">
|
||||
<header><h1><?= $this->printHtml($media->getName()); ?></h1></header>
|
||||
<div class="inner">
|
||||
<section class="portlet">
|
||||
<div class="portlet-head"><?= $this->printHtml($media->getName()); ?></div>
|
||||
<div class="portlet-body">
|
||||
<table class="list w-100">
|
||||
<tbody>
|
||||
<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">
|
||||
<?php if ($this->isCollectionFunction($media, $this->request->getData('sub') ?? '')) : ?>
|
||||
<div class="col-xs-12">
|
||||
<div class="box wf-100">
|
||||
<section class="portlet">
|
||||
<table class="default">
|
||||
<caption><?= $this->getHtml('Media') ?><i class="fa fa-download floatRight download btn"></i></caption>
|
||||
<thead>
|
||||
|
|
@ -91,17 +100,17 @@ echo $this->getData('nav')->render();
|
|||
<td><a href="<?= $url; ?>"><?= File::created($value)->format('Y-m-d'); ?></a>
|
||||
<?php endforeach; endif; ?>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="col-xs-12">
|
||||
<section id="mediaFile" class="box wf-100"
|
||||
<section id="mediaFile" class="portlet"
|
||||
data-update-content=".inner"
|
||||
data-update-element="#mediaFile .textContent"
|
||||
data-tag="form"
|
||||
data-method="POST"
|
||||
data-uri="<?= \phpOMS\Uri\UriFactory::build('{/api}media?{?}&csrf={$CSRF}'); ?>">
|
||||
<div class="inner">
|
||||
<div class="portlet-body inner">
|
||||
<?php
|
||||
$path = $this->filePathFunction($media, $this->request->getData('sub') ?? '');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user