mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-06 04:28:43 +00:00
draft media creation
This commit is contained in:
parent
9e6d321c05
commit
773fbe458f
|
|
@ -26,6 +26,17 @@ return [
|
|||
],
|
||||
],
|
||||
],
|
||||
'^.*/media/file(\?+.*|$)' => [
|
||||
[
|
||||
'dest' => '\Modules\Media\Controller\ApiController:apiMediaCreate',
|
||||
'verb' => RouteVerb::PUT,
|
||||
'permission' => [
|
||||
'module' => ApiController::MODULE_NAME,
|
||||
'type' => PermissionType::CREATE,
|
||||
'state' => PermissionState::MEDIA,
|
||||
],
|
||||
],
|
||||
],
|
||||
'^.*/media/find.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\Media\Controller\ApiController:apiMediaFind',
|
||||
|
|
|
|||
|
|
@ -362,4 +362,53 @@ final class ApiController extends Controller
|
|||
|
||||
return $mediaCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create media file.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiMediaCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
$virtualPath = (string) ($request->getData('path') ?? '');
|
||||
$fileName = (string) ($request->getData('fileName') ?? '');
|
||||
$pathSettings = (int) ($request->getData('pathsettings') ?? PathSettings::RANDOM_PATH);
|
||||
|
||||
$outputDir = '';
|
||||
if ($pathSettings === PathSettings::RANDOM_PATH) {
|
||||
$outputDir = self::createMediaPath(__DIR__ . '/../../../Modules/Media/Files');
|
||||
} elseif ($pathSettings === PathSettings::FILE_PATH) {
|
||||
$outputDir = __DIR__ . '/../../../Modules/Media/Files/' . \ltrim($virtualPath, '\\/');
|
||||
}
|
||||
|
||||
\file_put_contents($outputDir . '/' . $fileName, (string) ($request->getData('content') ?? ''));
|
||||
|
||||
$status = [
|
||||
[
|
||||
'status' => UploadStatus::OK,
|
||||
'path' => $outputDir . '/' . $fileName,
|
||||
'filename' => $fileName,
|
||||
'name' => $request->getData('name') ?? '',
|
||||
'size' => \strlen((string) ($request->getData('content') ?? '')),
|
||||
'extension' => \substr($fileName, \strripos($fileName, '.')),
|
||||
],
|
||||
];
|
||||
|
||||
$created = $this->createDbEntries($status, $request->getHeader()->getAccount(), $virtualPath);
|
||||
|
||||
$ids = [];
|
||||
foreach ($created as $file) {
|
||||
$ids[] = $file->getId();
|
||||
}
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Media', 'Media successfully created.', $ids);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -246,6 +246,9 @@ final class BackendController extends Controller
|
|||
$view = new View($this->app->l11nManager, $request, $response);
|
||||
$view->setTemplate('/Modules/Media/Theme/Backend/media-file-create');
|
||||
|
||||
$editor = new \Modules\Editor\Theme\Backend\Components\Editor\BaseView($this->app->l11nManager, $request, $response);
|
||||
$view->addData('editor', $editor);
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package Modules\Media
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Modules\Media\Models\PathSettings;
|
||||
use phpOMS\Uri\UriFactory;
|
||||
|
||||
/**
|
||||
* @var \phpOMS\Views\View $this
|
||||
*/
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="box">
|
||||
<a class="button" href="<?= UriFactory::build('{/prefix}media/list?path={?path}'); ?>">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="portlet">
|
||||
<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-second"><input type="submit" value="<?= $this->getHtml('Save', '0', '0') ?>"></div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="portlet">
|
||||
<div class="portlet-body">
|
||||
<?= $this->getData('editor')->render('editor'); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="box">
|
||||
<?= $this->getData('editor')->getData('text')->render('editor', 'plain', 'fEditor'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -35,10 +35,10 @@ use phpOMS\Uri\UriFactory;
|
|||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<section class="box wf-100">
|
||||
<header><h1><?= $this->getHtml('Upload') ?></h1></header>
|
||||
<div class="inner">
|
||||
<form method="PUT" id="media-uploader" action="<?= UriFactory::build('{/api}media'); ?>">
|
||||
<form method="PUT" id="media-uploader" action="<?= UriFactory::build('{/api}media'); ?>">
|
||||
<div class="portlet">
|
||||
<div class="portlet-head"><?= $this->getHtml('Upload') ?></div>
|
||||
<div class="portlet-body">
|
||||
<table class="layout wf-100">
|
||||
<tr><td><label for="iPath"><?= $this->getHtml('Path') ?></label>
|
||||
<tr><td><input type="text" id="iPath" name="virtualPath" value="<?= $this->request->getUri()->getQuery('path') ?? ''; ?>" disabled>
|
||||
|
|
@ -52,10 +52,12 @@ use phpOMS\Uri\UriFactory;
|
|||
</select>
|
||||
<tr><td><label for="iFiles"><?= $this->getHtml('Files') ?></label>
|
||||
<tr><td><input type="file" id="iFiles" name="files" multiple>
|
||||
<tr><td><input type="submit" id="iMediaCreate" name="mediaCreateButton" value="<?= $this->getHtml('Create', '0', '0'); ?>">
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<div class="portlet-foot">
|
||||
<input type="submit" id="iMediaCreate" name="mediaCreateButton" value="<?= $this->getHtml('Create', '0', '0'); ?>">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Reference in New Issue
Block a user